1.需求,板型有很多,一套代码在不同板子上,使用的签名不同,需要单独签名,于是就有了如下配置
2.配置app的build.gradle
plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' } android { namespace 'com.example.test' compileSdk 31
添加signingConfigs 配置不同的签名文件
signingConfigs { RK3568 { keyAlias 'fe-a3568' keyPassword '123456' storeFile file('../key/fe-a3568-old.keystore') storePassword '123456' } RK3399 { keyAlias '3399androidkey' keyPassword 'abc.123' storeFile file('../key/3399androidp.keystore') storePassword 'abc.123' } } defaultConfig { applicationId "com.example.test" minSdk 24 targetSdk 31 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
签名配置需要设置为null 不然指定具体签名文件后,就不会根据product的变化选择不同的签名文件了
signingConfig null } debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig null } } 配置不同的板型属性,使用不同的签名文件 productFlavors { RK3568 { signingConfig signingConfigs.RK3568 versionCode 1//该风味版本码 versionName "1.0"//该风味版本名称 dimension "1" } RK3399 { signingConfig signingConfigs.RK3399 versionCode 1//该风味版本码 versionName "1.0"//该风味版本名称 dimension "1" } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } dataBinding { enabled = true } } dependencies { implementation 'io.reactivex.rxjava3:rxjava:3.0.4' implementation 'io.reactivex.rxjava3:rxandroid:3.0.0' implementation 'org.greenrobot:eventbus:3.0.0' implementation 'androidx.core:core-ktx:1.8.0' implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' }
productFlavors配置签名 - 简书 (jianshu.com)
(345条消息) Android Studio 通过gradle配置 配置构建变体 组合多个产品风味 打包生成不同包名不同资源apk_蓝色的天空yyy的博客-CSDN博客