-
-
Save gianpaolof/fc62abd365be874b73e0740bb2728dd2 to your computer and use it in GitHub Desktop.
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
| Useful tricks for Android gradle files |
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
| def VERSION_NAME = "1.0" | |
| def buildTime() { | |
| new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC") | |
| } | |
| android { | |
| buildTypes { | |
| release { | |
| versionName VERSION_NAME | |
| // and/or | |
| buildConfigField "String", "BUILD_TIME", "\"\"" | |
| } | |
| debug { | |
| versionName VERSION_NAME + "-" + buildTime() | |
| // and/or | |
| buildConfigField "String", "BUILD_TIME", "\"${buildTime()}\"" | |
| } | |
| } | |
| } |
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
| task ci_job { | |
| group = 'ci' | |
| } | |
| if (project.hasProperty('buildVariant') && !project.property('buildVariant').isEmpty()) { | |
| def checkVariant = '[RegularRelease]' | |
| def testVariant = '[MockDebug]' | |
| project.afterEvaluate { | |
| /* Assemble */ | |
| def assemble = tasks["assemble${buildVariant}"] | |
| assemble.mustRunAfter clean | |
| /* Unit test */ | |
| def unitTests = project.tasks["test${testVariant}UnitTest"] | |
| unitTests.mustRunAfter assemble | |
| unitTests.onlyIf { | |
| !project.hasProperty('skipUnitTest') || project.property('skipUnitTest') != 'true' | |
| } | |
| /* Quality */ | |
| task quality | |
| quality.dependsOn project.tasks["lint${checkVariant}"] | |
| quality.dependsOn project.tasks["findbugs${checkVariant}"] | |
| quality.dependsOn project.tasks["checkstyle"] | |
| quality.onlyIf { | |
| !project.hasProperty('skipQuality') || project.property('skipQuality') != 'true' | |
| } | |
| /* Execute all */ | |
| ci_job.dependsOn clean | |
| ci_job.dependsOn assemble | |
| ci_job.dependsOn unitTests | |
| ci_job.dependsOn quality | |
| } | |
| } else { | |
| ci_job << { | |
| println "Nothing to do, buildVariant is not wel defined" | |
| } | |
| } |
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.versions = [ | |
| dagger : '2.7', | |
| rxAndroid : '1.2.1', | |
| rxJava : '1.1.6', | |
| // etc... | |
| ] | |
| ext.deps = [ | |
| // Dependency injection | |
| dagger : "com.google.dagger:dagger:${versions.dagger}", | |
| daggerCompiler : "com.google.dagger:dagger-compiler:${versions.dagger}", | |
| // RxJava | |
| rxAndroid : "io.reactivex:rxandroid:${versions.rxAndroid}", | |
| rxJava : "io.reactivex:rxjava:${versions.rxJava}", | |
| rxJavaProguard : "com.artemzin.rxjava:proguard-rules:${versions.rxJava}.0", | |
| ] | |
| dependencies { | |
| // Dependency injection | |
| compile deps.dagger | |
| apt deps.daggerCompiler | |
| // RxJava | |
| compile deps.rxAndroid | |
| compile deps.rxJava | |
| compile deps.rxJavaProguard | |
| } |
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
| def VERSION_NAME = "1.0" | |
| def gitVersion() { | |
| def cmd = 'git rev-list HEAD --first-parent --count' | |
| cmd.execute().text.trim().toInteger() | |
| } | |
| android { | |
| buildTypes { | |
| release { | |
| versionName VERSION_NAME | |
| // and/or | |
| buildConfigField "String", "GIT_SHA", "\"\"" | |
| } | |
| debug { | |
| versionName VERSION_NAME + "-" + gitVersion() | |
| // and/or | |
| buildConfigField "String", "GIT_SHA", "\"${gitVersion()}\"" | |
| } | |
| } | |
| } |
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
| // Trick 1 | |
| allprojects { | |
| ext { | |
| isCIBuild = System.getenv('BUILD_ID') | |
| } | |
| } | |
| // Trick 2 | |
| allprojects { | |
| ext { | |
| isIdeBuild = project.properties['android.injected.invoked.from.ide'] == 'true' | |
| } | |
| } |
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
| signingConfigs { | |
| release { | |
| storeFile "${System.env.MYAPP_PRIVATE_KEY}" | |
| keyAlias "${System.env.MYAPP_ALIAS}" | |
| storePassword "${System.env.MYAPP_STORE_PASSWORD}" | |
| keyPassword "${System.env.MYAPP_PASSWORD}" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment