设置 debug 版本签名与生产版本一致

debug 版本使用生产版本的签名

  • 在开发过程中,app 直接跑到手机上,用的签名文件是 Android Studio 默认的自动生成的一个签名,与生产版本的 app 签名是不一样的。当接入华为推送的时候,发现 debug 版本的签名不一致,造成初始化失败,所以需要把 debug 版的签名也修改为生产的签名
    1. 在 module 的 build.gradle 中配置签名文件和信息

       signingConfigs {
           releaseConfig {
               storeFile file('keystore/signing.keystore')
               storePassword "123456789"
               keyAlias "gradle"
               keyPassword "123456"
           }
       }
      
    2. 在 build.gradle 的配置 debug 版本

       debug {
           minifyEnabled false
           ......
           signingConfig signingConfigs.releaseConfig
       }
      

以上操作以后,每次跑到手机上的 bebug 的版本签名与生产的签名是一致的。

debug 版本安装的时候提示 INSTALL_FAILED_INVALID_APK

  • 根据以上操作把 debug 版本的签名更换为生产的签名,点击 run ,安装的时候提示了错误::

    INSTALL_FAILED_INVALID_APK: /data/app/vmdl654475879.tmp/8_slice__ signatures are inconsistent

  • 解决办法: clean project ,然后在 run ,就可以了。

signing.KeytoolException:XXX :Cannot recover key

  • debug 版本配置好了以后,在最后签名的时候显示了如下的错误:

    com.android.ide.common.signing.KeytoolException: Failed to read key xxx from store "D:gitlabdevelopxxxAndroid_developxxxkeystorexxx.keystore": Cannot recover key

  • 可能的原因:keystore 或者密码错误造成的。

  • 解决办法:

    1. 使用正确的 keystore
    2. 使用正确的密码
原文地址:https://www.cnblogs.com/liyiran/p/8556634.html