【问题标题】:Why does my custom buildtype gives apk not signed error为什么我的自定义构建类型会给出 apk 未签名错误
【发布时间】:2019-05-09 23:57:24
【问题描述】:

我有以下app.gradle 配置:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    debug {
        debuggable true
        // more configs here
    }

    staging {
        externalNativeBuild {
            cmake {
                cppFlags "-DDEBUG_FLAG"
            }
        }
    }
}

staging 构建类型给出错误:

您当前选择的变体的 apk 未签名。

【问题讨论】:

    标签: android android-gradle-plugin android-build-type


    【解决方案1】:

    显然,只有构建类型 releasedebug 配置了签名密钥。对于自定义构建类型,您必须通过以下方式手动设置:

    1) 使用调试的签名配置

    staging {
        signingConfig signingConfigs.debug
        ...
    }
    

    2) 从配置了签名密钥的构建类型继承

    staging {
        initWith debug
        ...
    }
    

    3) generate a new key 并创建您自己的签名配置

    android {
        signingConfigs {
            keyStagingApp {
                keyAlias 'stagingKey'
                keyPassword 'stagingKeyPassword'
                storeFile file('../stagingKey.jks')
                storePassword 'stagingKeyPassword'
            }
        }
        ...
    }
    

    然后像这样配置暂存:

    staging {
        signingConfig signingConfigs.keyStagingApp
        ...
    }
    

    【讨论】:

    • 为什么你不只是将staging 重命名为debug ...虽然只有两种构建类型?
    • 我需要暂存构建类型。为简洁起见,我刚刚删除了调试构建类型。
    • 如果没有此配置,这不再是一个 MCVE;因此,了解实际情况是相关的——因此我对此提出了疑问。 stackoverflow.com/help/mcve
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    相关资源
    最近更新 更多