您的位置:首页 > 移动开发 > Android开发

Android Studio 指定签名证书文件

2017-07-20 21:42 281 查看
1.先参照Android
Studio中创建keystore生成指定的证书文件。

2.在app/build.gradle文件中增加 signingConfigs字段:如下所示:

12345678910111213141516171819202122232425262728293031323334353637383940apply plugin: 'com.android.application' android {    compileSdkVersion 21    buildToolsVersion "21.1.0"    defaultConfig {        applicationId "com.test.example"        minSdkVersion 14        targetSdkVersion 21        versionCode 1        versionName "1.0"    }     signingConfigs {        debug {            File strFile = new File("../../Keystore/Debug/debug.jks")            storeFile file(strFile)            storePassword "storeDebug1234567890"            keyAlias "debugkey"            keyPassword "aliasDebug1234567890"            //println strFile.absolutePath;        }        release {            File strFile = new File("../../Keystore/Release/release.jks")            storeFile file(strFile)            storePassword "storeRelease1234567890"            keyPassword "keyRelease1234567890"            keyAlias "releasekey"            // println strFile.absolutePath;        }    }        buildTypes {        release {            signingConfig  signingConfigs.release            runProguard false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }}
注意1. storeFile, storePassword, keyAlias, keyPassword缺一不可,都必须填写,并且填写正确。如果没有填写 keyAlias,则签名时候会报告 Android-APK signing error : Failed toread key from keystore密码不正确的时候,会报告 Java.security.UnrecoverableKeyException: Cannot recoverkeyThis exception may result from the fact that you had provided a key password that wasdifferent from the keystore password2.对于 Release配置,在 buildTypes中必须指定

1

signingConfigsigningConfigs.release

否则,会出现

1

Error:Theapkforyourcurrentlyselectedvariant(app-release-unsigned.apk)isnotsigned.pleasespecifyasigningconfigurationforthisvariant(release)

3. signingConfigs必须在 buildTypes前面声明,否则会出现找不到配置选项的错误。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: