Reputation: 28168
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?
Upvotes: 32
Views: 15232
Reputation: 1616
One more thing to add is if you have added some debugging dependencies, like:
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
then say you want to add a new build type called "local", you need to add similar items like the following in the build.gradle file:
localImplementation 'com.squareup.leakcanary:leakcanary-android:2.8.1'
Upvotes: 0
Reputation: 24522
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"
}
}
Upvotes: 8
Reputation: 125
Other way could be using flavors, like so:
productFlavors {
app1 {}
app2 {}
}
Upvotes: 2
Reputation: 1259
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"'
}
}
...
Upvotes: 39
Reputation: 363805
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
}
}
Upvotes: 36