Archinamon / android-gradle-aspectj

gradle plug-in adding supports of AspectJ into Android project
Apache License 2.0
364 stars 58 forks source link

Multidex support with instant run #32

Closed vincentbrison closed 7 years ago

vincentbrison commented 7 years ago

Hi,

Does this plugin support multidex ? With the following configuration I end up with an empty (with ressources but no class) APK :

com.android.tools.build:gradle:2.2.3
com.github.Archinamon:GradleAspectJ-Android:2.2.2
compileSdkVersion = 25
buildToolsVersion = '25.0.1'
minSdkVersion = 21
targetSdkVersion = 25

Btw I am using java 7 sources and Proguard is disable.

When I disable the plugin, the multidex is working, giving me an normal apk.

Using Aspectj plugin without Transform API (like this one or the one from this plugin) seems to works with Multidex.

Thanks for the support and let me know if you need further info.

Archinamon commented 7 years ago

Hello! Did you use InstantRun? Unfortunately it leads to exclude of some classes on transformInstantRunSlicer step. Switching IR off may fix the problem. Also you may look into app/build/ajc-details.log file and post here any errors if they are.

vincentbrison commented 7 years ago

Thanks for the quick reply.

Yes I am using Instant Run. It is working without. But I would like to use Instant Run, Multidex, and AOP. There is no error in ajc-details.log, just reports of my aspects beeing applied.

So you would not recommand to rely on both Instant Run and AOP at the same time ?

Archinamon commented 7 years ago

At this moment I can say that my transformer doesn't lead to excluding any classes from final Dex and my mind the InstantRun works in unpredictable way. I have tried to find where am I wrong and still no useful info found. I'd recommend to switch off IR if you wanna use native aspects or change plugin that works well with IR if you're using annotation style.

vincentbrison commented 7 years ago

When I am looking into the generated classes, it seems to work well indeed.

Maybe the Transform API and Instant Run are not very compatible. It always great to have you feedback on this subject since there is not a lot of people doing AspectJ on Android.

Will look into it in the future.

BR.

Archinamon commented 7 years ago

I'll post update as soon as I find the solution for InstantRun support. Thanks for your feedback! Feel free to post any issues or questions you'll face with.

vincentbrison commented 7 years ago

Hello again,

I got update about this issue :).

At the end of the transform you apply this class https://github.com/Archinamon/GradleAspectJ-Android/blob/master/AspectJ-gradle/src/main/groovy/com/archinamon/api/AspectJMergeJars.groovy. I am not sure what its purpose is ? You seems to do some work on jar folders, but not on .class folder and at the end you are deleting the result dir from the weaving.

So I just commented this function, thus letting the .class folder weaved in place, and multidex instant run with aspect just succeed.

So Transform API is not well documented but I read that any class passed to the Transform as input should be present in the output, transformed or not. Could this class (AspectJMergeJars.groovy) be the source of the error ? I did fork your repository to do the tests (https://github.com/vincentbrison/GradleAspectJ-Android) if you want try yourself.

BR

Archinamon commented 7 years ago

Hello, Vincent!

Good suggest. I did look into it too before. This step was need to proceed two important goals:

If you have got it to work — it's wonderful :) I'll play with it this holidays or next week certainly. Thanks for your investigating!

vincentbrison commented 7 years ago

Thats great if you can look into it in the futur. I am not very confident with groovy :o . I will stick for this modification for now, waiting for your own investigation. Thanks for your feedback!

Archinamon commented 7 years ago

fixed in 2.3.0

vincentbrison commented 7 years ago

Seems to work fine :). What was the issue finally ?

Archinamon commented 7 years ago

Jar merger was the rudiment code, that was needed for proper work of proguard before gradle 2.2; but now this behavior leads to incorrect packaging of outputs and instantrun doesn't slice jars, only app code. So because of aspectj slicer thought no application code was available and strips nothing into spk :D I'm happy we finally found the logic of this behavior.