Last active
November 20, 2016 17:23
-
-
Save thunsaker/9956253 to your computer and use it in GitHub Desktop.
Common build.gradle snippets for Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Android debug/release build types including package renaming for debug | |
android { | |
buildTypes { | |
debug { | |
zipAlign true | |
debuggable true | |
runProguard false | |
packageNameSuffix ".debug" | |
versionNameSuffix "-debug" | |
signingConfig signingConfigs.debugSigning | |
} | |
release { | |
zipAlign true | |
debuggable false | |
runProguard true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' | |
signingConfig signingConfigs.releaseSigning | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Specify the keystore locations that are referenced in the signing.gradle snippet | |
DEBUG_STORE_FILE=../../.android/debug.keystore | |
RELEASE_STORE_FILE=../../release.keystore | |
RELEASE_KEY_ALIAS=myapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this to your parent build.gradle | |
println """\ | |
Welcome to Gradle $gradle.gradleVersion - http://www.gradle.org | |
Gradle home is set to: $gradle.gradleHomeDir | |
Gradle user directory is set to: $gradle.gradleUserHomeDir | |
Base directory: $projectDir | |
Running script ${relativePath(buildFile)} | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Android signing configuration with password prompt for release builds | |
android { | |
signingConfigs { | |
debugSigning { | |
storeFile file(DEBUG_STORE_FILE) | |
storePassword "android" | |
keyAlias "androiddebugkey" | |
keyPassword "android" | |
} | |
releaseSigning { | |
storeFile file(RELEASE_STORE_FILE) | |
storePassword System.console() != null ? new String(System.console().readPassword("\nStore password: ")) : "" | |
keyAlias RELEASE_KEY_ALIAS | |
keyPassword System.console() != null ? new String(System.console().readPassword("\nKey password: ")) : "" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this to the app's build.gradle (if needed) to specify sources | |
android { | |
sourceSets { | |
main { | |
manifest.srcFile 'src/main/AndroidManifest.xml' | |
java.srcDirs = ['src/main/java'] | |
res.srcDirs = ['src/main/res'] | |
} | |
androidTest { | |
java.srcDirs ['src/androidTest/java'] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment