Using Android Studio, how do I get a signed, non-debugging and archived APK?

Using Android Studio, how do I get a signed, non-debugging and archived APK?

So far I can get signed, but it is rejected because it is debugging it.

I can get apk without debugging, but it is rejected because it does not align in zip.

I can configure it, but then I can not download it because it is not signed.

Edit: I have to mention that I'm on the windows. Most of what I looked at is Linux based and makes it difficult to separate Linux paths from configuration paths.

Edit2: Things are currently paused. I updated Android Studio and killed everything because it comes with gradle 1.9 dependencies but does not install gradle 1.9 correctly. So I thought that download the full installer using gradle 1.9, but the download link will give me the version that I started working with. I know. I should have known better than updated, but given the problems that I thought the fix might contain.

Edit3: the problem is resolved. I have the full answer typed for publication, but SO will not let me publish it until tomorrow.

+3
android android-studio android-gradle apk
Jan 02 '14 at 3:52
source share
4 answers

You can execute any existing Android Studio gradle project and build / sign it from the command line without editing any files. This makes it very nice to keep your project in version control, while saving your keys and passwords separately, and not in the build.gradle file:

./gradlew assembleRelease -Pandroid.injected.signing.store.file=$KEYFILE -Pandroid.injected.signing.store.password=$STORE_PASSWORD -Pandroid.injected.signing.key.alias=$KEY_ALIAS -Pandroid.injected.signing.key.password=$KEY_PASSWORD 
+4
Aug 11 '14 at
source share

All assemblies are signed, even debugged (which are signed using the debug key). It is just a matter of how to configure it to sign your versions with the correct key. You can configure the signature configuration in the Project Structure dialog box or edit the build.gradle file manually by following the instructions in the Gradle Plugin User Guide

Once your build file is configured, you can either generate a release APK from the command line with the command

 ./gradlew assembleRelease 

on Linux or Mac or on Windows:

 gradlew.bat assembleRelease 

or in the graphical interface you can generate the assembly of the release by selecting it in the "Assembly Options" view:

IDE window showing Build Variants view

Building an APK and signing it with a wizard.

+16
Jan 02 '14 at 5:12
source share

I solved the problem. Part 1: The k3v1n4ud3 link really helped consolidate the information. Thank you for that. Here is my whole build.gradle located under the project folder:

  buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.6.+' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion "19.0.0" signingConfigs { debug { storeFile file("debug.keystore") } release { storeFile file("D:\\AndroidStudioProjects\\KeyStore\\Keystore_password1.jks") storePassword "password" keyAlias "MyAppName" keyPassword "password" } } productFlavors { free { packageName "com.mypackage.myappname" } paid { packageName "com.mypackage.myappname" } } buildTypes { debug { signingConfig signingConfigs.release } release { signingConfig signingConfigs.release debuggable false zipAlign true } /* alpha { packageNameSuffix ".alpha" } beta { packageNameSuffix ".beta" }*/ } defaultConfig { minSdkVersion 7 targetSdkVersion 19 } } android.applicationVariants.all { variant -> if (variant.buildType.name == "release") { switch (variant.name) { case "FreeRelease": variant.mergeResources.doFirst { android.sourceSets.debug.setRoot("src/free") } break; case "PaidDebug": variant.mergeResources.doFirst { android.sourceSets.debug.setRoot("src/paid") } break; } } else if (variant.buildType.name == "debug") { switch (variant.name) { case "FreeDebug": variant.mergeResources.doFirst { android.sourceSets.debug.setRoot("src/debug/free") } break; case "PaidDebug": variant.mergeResources.doFirst { android.sourceSets.debug.setRoot("src/debug/paid") } break; } } } dependencies { compile 'com.android.support:appcompat-v7:+' } 

Part 2: I used the keystore created when I originally used the Build-> Generate Signed APK wizard .... Pay attention to the keywords used. After half a day, hitting my head against the wall, I forgot what I typed :-)

Part 3: This thread helped me set up the source folders and understand the flavors. Folder naming convention for gradle build options

Part 4: with only one AndroidManifest.xml, I could not use suffixes in package names. With suffixes, it was rejected when downloading to the device. This becomes a problem when almost every build.gradle example includes suffixes.

Part 5: Use View-> Tool Windows-> BuildVariants to display build options. The second column is actually a drop down. Choose what you want to build here, otherwise it is just going to build a debug version. (Why on earth is this not in the build menu or the startup / debug configuration is a mystery ???)

Part 6: The future ... I have to try and work out the tastes and how to set them up, because in the end I will want to deploy a free and paid version from the same code base. I will also start signing debugging versions using my own key.

+5
Jan 02 '14 at
source share

If you use a different version of the gradle assembly, and not in which you created the keystore file, this may affect it at this time.

I also encountered this problem in my project, I am making the following changes:

set class path

from classpath 'com.android.tools.build: gradle: 2.2.0-alpha3'

to

classpath 'com.android.tools.build: gradle: 2.1.2'

0
Jul 09 '16 at 9:18
source share



All Articles