寫在前面
應屆畢業Android仔在新公司上班的第三個月,月底轉正。
Android Studio 發布3.0正式版,今天一早來上班,想瞧瞧新的版本又什么新奇又好玩的功能,手賤點了更新,然后就悲催了。一堆Error,exm?趕著發版呢老弟!bulu bulu bulu ,搬梯子上墻,bye~
以及,我的
buildToolsVersion 26.0.2
第一個錯誤:
指向--------------->
Error:(120, 0) Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=*****, fullName=*****, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.Open File
這個錯誤是由于升級了3.0后,AS API做了一些改變,引入原話
Android plugin 3.0.0 introduces API changes that removes certain functionalities and may break your existing builds. Later versions of the plugin may introduce new public APIs that replace broken functionalities.
用我蹩腳的英文水平翻譯一下?
大概就是說3.0版本的AS對某些API做了一些修改,而這些修改會導致你現有的一些方法不管用了。不過不要怕,后續的版本會逐步推出一些新的公共API去修復它們。
然后官方的建議是
emmm,我先放一下官方的鏈接吧Android Studio 3.0 官方API文檔?
以及
Step 1
// If you use each() to iterate through the variant objects,
// you need to start using all(). That's because each() iterates
// through only the objects that already exist during configuration time—
// but those object don't exist at configuration time with the new model.
// However, all() adapts to the new model by picking up object as they are
// added during execution.
android.applicationVariants.all{variant->
variant.outputs.all{
outputFileName="${variant.name}-${variant.versionName}.apk"
}
}
也就是說,我原先的output.outputFile =newFile(outputDirectory, fileName)不管用了
根據黨和官方的只是,改為outputFileName = fileName //這個是你的app名字喲喂,不要直接Copy,記得記得記得
Step 2
把這個?each?改為?all?
ok,Sync Project一下
發現又出來個新的錯誤
Error:android-apt plugin is incompatible with the Android Gradle plugin.? Please use 'annotationProcessor' configuration instead.
Step 3 :Error:android-apt plugin is incompatible with the Android Gradle plugin.? Please use 'annotationProcessor' configuration instead.
是因為我使用了apt插件,然而人家根本就不需要了這個好嗎?
把這個apt改為 annotationProcessor?
把這個插件去掉
Step 4 :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
大概就是flavor都要屬于一個維度什么的,要同一種風格巴拉巴拉的,才不管那么多...趕時間呢老鐵,那么如何解決?So Easy!
把這行加上 給你Copy算了? flavorDimensions"versionCode"
噢,最后這里
如果你也做了這個,先注釋掉吧老鐵,我還沒找到替代方法。
問題解決,拜拜您吶老鐵,滴,下班打卡!
已經下班15分鐘了,我還在碼字,如果對你有用,不如,點個贊?
第一篇簡書獻給各位看官~