最近將老項(xiàng)目遷移到Android Studio3.0過程中遇到了不少的問題,當(dāng)然這些問題都能在網(wǎng)上找到解決的辦法。以下都是我遇到的問題,在這里我主要是做一個(gè)總結(jié),希望能幫到你。
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.

錯(cuò)誤原因:SDK的構(gòu)建版本低于Android Gradle插件3.0.0的最低支持版本(26.0.2)
解決方法:只需要將SDK的構(gòu)建版本升級到26.0.2以上即可(項(xiàng)目中的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

錯(cuò)誤原因:因?yàn)槭褂昧藀roductFlavors分包(即多渠道打包)
解決方法: 在build.gradle中的defaultConfig中添加一個(gè)flavorDimensions "versionCode"就可以了,該versionCode是項(xiàng)目中的版本號(改成版本號即可)

添加后:

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

解決方案:在gradle.properties中關(guān)閉APPT2 編譯,在gradle.properties中加上android.enableAapt2=false即可。
4.?Error:Unable to resolve dependency for ':app@flavorsPre/compileClasspath': Could not resolve project ????:audiorecorder.

錯(cuò)誤原因:app下build.gradle里面的buildTypes配置和module下build.gradle中的buildTypes配置不一樣。
App下有“debug”、“pre”、“release”:

而module下的只有“release”:

解決辦法:在module下,添加"pre"、"debug",保證modlue和app下的buildTypes配置相同。
添加后:

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.
錯(cuò)誤原因:使用butterknife出現(xiàn)的問題,這是注解適配問題,新的 gradle 插件不再支持 annotation processors
解決辦法:在app下的build.gradle中的defauleConfig中添加一下代碼即可(需要使用需要顯式聲明):
javaCompileOptions {
? ? annotationProcessorOptions {
? ? ? ? includeCompileClasspath= true
? ? }
}
添加后:

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
替換前:

替換后:
