10

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 uses design dependency

  • aar-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

B-GangsteR
  • 2,534
  • 22
  • 34
  • I can't see any "build" folder in your "aar-lib-res-problem/aar-res-lib" repository. By the way, why are you including the .aar file in your gradle by "implementation files("../../aar-res-lib/app/build/outputs/aar/app-release.aar")" instruction instead of simply put the file inside the lib folder of your app? – Nicola Gallazzi Feb 06 '19 at 07:07
  • @NicolaGallazzi "build" folders are ignored by standard .gitignore, and are not included into commits. I tried this approach too, it doesn't changes result. – B-GangsteR Feb 06 '19 at 07:16
  • Did you try by removing the AppTheme from your library module? It has the same name of your app's module one and maybe is causing some conflicts in solving dependencies – Nicola Gallazzi Feb 06 '19 at 07:28
  • @NicolaGallazzi tried to rename it, and also other similar names, but after all it shows the same error again – B-GangsteR Feb 06 '19 at 07:47

1 Answers1

8

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.

B-GangsteR
  • 2,534
  • 22
  • 34