Android gradle plugin 3.0.0遷移問題

gradle 的版本需要升級(jí)4.1+,建議直接用4.3版本
gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

添加 google倉(cāng)庫(kù)

gradle plugin 3.0.0+support library 27+開始只放在了google倉(cāng)庫(kù)中了,不再jcenter中提供了

buildscript {
    repositories {
        google()
        jcenter()
    }
    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 {
        google()
        jcenter()
    }
}

buildToolsVersion

Android Studio 3.0.0 默認(rèn)可以不寫buildToolsVersion,默認(rèn)最低可用版本26.0.2
手動(dòng)修改 buildToolsVersion>=26.0.2

設(shè)置了productFlavors的必須設(shè)置flavorDimensions

buildType match問題

gradle 依賴的API變更

為了兼容使用gradle 4.3,目前是標(biāo)記為廢棄的,4.3后直接沒了
compile -> implementation (for app module)
compile -> api ( for sub module)
provided -> compileOnly
apk-> runtimeOnly

Studio 3.0 minimum

Error:This Gradle plugin requires Studio 3.0 minimum

gradle.properties

android.injected.build.model.only.versioned=3  

aapt2問題

AS3默認(rèn)使用aapt2處理,如果一些項(xiàng)目使用aapt2有問題,那么可以禁用掉,繼續(xù)使用原有的aapt。
gradle.properties

android.enableAapt2=false

獲取manifest文件路徑

修改apk名問題

以前的方式是 output.outputFile = xxxx

Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=normalDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

正確的姿勢(shì)

android.applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "${variant.name}-${variant.versionName}.apk"
    }
}

具體參考:
https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

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

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

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