项目向Android Studio3.0迁移过程中遇到的问题集合

最近将老项目迁移到Android Studio3.0过程中遇到了不少的问题,当然这些问题都能在网上找到解决的办法。以下都是我遇到的问题,在这里我主要是做一个总结,希望能帮到你。

1.Error:The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported     version (26.0.2) for Android Gradle Plugin 3.0.0.

Android SDK Build Tools 26.0.2 will be used.

To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the    Android Gradle Plugin now has a default version of the build tools.

错误提示截图

错误原因:SDK的构建版本低于Android Gradle插件3.0.0的最低支持版本(26.0.2)

解决方法:只需要将SDK的构建版本升级到26.0.2以上即可(项目中的Modules也需要修改)

2. Error:All flavors must now belong to a named flavor dimension. Learn more at     https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

错误提示截图

错误原因:因为使用了productFlavors分包(即多渠道打包)

解决方法: 在build.gradle中的defaultConfig中添加一个flavorDimensions "versionCode"就可以了,该versionCode是项目中的版本号(改成版本号即可)

项目向Android Studio3.0迁移过程中遇到的问题集合_第1张图片
productFlavors分包

添加后:

项目向Android Studio3.0迁移过程中遇到的问题集合_第2张图片
添加后

3. Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception:

错误提示截图

解决方案:在gradle.properties中关闭APPT2 编译,在gradle.properties中加上android.enableAapt2=false即可。

4. Error:Unable to resolve dependency for ':app@flavorsPre/compileClasspath': Could not resolve project     :audiorecorder.

项目向Android Studio3.0迁移过程中遇到的问题集合_第3张图片
错误提示截图

错误原因:app下build.gradle里面的buildTypes配置和module下build.gradle中的buildTypes配置不一样。

App下有“debug”、“pre”、“release”:

项目向Android Studio3.0迁移过程中遇到的问题集合_第4张图片
App下build.gradle的buildTypes

而module下的只有“release”:

项目向Android Studio3.0迁移过程中遇到的问题集合_第5张图片
Module下build.gradle的buildTypes

解决办法:在module下,添加"pre"、"debug",保证modlue和app下的buildTypes配置相同。

添加后:

项目向Android Studio3.0迁移过程中遇到的问题集合_第6张图片
添加后

5. Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found tocontain annotation processor. Please add them to the annotationProcessor configuration. - butterknife-7.0.1.jar Alternatively, setandroid.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue withprevious behavior. Note that this option is deprecated and will be removed in the future.

错误原因:使用butterknife出现的问题,这是注解适配问题,新的 gradle 插件不再支持 annotation processors

解决办法:在app下的build.gradle中的defauleConfig中添加一下代码即可(需要使用需要显式声明):

javaCompileOptions {

    annotationProcessorOptions {

        includeCompileClasspath= true

    }

}

添加后:

项目向Android Studio3.0迁移过程中遇到的问题集合_第7张图片
添加后

6.Error:(36, 0) Cannot set the value of read-only property 'outputFile' for          ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=flavorsPre, filters=[]}} of type     com.android.build.gradle.internal.api.ApkVariantOutputImpl.

错误提示截图

解决方法:1.使用all()来替换each();2.使用outputFileName来替换output.outputFile

替换前:

项目向Android Studio3.0迁移过程中遇到的问题集合_第8张图片
替换前

替换后:

项目向Android Studio3.0迁移过程中遇到的问题集合_第9张图片
替换后

你可能感兴趣的:(项目向Android Studio3.0迁移过程中遇到的问题集合)