美文网首页爱上AndroidAndroid知识
替换默认Android debug keystore

替换默认Android debug keystore

作者: 备忘君 | 来源:发表于2016-04-07 23:21 被阅读9524次

使用Android Studio开发,不需要前面的操作,请转至最后

为什么替换

Android开发中,在使用第三方的sdk(如,百度地图,微信分享,友盟统计等)提供的功能时通常都要事先申请密钥,在申请密钥时需要填写keystore的数字签名(SHA1)。这样,只有使用此keystore打包生成的apk才能正常的调用这些第三方提供的功能。如果你不想在每次修改相关代码后,都要执行繁琐的验证打包安装等流程,才能测试相应得功能的话,就将此keystore替换默认keystore吧。如果你不想你团队的每一个人都要申请一个自己密钥进行调试的话,就把你的keystore分发给他们,让他们替换了吧。

修改keystore信息

想要替换默认的keystore,那么你的keystore的密码、别名等信息必须和默认debug.keystore的一样,默认debug.keystore的信息如下:
Keystore name: “debug.keystore”
Keystore password: “android”
Key alias: “androiddebugkey”
Key password: “android”
CN: “CN=Android Debug,O=Android,C=US”

  1. 重命名.keystore文件名:将自己的.keystore修改名称修改为debug.keystore(可选,只是在输入下面的命令是,将debug.keystore更换为你的keystore文件名)
  2. 修改keystore密码为“android”:键入命令
    keytool -storepasswd -new android -keystore debug.keystore
    按提示输入原密码,修改密码完成
  3. 修改别名为androiddebugkey:
    keytool -changealias -keystore debug.keystore -alias 原别名 -destalias androiddebugkey,
    按提示输入keystore密码、alias 原密码、新密码、再次输入新密码

替换IDE的keystore

Eclipse

依次选择:Window->Preferences->Android->Build->Custom debug keystore,选择你刚刚修改完成的keystore文件。


eclipse截图

)

Intellij Idea

依次选择:Project structure -> Facets ->Packaging -> custom debug keystore,选择你刚刚修改完成的keystore文件。


intellij idea截图

Android Studio(不需要进行上面的步骤)

在项目的build.gradle的中引入如下代码:

android {
         //配置keystore签名
        signingConfigs {
            release {
                storeFile file("xxxxxxxxStore")
                storePassword "xxxxxxxx"
                keyAlias "xxxxxxxx"
                keyPassword "xxxxxxxx"
            }
        }
        buildTypes {
            debug {
                signingConfig signingConfigs.release
            }
            release {
                signingConfig signingConfigs.release
            }
        }
}

相关文章

网友评论

    本文标题:替换默认Android debug keystore

    本文链接:https://www.haomeiwen.com/subject/nmhvlttx.html