Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android manifest merger unable to merge manifests containing queries #14285

Closed
Bencodes opened this issue Nov 16, 2021 · 4 comments
Closed

Android manifest merger unable to merge manifests containing queries #14285

Bencodes opened this issue Nov 16, 2021 · 4 comments
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: feature request

Comments

@Bencodes
Copy link
Contributor

Description of the problem / feature request:

The Android manifest merger being used by the Bazel android_tools is unable to merge manifests that contain queries that have providers listed. This can be reproduced using the rolling releases and HEAD.

The merge fails with the below exception:

Error: [@maven//:androidx_car_app_app] /private/var/tmp/_bazel_ekamp/490385dd022af32a8a24bff076cf882c/bazel-workers/multiplex-worker-1-ManifestMerger/instantandroid/bazel-out/android-arm64-v8a-dbg/bin/external/maven/androidx_car_app_app_processed_manifest/AndroidManifest.xml:25:9-71 Error:
	Missing 'name' key attribute on element provider at [@maven//:androidx_car_app_app] AndroidManifest.xml:25:9-71
Error: [@maven//:androidx_car_app_app] /private/var/tmp/_bazel_ekamp/490385dd022af32a8a24bff076cf882c/bazel-workers/multiplex-worker-1-ManifestMerger/instantandroid/bazel-out/android-arm64-v8a-dbg/bin/external/maven/androidx_car_app_app_processed_manifest/AndroidManifest.xml Error:
	Validation failed, exiting

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

This can be reproduced by including the latest version of https://developer.android.com/jetpack/androidx/releases/car-app, which has the following listed in it's manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="androidx.car.app" >
    
    ...

    <queries>
        <provider
          android:authorities="androidx.car.app.connection"
      />
    ...

What operating system are you running Bazel on?

MacOS Big Sur

Have you found anything relevant by searching the web?

Support for queries got added in API 30 while the android_tools are still using v25.0.0.

Any other information, logs, or outputs that you want to share?

Error: [@maven//:androidx_car_app_app] /private/var/tmp/_bazel_ekamp/490385dd022af32a8a24bff076cf882c/bazel-workers/multiplex-worker-1-ManifestMerger/instantandroid/bazel-out/android-arm64-v8a-dbg/bin/external/maven/androidx_car_app_app_processed_manifest/AndroidManifest.xml:25:9-71 Error:
	Missing 'name' key attribute on element provider at [@maven//:androidx_car_app_app] AndroidManifest.xml:25:9-71
Error: [@maven//:androidx_car_app_app] /private/var/tmp/_bazel_ekamp/490385dd022af32a8a24bff076cf882c/bazel-workers/multiplex-worker-1-ManifestMerger/instantandroid/bazel-out/android-arm64-v8a-dbg/bin/external/maven/androidx_car_app_app_processed_manifest/AndroidManifest.xml Error:
	Validation failed, exiting
Warning: 
See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.
Nov 06, 2021 7:10:28 PM com.google.devtools.build.android.ManifestMergerAction main
SEVERE: Error during merging manifests
com.google.devtools.build.android.AndroidManifestProcessor$ManifestProcessingException: Manifest merger failed with multiple errors, see logs
	at com.google.devtools.build.android.AndroidManifestProcessor.mergeManifest(AndroidManifestProcessor.java:186)
	at com.google.devtools.build.android.ManifestMergerAction.main(ManifestMergerAction.java:230)
	at com.google.devtools.build.android.ResourceProcessorBusyBox$Tool$5.call(ResourceProcessorBusyBox.java:94)
	at com.google.devtools.build.android.ResourceProcessorBusyBox.processRequest(ResourceProcessorBusyBox.java:242)
	at com.google.devtools.build.android.ResourceProcessorBusyBox.lambda$runPersistentWorker$0(ResourceProcessorBusyBox.java:197)
	at com.google.devtools.build.lib.worker.WorkRequestHandler$WorkRequestCallback.apply(WorkRequestHandler.java:223)
	at com.google.devtools.build.lib.worker.WorkRequestHandler.respondToRequest(WorkRequestHandler.java:372)
	at com.google.devtools.build.lib.worker.WorkRequestHandler.lambda$startResponseThread$1(WorkRequestHandler.java:351)
	at java.base/java.lang.Thread.run(Thread.java:829)
@ahumesky ahumesky added P2 We'll consider working on this in future. (Assignee optional) type: feature request and removed type: bug untriaged labels Nov 19, 2021
@ahumesky
Copy link
Contributor

ahumesky commented Nov 19, 2021

While we get the android tools version issue sorted, I was able to backport the queries feature into com.android.tools.build_manifest-merger_25.0.0.jar.

I won't have time to patch this until the week of the 29th, but if you'd like to try this yourself:

# get bazel sources
cd
git clone [email protected]:bazelbuild/bazel.git

# get manifest merger sources
mkdir manifest-merger
cd manifest-merger
wget https://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/25.0.0/manifest-merger-25.0.0-sources.jar
mkdir -p src/main/java
unzip -d src/main/java manifest-merger-25.0.0-sources.jar 

# patch ManifestModel
cp ~/downloads/manifest-merger-pom.xml.txt pom.xml
patch src/main/java/com/android/manifmerger/ManifestModel.java ~/downloads/ManifestModel.java.patch.txt
mvn compile

cd target/classes
jar ufv ~/bazel/third_party/android_common/com.android.tools.build_manifest-merger_25.0.0-patched.jar com/android/manifmerger/ManifestModel*.class

# test
cd ~/bazel
bazel build //tools/android/runtime_deps:android_tools.tar.gz
tar xvf bazel-bin/tools/android/runtime_deps/android_tools.tar.gz -C /tmp/android_tools

bazel build <target> --override_repository=android_tools=/tmp/android_tools

manifest-merger-pom.xml.txt
ManifestModel.java.patch.txt

@nkoroste
Copy link
Contributor

@ahumesky any updates on this?
I just got a potentially related issue where I get:

/var/folders/tt/rk0s95wx44v3zv347_2ph2c00000gn/T/android_resources_tmp2414597592944003570/manifest-processed/AndroidManifest.xml:247: error: unexpected element <uses-native-library> found in <manifest><application>.
/var/folders/tt/rk0s95wx44v3zv347_2ph2c00000gn/T/android_resources_tmp2414597592944003570/manifest-processed/AndroidManifest.xml:250: error: unexpected element <uses-native-library> found in <manifest><application>.
/var/folders/tt/rk0s95wx44v3zv347_2ph2c00000gn/T/android_resources_tmp2414597592944003570/manifest-processed/AndroidManifest.xml:253: error: unexpected element <uses-native-library> found in <manifest><application>.
/var/folders/tt/rk0s95wx44v3zv347_2ph2c00000gn/T/android_resources_tmp2414597592944003570/manifest-processed/AndroidManifest.xml:256: error: unexpected element <uses-native-library> found in <manifest><application>.

https://developer.android.com/guide/topics/manifest/uses-native-library-element

@Bencodes
Copy link
Contributor Author

I put up a PR with the manifest merger jar #14429

@lukaciko
Copy link

manifest-merger:30.1.3 is used since aaf94c6. third_party/android_common no longer exists on master since #17582. The issue is resolved on master, but not on the 6.x branch. Therefore merging #14429 into master no longer makes sense, but it could be done into 6.x branch.

oliviernotteghem added a commit to uber-common/bazel that referenced this issue Sep 19, 2023
BenHenning added a commit to oppia/oppia-android that referenced this issue May 21, 2024
Robolectric upgrade is hard: it requires upgrading Espresso in order to
work around robolectric/robolectric#7367 and
robolectric/robolectric#6593. However, newer
Espresso makes use of new manifest features that require upgrading
Bazel: bazelbuild/bazel#14285. Because
upgrading Kotlin is a precursor to the Bazel upgrade, a workaround for
the single test that required the Robolectric upgrade (due to using a
deprecated API from SDK 33 without being able to actually use SDK 33 in
the test) is the best approach here until Robolectric can actually be
upgraded in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants