为什么我的自定义构建类型给出 apk not signed 错误

Why does my custom buildtype gives apk not signed error

我有以下 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 构建类型给出错误:

The apk for your currently selected variant is not signed.

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

1) 使用 debug

的签名配置
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
    ...
}