bazelbuild/rules_android

Starlark aar_import does not expose StarlarkAndroidResourcesInfo

katre opened this issue · 7 comments

katre commented

Discovered while testing bazelbuild/examples#287.

When building examples/android/ndk with rules_android master branch, the build succeeds. The ManifestMerger action has the --mergeeManfests argument set to a list of manifest files, which includes @maven//\:androidx_appcompat_appcompat,bazel-out/android-arm64-v8a-fastbuild-ST-0b94fd089017/bin/external/maven/androidx_appcompat_appcompat_resources_processed_manifest/AndroidManifest.xml

When building with the pre-alpha branch, the ManifestMerger does not set the flag, and the merge action fails (presumably due to the lack of needed dependencies).

katre commented

Looks like the issue is RourceDependencies.fromRuleDeps, which is looking for the AndroidResourceInfo.PROVIDER provider. This is present with the master branch, but not with the pre-alpha, which I assume is due to starlarkifying android_library.

katre commented

Yes, looks like the native android_library calls AndroidResources.from, which collects the AndroidResourceInfo providers, but the version in pre-alpha does not.

katre commented

Okay, finally figured out the issue.

The pre-alpha version of resource collection (as implemented in rules/resources.bzl only checks for the existence of StarlarkAndroidResourcesInfo, not the native AndroidResourcesInfo.

The Starlark version of aar_import creates this provider, as expected.

However, the code in examples/android/ndk depends on appcompat via maven_install from rules_jvm_external, which creates an aar_import target using the native rules, which uses the native provider.

Either the pre-alpha branch needs to check for both possible providers, or rules_jvm_export needs to use the same pre-alpha version of aar_import, or rules_jvm_export isn't compatible with rules_android pre-alpha.

katre commented

Looks like rules_jvm_external has support for this, possibly.

katre commented

But even using the starlark aar_import, the target @maven//:androidx_appcompat_appcompat doesn't have the StarlarkAndroidResourcesInfo provider.

Using native aar_import to list provider names:

$ /tmp/blazes/bazel cquery --output=starlark --starlark:expr='providers(target).keys()' @maven//:androidx_appcompat_appcompat_resources
[
  "InstrumentedFilesInfo",
  "AndroidResourcesInfo",
  "AndroidManifestInfo",
  "AndroidAssetsInfo",
  "DataBindingV2Info",
  "ProguardSpecProvider",
  "AndroidNativeLibsInfo",
  "JavaInfo",
  "FileProvider",
  "FilesToRunProvider",
  "OutputGroupInfo",
]

Using Starlark aar_import to list provider names:

$ /tmp/blazes/bazel cquery --output=starlark --starlark:expr='providers(target).keys()' @maven//:androidx_appcompat_appcompat_resources
[
  "AndroidLibraryResourceClassJarProvider",
  "JavaInfo",
  "AndroidNativeLibsInfo",
  "ProguardSpecProvider",
  "AndroidIdeInfo",
  "FileProvider",
  "FilesToRunProvider",
  "OutputGroupInfo",
]
katre commented

Retitled issue to clarify the root cause.