Last active
February 20, 2019 10:50
-
-
Save angeldevil/7498f6622c5c31b8f635569b2676e35c to your computer and use it in GitHub Desktop.
Configure aspectj on Android. Just copy this script to your module's build.gradle file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'org.aspectj:aspectjtools:1.8.13' | |
} | |
} | |
final def log = project.logger | |
final def variants = project.android.hasProperty("applicationVariants") ? | |
project.android."applicationVariants" : | |
project.android."libraryVariants" | |
variants.all { variant -> | |
JavaCompile javaCompile = variant.javaCompile | |
javaCompile.doLast { | |
String[] args = ["-showWeaveInfo", | |
"-1.7", | |
"-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 | |
} | |
} | |
} | |
} | |
dependencies { | |
api 'org.aspectj:aspectjrt:1.8.13' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment