Comments (6)
As far as I understood by looking over the implementation, mobile-install mainly uses the AndroidIdeInfo provider which has a merged R.java:
In the extract function from mobile-install/adapters/android_binary:
resource_src_jar = target[AndroidIdeInfo].resource_jar.source_jar, # This is the R with real ids.
I am not really familiar with android but maybe this is helpful, as in the stacktrace the error is that the specific androidx/startup/R$string could not be found.
When looking at all the split apks that mobile install produces and extracting the dex files there is also only com/example/basicapp/R.class with all the merged resources.
from rules_android.
Okay there are actually two reasons why it fails:
In mobile_install/adapters/android_binary.bzl all the resources files are filtered:
return dict(
debug_key = utils.only(ctx.rule.files.debug_key, allow_empty = True),
debug_signing_keys = ctx.rule.files.debug_signing_keys,
debug_signing_lineage_file = utils.only(ctx.rule.files.debug_signing_lineage_file, allow_empty = True),
key_rotation_min_sdk = ctx.rule.attr.key_rotation_min_sdk,
merged_manifest = target[AndroidIdeInfo].generated_manifest,
native_libs = target[AndroidIdeInfo].native_libs,
package = target[AndroidIdeInfo].java_package,
resource_apk = target[AndroidIdeInfo].resource_apk,
resource_src_jar = target[AndroidIdeInfo].resource_jar.source_jar, # This is the R with real ids.
aar_native_libs_info = MIAndroidAarNativeLibsInfo(
transitive_native_libs = transitive_native_libs,
),
android_dex_info = providers.make_mi_android_dex_info(
dex_shards = dex(
ctx,
target[JavaInfo].runtime_output_jars +
#filter_jars(
# ctx.label.name + "_resources.jar",
# target[JavaInfo].runtime_output_jars,
#) +
(
[
extension_registry_class_jar,
] if extension_registry_class_jar else []
),
target[JavaInfo].transitive_compile_time_jars,
),
deps = providers.collect(MIAndroidDexInfo, ctx.rule.attr.deps),
),
# TODO(djwhang): It wasteful to collect packages in
# android_resources_info, rather we should be looking to pull them
# from the resources_v3_info.
android_resources_info = providers.make_mi_android_resources_info(
package = target[AndroidIdeInfo].java_package,
deps = providers.collect(
MIAndroidResourcesInfo,
ctx.rule.attr.deps,
),
),
java_resources_info = providers.make_mi_java_resources_info(
deps = providers.collect(
MIJavaResourcesInfo,
ctx.rule.attr.deps,
),
),
apk = target[AndroidIdeInfo].signed_apk,
)
Commenting that filtering out makes another problem apparent:
The rules_jvm_external ruleset uses jvm_import instead of java_import for importing jar files. I have not yet looked into the difference but changing that to java_import leads to everything working with mobile-install.
What is the reason all resources files are filtered out? Is it important or was it just overlooked that it filters out external resources. Should they be added somewhere else?
from rules_android.
The reason why jvm_import does not work is that it has to be added to the adapters in the mobile-install aspects.
from rules_android.
So the problem was threefold:
- No aspect for jvm_import which is used by rules_jvm_external instead of java import -> The aspect for java_import can be reused for that
- Package name is inferred by directory structure or the explicit attribute on aar_import. This is not set by rules_jvm_external. There is alread a Todo label to instead retrieve the package name from AndroidManifest.xml -> I have implemented the package name retrieval from manifest and that works fine.
- The aar_import aspect ignores StarlarkAndroidResourcesInfo -> Try to use that if available
Let me know if this makes sense and whether these proposed fixes are appropriate, so that I can open a pr.
from rules_android.
Hi, thanks for filing this issue!
- I think jvm_import only exists in rules_jvm_external. I believe they had their own reasons to write their own rule for dealing with imported jars rather than re-using java_import.
- Usually package name inferred by directory structure works well enough. Can you elaborate why this doesn't work for your case? I also don't see where you've implemented the package name retrieval in the patch you shared.
- I think we will end up implementing this in the near future, as we finish up the Starlark migration effort for rules_android and fully delete both native Android rules and native Android providers from Bazel.
from rules_android.
rules_jvm_external is not setting the package field in aar_import and as the BUILD file with all imports is in the root of the generated repository the package name is empty. My usecase was just importing any library from maven but because the package name is unset the resources are missing or in the wrong location for them to be found. The patch I shared was before I found out the problems, it was just importing packages from maven via rules_jvm_external where the problem happened. I can clean up a bit and make a pr so it can be looked at.
from rules_android.
Related Issues (20)
- The Starlark implementaiton of process_deploy_jar fails to execute java.create_deploy_jar HOT 5
- Build fails when `--incremental_dexing` is disabled HOT 1
- Remove dependencies on --experimental_google_legacy_api and --experimental_enable_android_migration_apis HOT 1
- Can't build example basicapp HOT 5
- _copy_file and _copy_dir fail on macOS
- AAR libraries from Maven don't expose their resources unlike in built-in Android rules HOT 3
- Mobile install v3 doesn't work with --start=debug HOT 1
- Flags underneath rules/flags/ aren't working correctly HOT 1
- Android platforms breaks incremental dexing and desugaring HOT 4
- Unable to build with rules_android due to maven install issue HOT 2
- [Bazel CI] android_sdk_repository & android_sdk_repository_platforms_tests are failing with Bazel@HEAD HOT 1
- Bazel query broken at HEAD
- [Bazel CI] ERROR occurred during the fetch of repository 'rules_android_maven'
- APK doesn't include *.version files in metadata
- Rules use entire Android SDK dir as input instead of explicit files which may case poor cache hit HOT 1
- documentation for targets under android_sdk_repository
- Bash is not necessarily in /bin/bash
- No matching toolchains found for types @@bazel_tools//tools/android:sdk_toolchain_type even though called register_toolchains HOT 2
- [FR] Option for mobile-install command to install to all connected devices
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rules_android.