Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: how to create a second debug build type

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?

like image 649
Mister Smith Avatar asked Jan 27 '16 09:01

Mister Smith


People also ask

How do I create a build variant?

You can change the build variant to whichever one you want to build and run—just go to Build > Select Build Variant and select one from the drop-down menu. To start customizing each build variant with its own features and resources, however, you'll need to know how to create and manage source sets.

How many types of Gradle build files do we have in Android?

Each module has its own build file, so every Android Studio project contains two kinds of Gradle build files.

How many build Gradle File is there in one Android project?

There are two build. gradle files for every android studio project of which, one is for application and other is for project level(module level) build files.

What is BuildConfig in Android?

What is BuildConfig? Gradle generates a BuildConfig class that contains static configuration constants that are specific to the build at build time. The class includes default fields such as debug and flavor, but you can override them with build.


2 Answers

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"'     } } ... 
like image 125
ivan.panasiuk Avatar answered Sep 19 '22 00:09

ivan.panasiuk


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     } } 
like image 22
Gabriele Mariotti Avatar answered Sep 19 '22 00:09

Gabriele Mariotti