Android studio not generating unsinged apk - android

From my terminal if i run "gradle assemble" its only generating following apks. Any one please tell me how do i get default unsigned apk from android studio. I tried creating separate buildType for unsigned with empty keyStore but no use .
- MyApp-debug-unaligned.apk
- MyApp-debug.apk
- MyApp-release-unaligned.apk
- MyApp- release.apk

To generate an unsigned apk do the following:
define a signingConfig with empty configuations like this:
signingConfigs{
unsigned{
storePassword = ""
keyAlias = ""
keyPassword = ""
}
}
define in the buildTypes for your release Version with the unsigned Configuration:
buildTypes{
release{
signingConfig signingConfigs.unsigned
}
}
I get this from the adt-dev group, where Xavier Ducrohet write:
The current behavior is to check that the signing config is fully configured(*) and if it is, it generates a signed APK, otherwise an unsigned APK.
(*) fully configured right now means the value for store, alias and passwords are present, but does not include that the keystore is present.
UPDATE 2013-12-19
As withoutclass mentioned this doesn't work with the gradle plugin version 0.6.3.
Anyway it's possible to generate an unsigned APK with gradle: just let the signingConfig entry of a flavor or buildType empty. It should look like this:
productFlavors{
// with this config you should get a "MyProject-flavorUnsigned-release- unsigned.apk"
flavorUnsigned{
versionCode = 9
packageName defaultPkgName
}
}
buildTypes{
// with this config you should get a "MyProject-release-unsigned.apk"
release{
packageNameSuffix '.release'
}
}
Answer here: Build Unsigned APK with Gradle

Related

Why does the order of `buildTypes` matter?

I'm running into a strange issue with gradle.
My app/build.gradle file has a section which looks like this:
buildTypes {
debug {
...
}
release {
signingConfig signingConfigs.release
...
}
beta {
initWith release
...
}
}
When I run ./gradlew assembleBeta, the output is app-beta.apk, which I can install on my device.
However, I want to change the order of my build types, purely for aesthetics. So it now looks like:
buildTypes {
debug {
...
}
beta {
initWith release
...
}
release {
signingConfig signingConfigs.release
...
}
}
This syncs fine, but when I run ./gradlew assembleBeta, the output is now app-beta-unsigned.apk! And I cannot install this apk on a device - it tells me installation failed.
How is it possible that simply by changing the order in which my build types are declared, my apk can become broken?
The reason the apk is broken after changing the order of build types is because, in this situation, gradle requires that the release build type is defined before the beta build type.
Why is this? It's because beta refers to release in the line: initWith release
If release is defined after beta, then the initWith release command will silently fail. This is because, at the point initWith release is run, release does not exist. Although it may seem like Gradle should be able to look-ahead to the definition of release later in the file, it cannot.
Then, when running ./gradlew assembleBeta, the beta apk is built successfully - but the apk is unsigned - as alluded to by the name of the output file, app-beta-unsigned.apk. In the previous setup, beta was getting its signingConfig from release. When initWith release fails, the beta build simply has no signingConfig set - so the output apk is of course unsigned.

Updating existing debug app with different developers

I have trouble with updating the debug version of the app's apk:
Installation failed with message Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package [here our package] signatures do not match the previously installed version; ignoring
Two developers. Two PC's with same Android Studio versions (3.2.1). But when I try to install - have this, when the second developer make a debug apk with the same code (with git) it installs normally.
If I make an apk - it's an error occurred via an update of a version of the second developer on a different device (tester).
What I've tried already:
Restart Android Studio.
Clean and Rebuild.
Invalidate Caches and Restart.
Build apk and installed from the device. ("Application doesn't install" error occurred during update)
Increase versionCode.
The device is a Lenovo TB-X103F tablet on Android 6.0.1.
You need to use the same debug keystore. Your colleagues' keystore will be at:
Windows: C:\Users\USERNAME\.android\debug.keystore
Linux / Mac: ~/.android/debug.keystore
3 solutions are below in descending order of correctness:
In the long term, this should be configured inside your project, so that anyone with the project can sign the debug builds. This is done by configuring your build.gradle like so.
You can also set your signing config inside Android Studio, so you are not reliant on copying his file in the future. Here is how to set it.
You could also just replace your debug keystore in that location with your colleagues, so you are using the same config.
Different keystore files cause this warning. For the exact solution;
-Create your own keystore files for each build types.
-Define buildTypes and SigningConfigs in app level gradle file
like this:
signingConfigs {
release {
keyAlias '******'
keyPassword '******'
storeFile file('...\\release.jks')
storePassword '******'
}
debug {
keyAlias 'alias'
keyPassword '******'
storeFile file('...\\debug.jks')
storePassword '******'
}
}
buildTypes {
release {
lintOptions {
}
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
}
NOTE!!! You can move debug keystore file into project folder(app folder will be a good choice). So both developers have the same keystore easily.

Android Studio 2.3 is generating unaligned signed APK's instead of zipaligned?

I recently upgraded to Android Studio 2.3 and now I was going to generate a signed APK for one of my existing apps using Build / Generate signed APK... just as I've always done. Before I have always gotten a file called MyApp-1.0.apk (where 1.0 is the version name), but now I get MyApp-1.0-unaligned.apk.
I noticed there are some new options to choose V1 (Jar signature) and/or V2 (Full APK Signature. I selected both, as recommended in the documentation. The documentation does however say this
Caution: If you sign your app using APK Signature Scheme v2 and make further changes to the app, the app's signature is invalidated. For this reason, use tools such as zipalign before signing your app using APK Signature Scheme v2, not after.
In my build.gradle I have
buildTypes {
debug{
// Enable/disable ProGuard for debug build
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
zipAlignEnabled true
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
zipAlignEnabled true
}
}
I've seen some people experiencing similar problems with alpha releases of the Android gradle build tool, but I'm using 2.3.0:
classpath 'com.android.tools.build:gradle:2.3.0'
So how do I make the APK-generation process zipalign my APK's before signing them?
The problem was caused by having an external gradle script manage the filename of generated APK's. I had totally forgot about that script, and now it had started failing a check to see if the APK is zipaligned, since Google introduced the v2 signing.
I had the script included in my build.gradle like this
apply from: '../../export_signed_apk.gradle'
And the script itself looked like this
android.applicationVariants.all {
variant -> def appName
//Check if an applicationName property is supplied; if not use the name of the parent project.
if (project.hasProperty("applicationName")) {
appName = applicationName
} else {
appName = parent.name
}
variant.outputs.each {
output -> def newApkName
//If there's no ZipAlign task it means that our artifact will be unaligned and we need to mark it as such.
if (output.zipAlign) {
newApkName = "${appName}-${variant.versionName}.apk"
} else {
newApkName = "${appName}-${variant.versionName}-unaligned.apk"
}
output.outputFile = new File(output.outputFile.parent, newApkName)
}
}
It seems that output.zipAlign fails since applying the V2 signing, so it would return myApp-1.0-unaligned even when the signed APK was indeed zipaligned.
I simply removed the IF statement, and am just keeping
newApkName = "${appName}-${variant.versionName}.apk"

Script to generate signed apk for multiple projects android studio

I understand how to generate a signed apk from android studio-> Build menu, but if I have several projects is it possible to automate this task so that for all the projects I could run some script which automatically builds signed apks without me having to generate them one by one ?
Thanks,
Ahmed
Yes this can be done by creating a signed build configuration and specifying the keystore information. This is done by adding a couple sections to build.gradle:
First create the signed build type that uses release mode and runs proguard:
android {
buildTypes {
signed {
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.signed
}
}
}
Then add the signing configuration (supply your own values):
android {
signingConfigs {
signed {
storeFile file('keystore.jks')
storePassword 'storepassword'
keyAlias 'key'
keyPassword 'keypassword'
}
}
}
Then, you can build from the command line by typing ./gradlew assembleSigned (for Mac OSX) or gradlew assembleSigned (for Windows).
You can also use the installSigned build task to build and install on a connected device.

app-release-unsigned.apk is not signed

I downloaded the zip file of an Android app on github and I'm trying to run it, but I get a dialog with this message
app-release-unsigned.apk is not signed. Please configure the signing information for the selected flavor using the Project Structure dialog.
I'm using Android Studio.
What am I supposed to do?
If anyone wants to debug release build using Android Studio, follow these steps:
Set build variant to release mode.
Right click on app in left navigation pane, click Open Module Settings.
Go to Signing Tab. Add a signing config and fill in information. Select your keychain as well.
Go to Build Type tab. Select release mode and set:
-Debuggable to true.
-Signing Config to the config. (The one you just created).
Sync your gradle. Enjoy!
Make sure the build variant is set to debug (and not release) in Android Studio (check the build variants panel).
If set to debug, it should automatically sign the app with the auto-generated debug keystore, without editing the build scripts.
However you will need to create and configure a specific keystore for release.
Official documentation, covering debug and release modes: https://developer.android.com/tools/publishing/app-signing.html
Always sign your build using your build.gradle DSL script like this:
android {
signingConfigs {
debug {
storeFile file("debug.keystore")
}
myConfig {
storeFile file("other.keystore")
storePassword "android"
keyAlias "androidotherkey"
keyPassword "android"
}
}
buildTypes {
bar {
debuggable true
jniDebugBuild true
signingConfig signingConfigs.debug
}
foo {
debuggable false
jniDebugBuild false
signingConfig signingConfigs.myConfig
}
}
}
If you want to understand a little more of the Gradle build system associated to Android Studio just pay a visit to:
Gradle Plugin User Guide
If anyone wants to debug and release separate build variant using Android Studio 3.5, follow the below steps:
1. Set build variant to release mode.
Go to File >> Project Structure
Select Modules, then Signing Config
Click in the Plus icon under Signing Config
Select release section and Provide your release App Information then Apply and OK.
Go to your app level build.gradle and change your buildTypes > "release" section like below Screenshot.
Then Run your Project. Happy Coding.
I was successfully able to debug signed APK , Follow this procedure:-
Choose "release" version in "Build Variant" ToolBar
In the Build.gradle for the module set debuggable true for release build type
Go to File->Project Structure->under signing tab fill all info->Under Flavours
tab->Choose signing Config You just created
Set the breakpoints
Run the application in the debug mode
For gradle Kotlin dsl
signingConfigs {
create("releaseConfig") {
storeFile = file("your keystore file path")
storePassword = "storePassword"
keyAlias = "keyAlias"
keyPassword = "keyPassword"
}
}
buildTypes {
getByName("release") {
signingConfig = signingConfigs.getByName("releaseConfig")
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
signingConfigs should be before buildTypes
signingConfigs {
debug {
storeFile file("debug.keystore")
}
myConfig {
storeFile file("other.keystore")
storePassword "android"
keyAlias "androidotherkey"
keyPassword "android"
}
}
buildTypes {
bar {
debuggable true
jniDebugBuild true
signingConfig signingConfigs.debug
}
foo {
debuggable false
jniDebugBuild false
signingConfig signingConfigs.myConfig
}
}
if you want to run app in debug mode
1) Look at Left Side bottom, above Favorites there is Build Variants
2) Click on Build Variants. Click on release and choose debug
it works perfect !!!
The app project you downloaded may include a signed info in the file of build.gradle. If you saw codes like these:
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
signingConfig signingConfigs.release
}
}
you could delete them and try again.
My problem was solved by changing the build variant as suggested by Stéphane , if anyone was struggling to find the "Build variants" as I did here is a screenshot where you can find it .
For security reasons, you cannot install an unsigned apk on Android. So if you only have the unsigned apk: you must sign it. Here is how to do that : link
Note that you can sign the apk with a self-signed certificate.
An alternative can be either :
to download the signed apk if available.
to download the sources, compile them (with Android-Studio or gradle or ...). It will produce multiple apks and one of them will be signed with your debug-key (and so you will be able to install it)
How i solved this
This error occurs because you have set your build variants to release mode. set it to build mode and run project again.
If you want to run in release mode, just generate a signed apk the way we do it normally when releasing the app
In tool window bar select Build Variants
Change Build Variant from Release to Debug
My solution was to change the name of my signing config from the default "config" to "debug". To verify, I changed it to some other random name and got the error again, and then changed it back to "debug" and the error was gone. So while it seems artificial and I tend to not believe this is the whole story, give this solution a try.
i also appear this problem,and my code below
storeFile file(properties.getProperty("filepath"))
storePassword properties.getProperty("keypassword")
keyAlias properties.getProperty("keyAlias")
keyPassword properties.getProperty("keypassword")
the reason is property name error,it should be keyPassword not keypassword
What finally worked for me, and I have no idea why, is:
Went to LastPass (the service I use to keep all my passwords)
Select my password by putting the cursor on top of the password and double clicking
Once selected I press cmd C to copy
Went to Android study and cmd V to paste
Notice I did try to copy many times by selecting the password by clicking at the end of the password and selecting the password by moving the mouse.
It is strange but it only worked by double clicking on top of the password to copy it.
Also I did use the Open Module Settings > Signing... method explained by #NightFury on this post.
adding below lines of code in build.gradel file worked for me, add them under buildTypes block below release as shown
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
debuggable true
}

Categories

Resources