Material-components-android: Material components fails automatic namespaced resources due to malformed public.txt

Created on 3 Aug 2020  路  6Comments  路  Source: material-components/material-components-android

Description:

When enabling namespaced resources in AGP 4.1, material components causes the build to fail

   > Failed to transform material-1.2.0-beta01.aar (com.google.android.material:material:1.2.0-beta01) to match attributes {artifactType=android-symbol-with-package-name, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-api}.
      > Execution failed for AutoNamespaceTransform: /Users/zsweers/.gradle/caches/transforms-2/files-2.1/bc56df301aa7a093beed88eff5a85463/com.google.android.material.
         > Failed to auto-namespace com.google.android.material

This appears to be because it ships with a public.txt file in the aar with reference types, which are not a valid ResourceType. I believe this is coming from attrs.xml files

reference popupMenuBackground
reference values

These come from here:
https://github.com/material-components/material-components-android/blob/147620fc10694b9756f24746b7428a62fa4264ef/lib/java/com/google/android/material/menu/res/values/attrs.xml#L20
https://github.com/material-components/material-components-android/blob/5fb796437291ce6b7d43b3beba13a42256db6eac/lib/java/com/google/android/material/slider/res/values/attrs.xml#L67

Which eventually leads to this exception in AGP

Caused by: java.io.IOException: Invalid resource type reference
        at com.android.ide.common.symbols.SymbolIo.readPublicTxtLine(SymbolIo.java:677)
        at com.android.ide.common.symbols.SymbolIo.access$600(SymbolIo.java:106)
        at com.android.ide.common.symbols.SymbolIo$ReadConfiguration$6.parseLine(SymbolIo.java:789)
        at com.android.ide.common.symbols.SymbolIo$SymbolLineReader.readLines(SymbolIo.java:402)
        ... 115 more

Expected behavior: The library should ship valid a valid public.txt in its AAR

Source code: Try to use material components in a project with namespaced resources available. AGP will fail when it runs its auto-namespace transform

Android API version: N/A build-time

Material Library version: All of them and on master currently.

Device: N/A

bug

Most helpful comment

Looks like this is because a few places in res-public use type="reference" instead of type="attr". Will submit the fix.

All 6 comments

Thanks for reporting @ZacSweers. Does this happen with 1.2.0-rc01?

Oh nvm now I see your Material Library version: All of them and on master currently.

Sorry @ZacSweers, how can I enable namespaced resources in AGP 4.1?
I didn't find nothing online

It's an option under android.aaptOptions in gradle, or there's a gradle property you can set (I don't remember off hand what it is)

Thank you for the input, probably is this one: https://developer.android.com/reference/tools/gradle-api/com/android/build/api/dsl/AaptOptions#namespaced
will test this tonight

Looks like this is because a few places in res-public use type="reference" instead of type="attr". Will submit the fix.

Was this page helpful?
0 / 5 - 0 ratings