问题
I'm trying to convert Android app to lib module, without copying source. I did it (modified build.gradle file), and it syncs and builds, but when I add dependency to resulting AAR file into another project (where I want to use this lib) build fails and resource linking fails.
I can't understand why:
original app builds and runs
lib module (converted from app) builds
project that uses AAR from that lib does not builds, and finds error in this AAR.
For example, one of the possible errors is:
Android resource linking failed
error: resource style/TextAppearance.Design.Tab (aka bv.dev.aarlibtester:style/TextAppearance.Design.Tab) not found.
error: failed linking references.
So it says that resources not found, and point to dependencies that I used in that lib (in this example it's design
)
I created test project to demonstrate this on simple example.
Github
aar-res-app
is simple app project that usesdesign
dependencyaar-res-lib
is library created from this project (converted)aar-res-lib-tester
is simple app project that uses that lib.
Currently I renamed library package to do not match with application package, and using jar
instead of aar
.
I create it using Gradle -> root -> Tasks -> Other -> createFullJarRelease
.
Result is in Build > Intermediates > Full_jar > Release > CreateFullJarRelease > full.jar
回答1:
So real problem is that aar
and jar
created this way do not contain libraries on which them depend. If adding library this way, you need to add all its dependencies to project that uses it.
In my example it is implementation 'com.android.support:design:28.0.0'
.
If project contains a lot of such dependencies, you should add all of them. But you still can run in problem like "manifest merger failed" and other problems.
Or you can try to deploy your lib to maven or jitpack, but you need to setup this correctly to ensure that pom file will be generated with all needed dependencies, to be able to use this library easily.
来源:https://stackoverflow.com/questions/54548134/android-aar-lib-resource-linking-failed