关于Android Studio 更新到3.0版本以后出现的一些问题以及解决方案

分析:尤其是采用butterknife工具的,采用新的Android Studio都会出现这样的问题,我根据提示最后猜测原因可能是Android studio更新,然后gradle更新了,这样的话可能使原来的android-apt工具跟不上节奏了,所以让采用annotationProcessor工具。

解决方法:

1、修改project下的build.gradle当中的依赖

修改之前的代码:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'me.tatarka:gradle-retrolambda:3.2.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}


task clean(type: Delete) {
    delete rootProject.buildDir
}


修改之后的代码:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

2、然后再修改Module.app里的build.grade里的配置

去除apply plugin: 'android-apt'

3、另外需要把之前apt方式的引用改下,例如:

apt 'com.jakewharton:butterknife-compiler:8.4.0'  改为 annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' 这种方式。


按照上述方式修改之后,再次运行如果出现下图情形,按照解决方案解决就行,如没有请忽略


解决方案:关掉AAPT2即可 ,在Project/gradle.properties中添加 android.enableAapt2=false

android.enableAapt2=false


上述两个问题都解决了之后,你以为一运行就完事了嘛,别着急还有^_^

也许还会出现下面这个问题,如果出现,就按照下面解决方案解决,如若没有请忽略

报错日志:

Error:Execution failed for task ':CNKI:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - lombok-1.16.12.jar (org.projectlombok:lombok:1.16.12)
  Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
  See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

解决方案:在Module.app里的build.grade里的android defaultCondig下添加,即可

        javaCompileOptions {
            annotationProcessorOptions { includeCompileClasspath = true }
        }

以上就是在更新过AS新版以后遇到的问题以及解决方案^_^




猜你喜欢

转载自blog.csdn.net/lvshuchangyin/article/details/78354721
今日推荐