androidandroid-gradle-pluginandroid-build-type

Why does my custom buildtype gives apk not signed error


I have the following app.gradle configuration:

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

    debug {
        debuggable true
        // more configs here
    }

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

The staging build type gives error:

The apk for your currently selected variant is not signed.


Solution

  • Apparently, only buildtypes release and debug are configured with signing keys. For custom buildtypes, you have to manually set it by:

    1) using the signing config of debug

    staging {
        signingConfig signingConfigs.debug
        ...
    }
    

    OR

    2) inherit from a buildtype that has signing key configured

    staging {
        initWith debug
        ...
    }
    

    OR

    3) generate a new key and create your own signing configuration

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

    then configure the staging like so:

    staging {
        signingConfig signingConfigs.keyStagingApp
        ...
    }