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
Unsigned APK is actually signed by debugging key. It is Secure. Only the Developer has unsigned Apk. Step 1: Build your project then go to the Build > Build Bundle (s)/APK (s) > Build APK (s) as shown in the below image. Step 2: Then, You will see that Gradle is building. Wait for 3 to 4 minutes to complete the build.
That is why most of the time we prefer to generate unsigned apk as that is even easy to be generated. Unsigned APK is actually signed by debugging key. It is Secure. Only the Developer has unsigned Apk. Step 1: Build your project then go to the Build > Build Bundle (s)/APK (s) > Build APK (s) as shown in the below image.
Step 1: Go to Build -> Generate Signed Bundle or APK, a pop up will arise. Choose APK in the pop-up and click on Next. Step 2: After completing step 1, if you already have a key, make sure you just refer to that and you can release the version of that app but in case if it is the first time it is recommended to create a new key.
The signed apk is simply the unsigned apk that has been signed via the JDK jarsigner tool. If you want to generate a signed apk then refer to How to Generate Signed Apk in Android Studio? Why do We Need to Generate an Unsigned Apk?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With