Build Unsigned APK with Gradle

AndroidGradleAndroid Studio

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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'
	}
}

Solution 3 - Android

just assign null to signingConfig

android {
  buildTypes {
    debug {
      signingConfig null
    }
  }
}

Solution 4 - Android

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

myBuildType {
    initWith debug
    ...
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZulView Question on Stackoverflow
Solution 1 - AndroidrafaelloView Answer on Stackoverflow
Solution 2 - AndroidoweView Answer on Stackoverflow
Solution 3 - AndroidPrakashView Answer on Stackoverflow
Solution 4 - AndroidphatmannView Answer on Stackoverflow