Skip to content

Instantly share code, notes, and snippets.

@jaisonfdo
Last active January 9, 2019 06:04
Show Gist options
  • Save jaisonfdo/aac64cd266bbb914411f83baacdba249 to your computer and use it in GitHub Desktop.
Save jaisonfdo/aac64cd266bbb914411f83baacdba249 to your computer and use it in GitHub Desktop.
It helps you to Automatically Sign Your APK using build.gradle in Android Studio. For more information, check out my detailed guide here : http://droidmentor.com/sign-apk-automatically/
apply plugin: 'com.android.application'
ext.majorVersion = 1
ext.minorVersion = 0
ext.patchVersion = 1
ext.preRelease = "Alpha"
ext.minSdkVersion = 16
android {
compileSdkVersion 23
buildToolsVersion "24.0.2"
Properties keystoreProperties = new Properties();
keystoreProperties.load(new FileInputStream(file(rootProject.file("gradle.properties"))))
defaultConfig {
applicationId "droidmentor.permissionexample"
minSdkVersion project.ext.minSdkVersion
targetSdkVersion 23
versionCode generateVersionCode() // 160010001
versionName generateVersionName() // 1.0.1-Alpha
}
signingConfigs
{
release
{
storeFile file(keystoreProperties["release_keystore_path"])
storePassword keystoreProperties["release_keystore_password"]
keyAlias keystoreProperties["release_key_alias"]
keyPassword keystoreProperties["release_key_alias_password"]
}
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
testCompile 'junit:junit:4.12'
}
private Integer generateVersionCode() {
return ext.minSdkVersion * 10000000 + ext.majorVersion * 10000 + ext.minorVersion * 100 + ext.patchVersion
}
private String generateVersionName() {
String versionName = "${ext.majorVersion}.${ext.minorVersion}.${ext.patchVersion}"
if (ext.preRelease != null && !ext.preRelease.isEmpty()) {
versionName = versionName + "-" + ext.preRelease
}
return versionName;
}
# Project-wide Gradle settings.
release_keystore_path=/Path/Of/Your/Keystore/KeyStoreName.jks
release_keystore_password=P@ssword1
release_key_alias=KeyIdentifier
release_key_alias_password=KeyP@ssword1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment