相信不少人都用過aspactJ!,有同窗反應,在debug都狀態下打包測試是沒有問題的,可是在Release下,AOP失效了???java
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
}
}
}
}
複製代碼
if (!variant.buildType.isDebuggable()) {
log.debug("Skipping non-debuggable build type '${variant.buildType.name}'.")
return
}
複製代碼
看一下上面這一段代碼,若是構建的類型是非debug的,就會直接返回不會執行下面的配置代碼,也就是是說,若是當前構建類型是release,那麼就不會執行下面的配置,那麼配置若是不生效,aspctj也就不會生效了。因此必定要把這段代碼刪除掉!!!android
我相信有不少小夥伴被這個問題搞的焦頭爛額,甚至放棄AOPJ,我也不知道當初寫這個配置的人到底什麼目的,這讓第一次使用接觸aspactJ的小夥伴徹底沒有心理準備,總覺得問題出如今更深的其餘地方,會認爲編譯器或者混淆的問題,偏離了排查軌跡,會很容易忽略配置的排查,這是一種嚴重的誤導!app
最後,若是你覺的這個問題能幫到你,點個贊,讓更多的小夥伴看到這個問題。測試