buildプラグインをgradle 3にアップグレードします.0+マルチチャネルパッケージアプリケーションバリアント、compile構文交換

3940 ワード

Android Studioが3.0+にアップグレードされるにつれて、付属のbuildプラグインも2.xを3にアップグレードx時代には、アップグレードがあれば調整されます.次に、出会った文法の変更をリストします.
       : compile =》 implementation
    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    }
    =》
    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
   }

----------
       apk     :
 //          
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                File outputDirectory = new File(outputFile.parent);
                def fileName
                if (variant.buildType.name == "release") {
                    //   apk  
                    fileName = "Xxx_v${defaultConfig.versionName}_${variant.productFlavors[0].name}.apk"
                } else {
                    fileName = "Xxx_v${defaultConfig.versionName}_${"Test"}_debug.apk"
                }
                output.outputFile = new File(outputDirectory, fileName)
            }
        }
    }
=>
applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                def fileName
                if (variant.buildType.name == "release") {
                    //   apk   
                    fileName = "Xxx_v${variant.versionName}_${variant.productFlavors[0].name}.apk"
                } else {
                    fileName = "Xxx_v${variant.versionName}_${"Test"}_debug.apk"
                }
                outputFileName = fileName
            }

        }
    }

----------
       flavorDimensions  (     )
flavorDimensions "channel"  //    "api", "channel"
              ,     。
 productFlavors {
        googleplay { dimension "channel" }
        qh360 { dimension "channel" }
        tengxun { dimension "channel" }
}

             
productFlavors.all {
        flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
    }

    
 productFlavors {
    googleplay { 
        dimension "channel"
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "googleplay"] }           
    qh360 { 
        dimension "channel"
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "qh360"]   }    
   tengxun { 
        dimension "channel"
        manifestPlaceholders = [UMENG_CHANNEL_VALUE: "tengxun"] }    
    }

           api
  :       minApi21 {
            dimension "api"
            minSdkVersion '21'
            versionCode 10000  + android.defaultConfig.versionCode
            versionNameSuffix "-minApi21"
       }