我遇到错误,在我的gradle文件中,“javaCompile.doLast”不起作用, 这是我的gradle文件
import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
import org.aspectj.tools.ajc.Main
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.aspectj:aspectjtools:1.8.5'
}
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
lintOptions {
checkReleaseBuilds true
abortOnError true
}
}
final def log = project.logger
final def variants = project.android.applicationVariants
variants.all { variant ->
println "AAAAAAAA";
JavaCompile javaCompile = variant.javaCompile
javaCompile.doLast {
println "CCCC"
String[] args = ["-showWeaveInfo",
"-1.5",
"-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)
println "BBBBBBB";
println javaCompile.destinationDir.toString()
println javaCompile.classpath.asPath
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;
}
}
}
}
repositories {
mavenCentral()
}
当我运行gradle信息时, 我可以看两次“AAA”打印,但“BBB”和“CCC”不打印, 我不知道gradle文件中有什么问题, 我从https://github.com/android10/Android-AOPExample
复制“变体”============更新=======================
抱歉,这是我的错, 如果在命令行中运行“gradle clean build”,它可以工作,并且当我在Intellij中按下运行按钮时工作正常,但是如果我没有运行命令,如果我在Intellij中按下运行按钮,这将无法工作,
所以一个新问题,“命令行”和“Intellij运行按钮”不同,