14

I need to generate both unsigned and signed release apks using gradle command line (gradlew assembleRelease is the command im using now)

The apks must be aligned. I checked this: Build Unsigned APK with Gradle but it seems to be an old way to achieve this, now it does not work and something has changed in lastest versions of android and gradle compilation. And also i need to generate both apks at same time, not only release mode or unsigned mode

3
  • Apologies for my initial answer, I misread the question Commented Aug 25, 2015 at 9:00
  • run gradle clean assemble (this will execute assembleDebug and assembleRelease. Make sure the debug buildType has no singingConfig, but the release buildType has got one. Commented Aug 25, 2015 at 9:29
  • So, did you solve your problem? Commented Aug 27, 2015 at 11:06

4 Answers 4

8

I think buildTypes is a more suitable place than productFlavors.
You can extend your release build with replacing signingConfig.

buildTypes { release { .... signingConfig signingConfigs.release } releaseUnsigned.initWith(buildTypes.release) releaseUnsigned { signingConfig null } } 

Then for building both APK-files:

./gradlew assemble 

Or if you want only release builds

./gradlew assembleRelease assembleReleaseUnsigned or ./gradlew assR assRU 

If you really want to use only assembleRelease task, you can make this dependency

assembleRelease.dependsOn assembleReleaseUnsigned 

And build with just

./gradlew assembleRelease 
Sign up to request clarification or add additional context in comments.

2 Comments

where do you add the line assembleRelease.dependsOn assembleReleaseUnsigned ?
@KhaledOsman anywhere in app/build.gradle, after dependencies {} or other custom tasks.
8

I know it's pretty old answer but it still might help someone gain your goal without adding extra flavour (even as in my case it might be challenging because many dependencies in the project).

android { signingConfigs { release { ... } } productFlavors { signed { signingConfig (checkUnsigned() ? null : signingConfigs.release) } } def checkUnsigned () { return project.hasProperty("unsigned") } 

In order to use it just use

gradle assembleRelease 

or

gradle assembleRelease '-Punsigned' 

for creating unsigned (quotes for CI, otherwise it might not be needed)

Disadvantage of the solution is just when you want to assemble several flavours in one line ie

gradle assembleRelease assembleDebug assembleRelease '-Punsigned' 

assembleRelease checks all properties in command line, so first assembleRelease will be callse also with param '-Punsigned' I resolved this CI issue by using 2 commands - one for signed, other for unsigned versions

gradle assembleRelease assembleOtherFlavour '-Punsigned' gradle assembleDebug assembleRelease assembleOtherFlavour 

1 Comment

This is lighter weight than adding a new build variant. Thanks!
4

The answer you linked to is correct - if your chosen variant (i.e. build type + flavor combination) is not using a "signing ready" signing config, gradle will create an unsigned APK.

So you can define a setup like this:

android { signingConfigs { release { ... } } productFlavors { signed { signingConfig signingConfigs.release // defined above } unsigned {} // use the default options } } 

Then running ./gradlew :app:assembleRelease will create your APKs:

app/build/outputs/apk ├── app-signed-release.apk ├── app-signed-release-unaligned.apk └── app-unsigned-release-unsigned.apk 

1 Comment

I think signingConfig should take place in buildTypes, and flavors are for app logic
3

It didn't work for me with defining new buildType. But it works with debug/release:

 buildTypes { release { signingConfig null } debug { signingConfig null } } 

this will create unsigned apks

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.