Android Studio: how to create a second debug build type
Solution 1
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"'
}
}
...
Solution 2
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
}
}
Solution 3
For Kotlin build scripts, the equivalent of the above answer would be something like this:
android {
buildTypes {
create("local") {
initWith(buildTypes["debug"])
buildConfigField("String", "URL_API_BASE_SERVICE", """"http://..."""")
buildConfigField("Boolean", "IS_CI", "${System.getenv("CI") == "true"}") // boolean example
isDebuggable = true
}
testBuildType = "local"
}
}
Solution 4
Other way could be using flavors, like so:
productFlavors {
app1 {}
app2 {}
}
Related videos on Youtube
Comments
-
Mister Smith almost 2 years
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:
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:
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?
-
TacB0sS over 6 yearsYou should accept the correct answer, for me it was ivan.panasiuk answer
-
-
Mister Smith over 8 yearsSorry, we don't include the signing config in the build.gradle as each team member has a different OS and keystore path, and a VCS sync would break other devs workspaces. But most importantly, I don't want to sign for release. It should sign with the same debug cert the debug config is using.
-
Gabriele Mariotti over 8 years@MisterSmith Each build type is signed with a keystore. And of course you can use the debug keystore, check the first part of the answer. The important part of the answer is that you have to define the signing config in the build.gradle because the local build type is a custom build type and there isn't a default.
-
Mister Smith over 8 yearsI understand that. But what should I write in the "local" signingConfig so that it uses the default debug keystore?
-
Gabriele Mariotti over 8 yearsShould be enough
signingConfig signingConfigs.debug
. If it doesn't work addsigningConfigs { debug { storeFile file("debug.keystore") }}
-
Mister Smith over 8 yearsYes, that s probably the easiest way.
-
narancs almost 7 yearsthat's a good solution, but my problem with falviours that I will have buildType&flavors combination. What if i just want to switch between different debug environments?
-
aricherca almost 7 yearsYou have the build variants on a tab. There you can choose the build variant.
-
TacB0sS over 6 yearsThanks a ton, I tried setting up signingConfig signingConfigs.debug, I've expected it to work, but it didn't, your solution did it!! thanks
-
Samuel over 6 yearsIt took me ours to find that signingConfig option which is implicitly set for the debug build. Geez.
-
V.S. almost 5 yearsIf your app has sub-modules, the compilation will fail with this configuration unless you declare the
local
build type for your sub-modules as well. This can be more easily overcome by addingmatchingFallbacks = ['debug']
to thelocal
in build type in main:app
'sbuild.gradle
. Gradle will then use thedebug
configuration for your sub-modules, which is probably what you want. -
Aman Alam about 4 yearsLooks like
signingConfig.debug
doesn't work anymore, and it's changed todebug.signingConfig
now