bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.73k stars 3.98k forks source link

Unsupported Resource Type "Macro" in "com.google.android.material:material:1.7.0" #17345

Open EdbertChan opened 1 year ago

EdbertChan commented 1 year ago

Description of the bug:

Bazel cannot compile the newest material library com.google.android.material:material:1.7.0 because of a new "macro" type resource that was introduced into the library.

This causes a parsing error inside of Bazel (see 1: Stack Trace) where it does not recognize the resource type.

The parsing of resource type is done inside of com.android.tools.layoutlib_layoutlib_26.1.2.jar. In ResourceType, it does not list MACRO as one of the enums (see 2: Source code parsing). Because of that, this line in AndroidCompiledDataDeserializer.java will return a null and cause the crash.

The solution is to bump the binary in com.android.tools.layoutlib_layoutlib_26.1.2.jar to support this ResourceType the same way AGP does.

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

Please see branch at :

https://github.com/EdbertChan/SimpleBazelAndroidApp/tree/proof_of_materials

Which operating system are you running Bazel on?

MacOS Ventura Version 13.1

What is the output of bazel info release?

release 6.0.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

https://github.com/EdbertChan/SimpleBazelAndroidApp.git
master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
ac5d33dd34c18977117b2107c7f3fb577936fb08

Have you found anything relevant by searching the web?

This is not a issue necessarily unique to Bazel. It looks like a lot of people are hitting this issue and are recommended to downgrade to 1.6.0. Example 2

However, the better solution is to actually bump the AGP version.

Digging in the source code of AGP supports this. Perhaps there should be a broadcast of this for people still using Gradle + Android Studio.

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

1: Stack Trace

SEVERE: Unexpected java.lang.NullPointerException: Null type at com.google.devtools.build.android.AutoValue_ResourceName.(AutoValue_ResourceName.java:24) at com.google.devtools.build.android.ResourceName.create(ResourceName.java:42) at com.google.devtools.build.android.AndroidCompiledDataDeserializer.consumeResourceTable(AndroidCompiledDataDeserializer.java:291) at com.google.devtools.build.android.AndroidCompiledDataDeserializer.read(AndroidCompiledDataDeserializer.java:672) at com.google.devtools.build.android.SerializedAndroidData.deserialize(SerializedAndroidData.java:108) at com.google.devtools.build.android.AndroidResourceMerger.mergeCompiledData(AndroidResourceMerger.java:202) at com.google.devtools.build.android.AndroidCompiledResourceMergingAction.main(AndroidCompiledResourceMergingAction.java:231) at com.google.devtools.build.android.ResourceProcessorBusyBox$Tool$3.call(ResourceProcessorBusyBox.java:85) at com.google.devtools.build.android.ResourceProcessorBusyBox.processRequest(ResourceProcessorBusyBox.java:251) at com.google.devtools.build.android.ResourceProcessorBusyBox.main(ResourceProcessorBusyBox.java:181)

Jan 26, 2023 12:41:06 PM com.google.devtools.build.android.ResourceProcessorBusyBox processRequest SEVERE: Error during processing java.lang.NullPointerException: Null type at com.google.devtools.build.android.AutoValue_ResourceName.(AutoValue_ResourceName.java:24) at com.google.devtools.build.android.ResourceName.create(ResourceName.java:42) at com.google.devtools.build.android.AndroidCompiledDataDeserializer.consumeResourceTable(AndroidCompiledDataDeserializer.java:291) at com.google.devtools.build.android.AndroidCompiledDataDeserializer.read(AndroidCompiledDataDeserializer.java:672) at com.google.devtools.build.android.SerializedAndroidData.deserialize(SerializedAndroidData.java:108) at com.google.devtools.build.android.AndroidResourceMerger.mergeCompiledData(AndroidResourceMerger.java:202) at com.google.devtools.build.android.AndroidCompiledResourceMergingAction.main(AndroidCompiledResourceMergingAction.java:231) at com.google.devtools.build.android.ResourceProcessorBusyBox$Tool$3.call(ResourceProcessorBusyBox.java:85) at com.google.devtools.build.android.ResourceProcessorBusyBox.processRequest(ResourceProcessorBusyBox.java:251) at com.google.devtools.build.android.ResourceProcessorBusyBox.main(ResourceProcessorBusyBox.java:181)

Exception in thread "main" java.lang.NullPointerException: Null type at com.google.devtools.build.android.AutoValue_ResourceName.(AutoValue_ResourceName.java:24) at com.google.devtools.build.android.ResourceName.create(ResourceName.java:42) at com.google.devtools.build.android.AndroidCompiledDataDeserializer.consumeResourceTable(AndroidCompiledDataDeserializer.java:291) at com.google.devtools.build.android.AndroidCompiledDataDeserializer.read(AndroidCompiledDataDeserializer.java:672) at com.google.devtools.build.android.SerializedAndroidData.deserialize(SerializedAndroidData.java:108) at com.google.devtools.build.android.AndroidResourceMerger.mergeCompiledData(AndroidResourceMerger.java:202) at com.google.devtools.build.android.AndroidCompiledResourceMergingAction.main(AndroidCompiledResourceMergingAction.java:231) at com.google.devtools.build.android.ResourceProcessorBusyBox$Tool$3.call(ResourceProcessorBusyBox.java:85) at com.google.devtools.build.android.ResourceProcessorBusyBox.processRequest(ResourceProcessorBusyBox.java:251) at com.google.devtools.build.android.ResourceProcessorBusyBox.main(ResourceProcessorBusyBox.java:181)

2: Source code parsing Screenshot 2023-01-26 at 2 40 28 PM

alexjlockwood commented 1 year ago

We are facing the same issue and are unable to depend on recent versions of material-components-android for this reason. And because we aren't able to update to the latest material-components-android, we are also unable to update several other dependencies as well (mainly AppCompat, since our current version of material-components-android depends on an older version of AppCompat).

EdbertChan commented 1 year ago

It looks like this will be fixed and addressed in "com.android.tools.layoutlib:layoutlib-api:30.1.3"

However, it was introduced in this commit which is only available in 7.0 https://github.com/bazelbuild/bazel/commit/aaf94c63bf1eb7db4921330e3f4eb0ede8381ec0

Either this should be backported or the 7.0 timeline should be escalated.

I have opened up a pull request for people who are still on < 7.0 and need to be unblocked. However, note that this packaged layoutlib will be deleted eventually.