欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新

Gradle连载7-配置签名,APP被恶意篡改,签

来源: 开发者 投稿于  被查看 20405 次 评论:136

Gradle连载7-配置签名,APP被恶意篡改,签


一、配置签名信息

    /**
     * 1.testApplicationId用于配置测试App的包名,默认情况下是applicationId + ".test".一般情况下默认即可,他也是
     * ProductFlavor的一个属性,方法原型为
     * public ProductFlavor setTestApplicationId(String applicationId) {
     *     mTestApplicationId = applicationId;
     *     return this;
     * }
     *
     * public String getApplicatonId() {
     *     return mTestApplicationId;
     * }
     *
     * 2.testInstrumentationRunner
     * 用于配置单元测试使用的Runner,默认使用的是android.test.InstrumenttationTestRunner,
     * 如果自定义的Runner,修改这个值就可以,它也是一个属性,方法原型
     * public ProductFlavor setTestInstrument(String testInstrumentationRunner) {
     *     mTestInstrumentationRunner = testInstrumentationRunner;
     *     return this;
     * }
     *
     * 3.signingConfig
     * 配置磨人的签名信息,对生成的App签名,他是一个SigningConfig, 也是ProductFlavor的一个属性,他可以直接对其进行配置,方法原型为:
     * public SigningConfig getSigningConfig() {
     *     return mSigningConfig;
     * }
     *
     * public ProductFlavor setSigningConfig(SigningConfig signingConfig) {
     *     mSigningConfig = signingConfig;
     *     return this;
     * }
     *
     * 4. proguardFile
     * 用于配置App ProGuard混淆所使用的ProGuard配置文件,它是ProductFlavor的一个方法,接受一个文件作为参数,其方法原型为:
     * public void proguardFile(Object proguardFile) {
     *     getProguardFiles().add(project.file(proguardFile));
     * }
     *
     * 5.proguardFiles
     * 这个也是配置ProGuard的配置文件,只不过他可以同时接受多个配置文件,因为它的参数是一个可变类型的参数
     * public void proguardFiles(Object... proguardFileArray) {
     *     getProguardFiles.addAll(project.files(proguardFileArray).getFiles());
     * }
     */

1.使用混淆示例

    release {
        minifyEnabled false
        // 使用混淆功能
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  • minifyEnable表示启用混淆功能

二、签名信息

1.一些注意事项

  • APP必须签名才能发布使用。
  • APP被恶意篡改,签名变动,就无法安装升级。
  • APP有debug和release两种,debug模式一般AndroidSDK已经为我们提供了默认证书,release要使用自己的证书

2.进行举例

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    signingConfigs {
        release {
            storeFile file("myreleasekey.keystore")  // 签名文件
            storePasswork "password" // 签名文件的密码
            keyAlias "MyReleaseKey" // 签名证书中秘钥别名
            keyPassword "password" // 该证书中秘钥的密码
            // 还有一个属性storeType签名证书的类型
        }
    }
     debug {
        storeFile("mydebugkey.keystore")
        storePasswork "passwork"
        keyAlias "MyDebugKey"
        keyPassword "password"
    }
}

三、源码

  • gitee路径:https://gitee.com/dongqianrui/AndroidStudioProject/tree/master/Test1
  • CSDN:https://blog.csdn.net/weixin_44630050
  • 博客园:https://www.cnblogs.com/ruigege0000/
  • 欢迎关注微信公众号:傅里叶变换,个人账号,仅用于技术交流

相关文章

    暂无相关文章

用户评论