Last active
July 16, 2018 14:23
-
-
Save mobiRic/e1f4b93d2c69298c90d45c3a1942dd9e to your computer and use it in GitHub Desktop.
Gradle tips
This file contains hidden or 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
This is a collection of gradle tricks for the app's 'build.gradle' file. |
This file contains hidden or 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
/** | |
* Copy the APK file into extras folder. Run this task at the end of a release build and commit to git. | |
* | |
* This task will not work if destination folder is the root folder due to a `fileHashes.lock` issue. | |
* | |
* @see https://gist.github.com/caipivara/bfb2fb5732d760e766f5 | |
* @see https://stackoverflow.com/a/47262820/383414 | |
*/ | |
task copyApk(type: Copy) { | |
from "build/outputs/apk/release" | |
into "../extras" | |
include "*-release.apk" | |
} |
This file contains hidden or 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
ext { | |
appVersions = [ | |
code: 10000, | |
name: '1.0.0' | |
] | |
buildVersions = [ | |
compileSdk: 27, | |
minSdk : 17, | |
targetSdk : 26, | |
] | |
libVersions = [ | |
supportLib : '27.1.0', | |
constraintLayout: '1.0.2', | |
aboutLib : '6.0.1@aar', | |
gson : '2.8.2', | |
crashlytics : '2.8.0@aar', | |
stetho : '1.5.0', | |
qrScanner : '2.0.0', | |
qrGen : '2.4.0', | |
calligraphy : '2.3.0', | |
] | |
testVersions = [ | |
junit : '4.12', | |
testRunner: '1.0.1', | |
espresso : '3.0.1', | |
] | |
} |
This file contains hidden or 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
dependencies { | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
implementation("com.mikepenz:aboutlibraries:${libVersions.aboutLib}") { | |
transitive = true | |
} | |
/* GSON */ | |
implementation "com.google.code.gson:gson:${libVersions.gson}" | |
/* Crashlytics */ | |
implementation("com.crashlytics.sdk.android:crashlytics:${libVersions.crashlytics}") { | |
transitive = true; | |
} | |
implementation "com.facebook.stetho:stetho:${libVersions.stetho}"; | |
implementation "com.github.KingsMentor:MobileVisionBarcodeScanner:${libVersions.qrScanner}" | |
implementation "com.github.kenglxn.QRGen:android:${libVersions.qrGen}" | |
implementation "uk.co.chrisjenx:calligraphy:${libVersions.calligraphy}" | |
implementation "com.android.support:appcompat-v7:${libVersions.supportLib}" | |
implementation "com.android.support.constraint:constraint-layout:${libVersions.constraintLayout}" | |
implementation "com.android.support:design:${libVersions.supportLib}" | |
implementation "com.android.support:cardview-v7:${libVersions.supportLib}" | |
implementation "com.android.support:support-v4:${libVersions.supportLib}" | |
implementation "com.android.support:recyclerview-v7:${libVersions.supportLib}" | |
testImplementation "junit:junit:${testVersions.junit}" | |
androidTestImplementation "com.android.support.test:runner:${testVersions.testRunner}" | |
androidTestImplementation "com.android.support.test.espresso:espresso-core:${testVersions.espresso}" | |
} |
This file contains hidden or 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
storeFile=../extras/key/my_app_name_release.jks | |
storePassword=silly-words | |
keyPassword=super-cool-password | |
keyAlias=release |
This file contains hidden or 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 { | |
compileSdkVersion buildVersions.compileSdk | |
defaultConfig { | |
applicationId "mobi.glowworm.example`" | |
minSdkVersion buildVersions.minSdk | |
//noinspection OldTargetApi | |
targetSdkVersion buildVersions.targetSdk | |
versionCode appVersions.code | |
versionName appVersions.name | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
// allow Crashlytics configuration based on build type - disable this in debug builds | |
buildConfigField("boolean", "CRASHLYTICS", "true") | |
/*BETA DISTRIBUTION*/ | |
ext.betaDistributionReleaseNotesFilePath = "extras/fabric/release_notes.txt" | |
ext.betaDistributionEmailsFilePath = "extras/fabric/distribution.txt" | |
} | |
signingConfigs { | |
debug { | |
// keystore properties stored in an external file - do not commit to repo | |
def keystorePropertiesFile = rootProject.file("./extras/key/keystore_debug.properties") | |
if (keystorePropertiesFile.exists()) { | |
def keystoreProperties = new Properties() | |
keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) | |
storeFile file(keystoreProperties['storeFile']) | |
storePassword keystoreProperties['storePassword'] | |
keyAlias keystoreProperties['keyAlias'] | |
keyPassword keystoreProperties['keyPassword'] | |
} | |
} | |
release { | |
// keystore properties stored in an external file - do not commit to repo | |
def keystorePropertiesFile = rootProject.file("./extras/key/keystore_release.properties") | |
if (keystorePropertiesFile.exists()) { | |
def keystoreProperties = new Properties() | |
keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) | |
storeFile file(keystoreProperties['storeFile']) | |
storePassword keystoreProperties['storePassword'] | |
keyAlias keystoreProperties['keyAlias'] | |
keyPassword keystoreProperties['keyPassword'] | |
} | |
} | |
} | |
buildTypes { | |
debug { | |
applicationIdSuffix ".debug" | |
buildConfigField("boolean", "CRASHLYTICS", "false") | |
// buildConfigField "String", "API_URL", '"https://debug.api.glowworm.mobi"' | |
signingConfig signingConfigs.debug | |
} | |
release { | |
minifyEnabled false | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
// buildConfigField "String", "API_URL", '"https://production.api.glowworm.mobi"' | |
signingConfig signingConfigs.release | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added a debug signing config block.