adwiv / android-fat-aar

Gradle script that allows you to merge and embed dependencies in generted aar file
The Unlicense
1.46k stars 435 forks source link

Something is wrong with resource IDs #12

Closed DoDoENT closed 8 years ago

DoDoENT commented 8 years ago

It appears that this script does not properly handle resource IDs from multiple AARs.

I have an AAR that contains activities that require resources packaged in that AAR. All resources are referenced using R class from library's package name (com.first.library.R). Next, I have a second AAR which has its own activities and resources that are referenced via com.second.library.R and this AAR also needs first AAR (it calls its activities). This second library uses android-fat-aar script to build a fat AAR.

After fat AAR is built, it is imported in test application (application references AAR directly, it does not reference any of the library projects). Test application can be correctly built and can run on device/emulator. However, when an activity from first AAR is accessed, app crashes with java.lang.NoClassDefFoundError: Failed resolution of: Lcom/first/library/R$layout;. It appears that final APK does not have R class from first AAR available.

Can this be fixed?

If required, I can provide two sample projects that reconstruct the issue.

adwiv commented 8 years ago

I tried testing with a similar setup as explained by you and it worked. Can you please share a sample project? Have you used the word embedded for firstlibrary?

DoDoENT commented 8 years ago

Here is the zip containing a library project that adds activity which starts activity from a proprietary AAR available from Maven and test project that imports the merged AAR generated by library project: MergeAARTest.zip

adwiv commented 8 years ago

Worked for me with gradle plugin 1.5.0 The release aar generated by you was missing the Resources R file for the embedded library. Not sure if that is an issue with 2.0 plugin as I didn't test with it.

adwiv commented 8 years ago

I can confirm that compileReleaseJavaWithJavac does not use the generated R file from embedded library in 2.0.0-alpha3 which results in the problem. Will need to look into the code for the task in 2.0.0

Meanwhile a solution can be to change the path in the embedRClassFiles to the main/src

adwiv commented 8 years ago

Changing the path to main/src doesn't work either. Android 2.0.0 plugin seems to explicitly ignore all R.java files during compilation (tested by creating a R.java class in a different package). This seems to be tricky to fix, will check next week.

DoDoENT commented 8 years ago

Wow, it really works with gradle plugin 1.5.0. This is a great news! The 2.0.0 issue might be an upstream bug, or feature required to support instant run. I suggest filing a bug report to gradle plugin developers and ask their opinion on how to perform the same task with new plugin.

Let's keep this issue open until solution for plugin 2.0.0 is found. Thank you for helping me out.

DoDoENT commented 8 years ago

The 2.0.0 plugin has now been released and is now official tool for android development. Adding support for it should be important now.

mic331 commented 8 years ago

@adwiv Do you have plans to resolve this for 2.0.0? I too have multiple aars and your plugin is what currently works to bundle everything. If not, can you recommend an alternative?

maxxx commented 8 years ago

confirm this bug with "com.android.tools.build:gradle:2.1.2" and gradle 2.14. https://github.com/adwiv/android-fat-aar/issues/19 related

isometriq commented 8 years ago

Same here

Trinea commented 8 years ago

This problem is exist still when gradle is up 2.0.0, I thought whether can modify import xxx.xxx.lib.R of *.java of lib to import xxx.xxx.R?

adwiv commented 8 years ago

Fixed in latest version tested with android gradle 2.2.0. Kindly test and open new issue for any problems.

isometriq commented 8 years ago

Many thanks! will report when testing it

LilianaB commented 8 years ago

Hi,

I am testing the library with 'com.android.tools.build:gradle:2.2.1' and Gradle 3.1. I created my fat aar containing an .aar library. But when I try to use my newly created fat .aar library I get an error on the resources.

See attached image for reference.

screen shot 2016-10-14 at 11 01 16

Any idea of what can be happening? Thanks in advance.

adwiv commented 8 years ago

Hi, can you please test with the latest release of script.

If there are any problems please open a new issue?

There may be some change with gradle 3.1 as I am still using the bundled gradle 2.14.1

LilianaB commented 8 years ago

Hi

Thanks for the quick response. I tested with the last version I guess. I am using this: apply from: 'https://raw.githubusercontent.com/adwiv/android-fat-aar/master/fat-aar.gradle'

isometriq commented 8 years ago

I had problem with bundled resources and my pattern (in Android Studio) is to "Rebuild" every time when changing gradle files + sync. Try also the "Clean" operation.

maxim-petlyuk commented 7 years ago

I have the same issue as in the first mail. Try with gradle plugin 1.5 - unfortunately it doesn`t help. Maybe somebody find another solution