JavaCompile将被移除的问题

WARNING: API ‘variant.getJavaCompile()’ is obsolete and has been replaced with ‘variant.getJavaCompileProvider()’.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.
Affected Modules: app

这个问题是在在Android中使用aop编程的时候用到的,虽然只是个警告,但是随着gradle的版本的升级,搞不好哪天就不让用了呢,所以还是解决到比较好,解决之道也很简单:

       JavaCompile javaCompile
        if (variant.hasProperty('javaCompileProvider')) {
            //android gradle 3.3.0 +
            javaCompile = variant.javaCompileProvider.get()
        } else {
            javaCompile = variant.javaCompile
        }

这个还是看这个https://github.com/HujiangTechnology/gradle_plugin_android_aspectjx的代码是看见的,所以完成的gradle的代码入下:


    // 下面是AspectJ的编译配置文件
    import org.aspectj.bridge.IMessage
    import org.aspectj.bridge.MessageHandler
    import org.aspectj.tools.ajc.Main
    final def log = project.logger

    android.applicationVariants.all { variant ->


//        JavaCompile javaCompile = variant.javaCompile
        JavaCompile javaCompile
        if (variant.hasProperty('javaCompileProvider')) {
            //android gradle 3.3.0 +
            javaCompile = variant.javaCompileProvider.get()
        } else {
            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
                }
            }
        }
    }
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

悟红尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值