55

Currently I'm trying to learn Gradle to build Android APKs. How to set an option in gradle to build an unsigned APK?

Kirill
  • 7,580
  • 6
  • 44
  • 95
Zul
  • 1,344
  • 2
  • 12
  • 21

4 Answers4

85

You don't have to set any option, just run the usual task:

$ gradle assemble

This will generate two files in project/build/apk/

app-debug-unaligned.apk 
app-release-unsigned.apk
rafaello
  • 2,385
  • 1
  • 18
  • 16
  • @rafaello: Iknow it's a while ago. But my solution (answer above) doesn't work anymore (Why?... I don't know). Now I tried you solution and it worked for me. Thanks a lot! The mistake I made in earlier time was to set a signConfig in the flavor that I wanted unsigned... Now I removed the signConfig and everything works fine! It's just annoying to this over the command line... – owe Sep 11 '13 at 09:55
  • Do you need to have signing config stuff for this to work? even if it's just the debug one? – Daniel Jonker Jun 27 '14 at 00:30
  • 1
    Go to `Run > Edit configurations` and add a new gradle job with tasks "assemble". Now run your new job. The `myapp-debug.apk` is under `/build/outputs/apk` – vault Dec 02 '14 at 16:32
  • @rafaello I get an error: >Could not find method jcenter() for arguments [] on repository container. – IgorGanapolsky Dec 10 '14 at 15:54
  • @IgorGanapolsky try the answer from http://stackoverflow.com/questions/21087330/gradle-eclipse-plugin-could-not-find-method-jcenter-for-arguments-on-repo see if it solves your problem – rafaello Dec 11 '14 at 06:10
  • Here are some detailed instructions to do what vault is describing in the comment above https://developer.android.com/guide/topics/manifest/uses-feature-element.html#testing – Nick Sep 15 '17 at 16:28
20

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'
    }
}
owe
  • 4,890
  • 7
  • 36
  • 47
  • Doesn't work for me anymore. But rafaellos answer is quite good. Added a post to ADT Dev Group on G+:https://plus.google.com/117954254390243608387/posts/N5dTMNS5UGv – owe Sep 11 '13 at 09:57
  • 1
    This doesn't work as the build will fail stating that there are no value specified for the required fields. plugin version 0.6.3 – withoutclass Dec 18 '13 at 21:48
  • @withoutclass: Your right. I updated my answer and explained how can generate an unsigned apk with the newest gradle version. – owe Dec 19 '13 at 07:10
  • this doesn't work if your release build has a signing config. It will sign the app using the release config. Plugin version 0.7.0. – withoutclass Dec 19 '13 at 16:42
  • Ok, I still use the plugin version 0.6.+, because there is no update for AS 0.4.0 in the "dev channel". Now is the question: how can i generate an unsigned apk with plugin version 0.7.0? Do I need an additionally buildType "unsigned" where I don't declare a `signingConfig`? This wouldn't be a nice solution because the count of buildVariants increase... – owe Dec 20 '13 at 07:01
11

just assign null to signingConfig

android {
  buildTypes {
    debug {
      signingConfig null
    }
  }
}
Prakash
  • 4,479
  • 30
  • 42
-1

If you want to make a build type act that is unsigned (just like a debug build), do the following:

myBuildType {
    initWith debug
    ...
}
phatmann
  • 18,161
  • 7
  • 61
  • 51