debugging – Android Studio: how to create a second debug build type-ThrowExceptions

Exception or error:

I want to create a second build type that should work exactly as the already existing debug type. Currently I have two build types: debug and release. The debug one can be run with a single click, and is automatically signed with the debug keystore.
I manually compile the release build through the Build -> Generate signed APK wizard.

So to clone the debug build type, I first added a second build type named “local” to the app build.graddle file:

buildTypes {
    ...
    debug {
        debuggable true
        minifyEnabled false
    }
    local {
        debuggable true
        minifyEnabled false
    }
}

Then I created app/src/local/res and added some files.

Then I do a gradle resync and select the new build type in the left tab:
build type tab

Finally I click the run button and I expected it to just work. This IntelliJ help article says the debug signing config is the default:

This means that if you do not configure an artifact manually and
select the Deploy default APK option in the Run/Debug Configuration:
Android Application dialog box, IntelliJ IDEA will use the predefined
values in the certificate for the generated

Instead, this dialog is shown:

run dialog

When I click the fix button, it opens the signing config dialog for the whole app module. However, I don’t want to sign this apk for release, I need it signed with the debug cert. Also I noticed that a new assembleLocal gradle task has been created, but it generates an unaligned apk. In this folder I can see the regular debug apks are generated correctly in their unaligned and final versions.

How on Earth can I just clone the debug build type?

How to solve:

You can specify in the build.gradle file which signingConfig should be used with the buildType.

To sign using the same signingConfig as the default debug buildType, use the following:

buildTypes {
    local {
        signingConfig signingConfigs.debug
    }

    /* NOTE: the debug block is not required because it is a default
     * buildType configuration; all of its settings are defined implicitly
     * by Android Studio behind the scenes.
     */
}

If you would prefer to use a custom keystore located on your local system, use the following instead:

signingConfigs {
    local {
        storeFile file("/path/to/custom.keystore")
        storePassword "password"
        keyAlias "MyLocalKey"
        keyPassword "password"
    }
}

buildTypes {
    local {
        signingConfig signingConfigs.local
    }
}

###

Also, you can make your Build type similar to debug using:

initWith(buildTypes.debug)

Here is an example:

...
buildTypes {

    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField 'String', 'URL_API_BASE_SERVICE', '"http://theidasworld.com"'
    }
    debug {
        versionName 'APP BETA'
        buildConfigField "Integer", "PIN", "0000"  
        buildConfigField 'String', 'URL_API_BASE_SERVICE', '"http://debug.theidasworld.com"'
    }
    inspection {
        initWith(buildTypes.debug) // keep versionName and PIN from 'debug'
        buildConfigField 'String', 'URL_API_BASE_SERVICE', '"http://inspection.theidasworld.com"'
    }
}
...

###

Other way could be using flavors, like so:

productFlavors {

  app1 {}

  app2 {}

}

Leave a Reply

Your email address will not be published. Required fields are marked *