公司项目中我们公司测试使用测试包测试。因为用到了百度地图导致debug版本的签名只能在我的电脑打debug才可以用,release版本没有问题。所以要解决这个问题。
于是我想着在debug模式下面直接调用正式版本的签名不就好了,所以有了这边文章。
如何使用?
很简单:
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
signingConfigs {
config {
keyAlias 'demo'
keyPassword '123456'
storeFile file('./user.jks')
storePassword '123456'
}
}
defaultConfig {
// applicationId "com.reapal.wallet"
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode rootProject.ext.android.versionCode
versionName rootProject.ext.android.versionName
flavorDimensions "versionCode"
defaultPublishConfig 'debug'
// publishNonDefault true
}
buildTypes {
debug {
ext.enableCrashlytics = false
signingConfig signingConfigs.config
}
release {
minifyEnabled false
zipAlignEnabled true
shrinkResources false
/*此debuggable设置成true后在debug模式下也可用正式签名*/
debuggable true
signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
delete fileTree(project.rootDir.absolutePath + "/") {
include '*v1.0.apk'
}
/* android.applicationVariants.all { variant ->
variant.outputs.all {
variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + "/")
outputFileName = "${variant.productFlavors[0].manifestPlaceholders.get("UMENG_CHANNEL_VALUE")}_${variant.productFlavors[0].name}_v${defaultConfig.versionName}.apk"
}
}*/
}
}
}
只需要在debug里面配置release版本一样的配置即可也就是:
signingConfig signingConfigs.config这行配置
然后要在release配置里面加上一行代码:
/*此debuggable设置成true后在debug模式下也可用正式签名*/
debuggable true
就可以了,每次直接运行就是正式签名包了,可解决第三方分享,微信支付等需要正式签名包的调试了。