Search code examples
androidgradleaspect

Android aspect No such property: project for class: com.android.build.gradle.LibraryPlugin


I am use aspect, the problem is come out when upgrade gradle from 2.2.3 to 2.3.0 in this line :

"-bootclasspath", plugin.project.android.bootClasspath.join(
            File.pathSeparator)]

here is the full build.gradle

android.libraryVariants.all { variant ->
LibraryPlugin plugin = project.plugins.getPlugin(LibraryPlugin)
JavaCompile javaCompile = variant.javaCompile
javaCompile.doLast {
    String[] args = ["-showWeaveInfo",
                     "-1.5",
                     "-inpath", javaCompile.destinationDir.toString(),
                     "-aspectpath", javaCompile.classpath.asPath,
                     "-d", javaCompile.destinationDir.toString(),
                     "-classpath", javaCompile.classpath.asPath,
                     "-bootclasspath", plugin.project.android.bootClasspath.join(
            File.pathSeparator)]

    MessageHandler handler = new MessageHandler(true);
    new Main().run(args, handler)

    def log = project.logger
    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:
            case IMessage.INFO:
                log.info message.message, message.thrown
                break;
            case IMessage.DEBUG:
                log.debug message.message, message.thrown
                break;
        }
    }
}

}

here is the error

11:14:38.176 [ERROR] 
[org.gradle.internal.buildevents.BuildExceptionReporter] Build file '************/build.gradle' line: 42
11:14:38.176 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
11:14:38.176 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
11:14:38.176 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':yfdaq:compileReleaseJavaWithJavac'.
11:14:38.176 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > No such property: project for class: com.android.build.gradle.LibraryPlugin
11:14:38.176 [ERROR] 

Solution

  • @yefeng for now to run your application you can remove below line of codes from library level build.gradle

    LibraryPlugin plugin = project.plugins.getPlugin(LibraryPlugin)
    

    and

    , "-bootclasspath", plugin.project.android.bootClasspath.join(
                    File.pathSeparator)
    

    and sync gradle, work for me, at least i can log message now.