項(xiàng)目向Android Studio3.0遷移過程中遇到的問題集合

最近將老項(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ò)誤提示截圖

錯(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ò)誤提示截圖

錯(cuò)誤原因:因?yàn)槭褂昧藀roductFlavors分包(即多渠道打包)

解決方法: 在build.gradle中的defaultConfig中添加一個(gè)flavorDimensions "versionCode"就可以了,該versionCode是項(xiàng)目中的版本號(改成版本號即可)

productFlavors分包

添加后:

添加后

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

錯(cuò)誤提示截圖

解決方案:在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ò)誤提示截圖

錯(cuò)誤原因:app下build.gradle里面的buildTypes配置和module下build.gradle中的buildTypes配置不一樣。

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

App下build.gradle的buildTypes

而module下的只有“release”:

Module下build.gradle的buildTypes

解決辦法:在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.

錯(cuò)誤提示截圖

解決方法:1.使用all()來替換each();2.使用outputFileName來替換output.outputFile

替換前:

替換前

替換后:

替換后
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容