打包批处理方法整理

//先通过project structure 编辑签名信息


signingConfigs {
        release {
            storeFile file('D:\\work_space\\MyApplication3\\test.jks')
            storePassword '12345678'
            keyPassword '12345678'
            keyAlias 'key0'
        }
    }

然后创建你想批量打包的包名versioncode 等信息.

 

 productFlavors {
        aa1 {
            applicationId "com.test.bb1"
            resValue "string", "app_name", "bb1"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
        aa2 {
            applicationId "com.test.aa2"
            resValue "string", "app_name", "aa2"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
        aa3 {
            applicationId "com.test.aa3"
            resValue "string", "app_name", "aa3"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }        
aa4 {
            applicationId "com.test.aa4"
            resValue "string", "app_name", "aa4"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
        aa5 {
            applicationId "com.test.aa5"
            resValue "string", "app_name", "aa5"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
    }

指定编译出来的apk的命名规则,是否混淆

applicationVariants.all {
        variant ->
            variant.outputs.all {
                outputFileName = "${variant.productFlavors[0].applicationId}_${variant.productFlavors[0].versionName}_${variant.productFlavors[0].name}.apk"
            }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

这里特别声明,如果要混淆  配置好proguard-rules.p

ro,否则,编译出来的apk可能无法正常运行

还要加上如下一句,否则报错:

android{
....省略代码
flavorDimensions "default"
....省略代码
}

今天配置的时候还遇到了如下问题:no signature of method android

 

后来检查代码发现 minifyEnable 少加了个d,  应该是minifyEnabled  花了很多时间找原因。希望以后不再浪费这种时间了。

 

记得把strings.xml中的app_name删掉,否则无法编译通过。

 

最后我把整个demo的配置贴出来方便看

 

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    signingConfigs {
        release {
            storeFile file('D:\\work_space\\MyApplication3\\test.jks')
            storePassword '12345678'
            keyPassword '12345678'
            keyAlias 'key0'
        }
    }
    compileSdkVersion 30
    buildToolsVersion "30.0.0"
    flavorDimensions "default"
    productFlavors{
        aa1 {
            applicationId "com.test.bb1"
            resValue "string", "app_name", "bb1"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
        aa2 {
            applicationId "com.test.aa2"
            resValue "string", "app_name", "aa2"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
        aa3 {


            applicationId "com.test.aa3"
            resValue "string", "app_name", "aa3"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
        aa4 {
            applicationId "com.test.aa4"
            resValue "string", "app_name", "aa4"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
        aa5 {
            applicationId "com.test.aa5"
            resValue "string", "app_name", "aa5"
            versionName "1.0"
            versionCode 1
            signingConfig signingConfigs.release
        }
    }
defaultConfig {
        applicationId "com.test.dd"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}
dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值