Unfortunately it's not possible today to put such information into a build rule, because we'll need dynamic configurations, which are a long ways out:
For your situation though, you can base the decision on which .so to include in the rule on the --fat_apk_cpu flag, using configurable attributes, like this
config_setting(
name = "x86",
values = {
"fat_apk_cpu": "x86"
},
)
config_setting(
name = "armeabi-v7a",
values = {
"fat_apk_cpu": "armeabi-v7a"
},
)
android_binary(
name = "hello_world",
srcs = glob([
"MainActivity.java",
"Jni.java",
]),
legacy_native_support = 1,
manifest = "AndroidManifest.xml",
deps = select({
"x86": ["precompiled_x86_so"],
"armeabi-v7a": ["precompiled_armeabi-v7a_so"],
}),
)
cc_library(
name = "precompiled_x86_so",
srcs = ["jni-x86.so"]
)
cc_library(
name = "precompiled_armeabi-v7a_so",
srcs = ["jni-armeabi-v7a.so"]
)
Note also that this should work equally well, but for some reason that I haven't figured out yet it fails for me:
android_binary(
name = "hello_world",
srcs = glob([
"MainActivity.java",
"Jni.java",
]),
legacy_native_support = 1,
manifest = "AndroidManifest.xml",
deps = [
":precompiled_so",
],
)
config_setting(
name = "x86",
values = {
"fat_apk_cpu": "x86"
},
)
config_setting(
name = "armeabi-v7a",
values = {
"fat_apk_cpu": "armeabi-v7a"
},
)
cc_library(
name = "precompiled_so",
srcs = select({
":x86": ["jni-x86.so"],
":armeabi-v7a": ["jni-armeabi-v7a.so"],
}),
)