I believe many people have used aspactJ! In the debug state, there is no problem to package the test, but in the Release state, AOP is invalid.
You are using the wrong Gradle configuration!!
This configuration is circulating on the Internet
final def log = project.logger final def variants = project.android.applicationVariants variants.all { variant -> if (! variant.buildType.isDebuggable()) { log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.") return } JavaCompile JavaCompile = variant. JavaCompile JavaCompile. DoLast {String[] args = [" -showweaveinfo ", "-1.8", "-inpath", javaCompile.destinationDir.toString(), "-aspectpath", javaCompile.classpath.asPath, "-d", javaCompile.destinationDir.toString(), "-classpath", javaCompile.classpath.asPath, "-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)] log.debug "ajc args: " + Arrays.toString(args) MessageHandler handler = new MessageHandler(true) new Main().run(args, handler) for (IMessage message : handler.getMessages(null, true)) { switch (message.getKind()) { case IMessage.ABORT: case IMessage.ERROR: case IMessage.FAIL: log.error message.message, message.thrown break case IMessage.WARNING: log.warn message.message, message.thrown break case IMessage.INFO: log.info message.message, message.thrown break case IMessage.DEBUG: log.debug message.message, message.thrown break } } } }Copy the code
Note that this configuration is problematic for gradle in the main app!! Please delete the following code!!
if (! variant.buildType.isDebuggable()) { log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.") return }Copy the code
If the build type is not DEBUG, the following configuration will not be executed. If the build type is release, the following configuration will not be executed. If the configuration does not take effect, aspCTJ will not take effect. So be sure to delete this code!!
I believe there are a lot of friend is the problem, or even give up AOPJ, I also don’t know when to write exactly what purpose this configuration, the first use contact aspactJ friend no psychological preparation, always think problem in other parts of the deeper, would think that the compiler or confusing problems, track off the screen, It is very easy to ignore the configuration of the screening, which is a serious misleading!
Finally, if you think the question will help you, give it a “like” and let more people see it.