Archinamon / android-gradle-aspectj

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

Simple mode lacks JarMerging #44

Closed Badya closed 7 years ago

Badya commented 7 years ago

Preconditions: I have classpath dependecy added sa written in instruction. I use android library (my-library.aar) containing aspects for androidTest, and basically have no aspects in app itself. I have applied apply plugin: 'com.archinamon.aspectj' and configured includeAspectsFromJar 'my-library' in aspectj section. In ajc-transform.log i see an info that weaving was OK, and join points advised.

Problem: When i launch Instrumentation tests my app fails to start due to:

 java.lang.ClassNotFoundException: Didn't find class "com.example.MyApp" on path: DexPathList ...

Workaround: If we switch plugin to complex mode everything works like a charm:

apply plugin: 'com.archinamon.aspectj-ext'

Solution: Remove modeComplex() check from com.archinamon.api.AspectJTransform#transform(com.android.build.api.transform.TransformInvocation)

            // if (modeComplex()) {
            aspectJMerger.doMerge(this, transformInvocation, outputDir)
            // }
Archinamon commented 7 years ago

Removing this check you'll brake working in main module with InstantRun and will get a ZipException when instantRun slicer tries to merge all sources into single dex.

Badya commented 7 years ago

@Archinamon, as far as i concerned there are some issues about InstantRun and multidex support, so we can return this check, but need an update in README.md that using multidex requires complex mode - am i right?

Archinamon commented 7 years ago

Seems so. Another point is to make a aspectj-test plugin with a different configs. That look much more flexible in future :) This way we strictly define usage in tests mostly (without instantrun or some other features).

Badya commented 7 years ago

commited with #42 in message =(

Badya commented 7 years ago

@Archinamon, I think we can close this issue.