7 Ways to improve your gradle build

  • Published on
    16-Apr-2017

  • View
    41

  • Download
    4

Transcript

7 WAYS TO IMPROVE YOUR GRADLE BUILDTania Pinheiro@tcmpinheiroDroidcon London 2016WHY?Automate tasks Customise the build to the current project Integrate continuous delivery#1 EXTRA PROPERTIES// app/build.gradle ext { applicationIdName = "com.example.myapplication" minVersion = 16 targetVersion = 24} android { compileSdkVersion targetVersion defaultConfig { applicationId applicationIdName minSdkVersion minVersion targetSdkVersion targetVersion } }#1 EXTRA PROPERTIES// app/build.gradle ext { applicationIdName = "com.example.myapplication" minVersion = 16 targetVersion = 24} android { compileSdkVersion targetVersion defaultConfig { applicationId applicationIdName minSdkVersion minVersion targetSdkVersion targetVersion } }#1 EXTRA PROPERTIES// app/build.gradle ext { applicationIdName = "com.example.myapplication" minVersion = 16 targetVersion = 24} android { compileSdkVersion targetVersion defaultConfig { applicationId applicationIdName minSdkVersion minVersion targetSdkVersion targetVersion } }#2 APPLICATIONID// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }#2 APPLICATIONID// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }#2 APPLICATIONID// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }#2 APPLICATIONID// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }#2 APPLICATIONID// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }#3 APP NAME / ICON// app/build.gradle productFlavors { pro { applicationId applicationIdName + ".pro" resValue "string", "app_name", "App-Pro" manifestPlaceholders = [appIcon: "@mipmap/ic_launcher_pro"] } free { applicationId applicationIdName + ".free" resValue "string", "app_name", "App-Free" manifestPlaceholders = [appIcon: "@mipmap/ic_launcher_free"] }}// app/AndroidManifest.xml #3 APP NAME / ICON// app/build.gradle productFlavors { pro { applicationId applicationIdName + ".pro" resValue "string", "app_name", "App-Pro" manifestPlaceholders = [appIcon: "@mipmap/ic_launcher_pro"] } free { applicationId applicationIdName + ".free" resValue "string", "app_name", "App-Free" manifestPlaceholders = [appIcon: "@mipmap/ic_launcher_free"] }}// app/AndroidManifest.xml #3 APP NAME / ICON// app/build.gradle productFlavors { pro { applicationId applicationIdName + ".pro" resValue "string", "app_name", "App-Pro" manifestPlaceholders = [appIcon: "@mipmap/ic_launcher_pro"] } free { applicationId applicationIdName + ".free" resValue "string", "app_name", "App-Free" manifestPlaceholders = [appIcon: "@mipmap/ic_launcher_free"] }}// app/AndroidManifest.xml #3 APP NAME / ICON// app/build.gradle productFlavors { pro { applicationId applicationIdName + ".pro" resValue "string", "app_name", "App-Pro" manifestPlaceholders = [appIcon: "@mipmap/ic_launcher_pro"] } free { applicationId applicationIdName + ".free" resValue "string", "app_name", "App-Free" manifestPlaceholders = [appIcon: "@mipmap/ic_launcher_free"] }}// app/AndroidManifest.xml #4 CUSTOM SCRIPTS// scripts/dependencies.gradle ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }#4 CUSTOM SCRIPTS// scripts/dependencies.gradle ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }#4 CUSTOM SCRIPTS// scripts/dependencies.gradle ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }#4 CUSTOM SCRIPTS// scripts/dependencies.gradle ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }#4 CUSTOM SCRIPTS// scripts/dependencies.gradle ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }#5 BUILD TYPE TO RUN TESTS// app/build.gradle android { testBuildType staging' }#5 BUILD TYPE TO RUN TESTS// app/build.gradle android { testBuildType staging' }#6 SIGNING CREDENTIALS// app/build.gradle signingConfigs { release { if(file('deployment/keystore.properties').exists()){ def props = new Properties() props.load(new FileInputStream(file('deployment/keystore.properties'))) storeFile = file('../deployment/production_keystore.jks') storePassword = props['storePassword'] keyAlias = props['keyAlias'] keyPassword = props['keyPassword'] } }}// deployment/keystore.properties storePassword = storePasswordkeyAlias = keyAliaskeyPassword = keyPassword#6 SIGNING CREDENTIALS// app/build.gradle signingConfigs { release { if(file('deployment/keystore.properties').exists()){ def props = new Properties() props.load(new FileInputStream(file('deployment/keystore.properties'))) storeFile = file('../deployment/production_keystore.jks') storePassword = props['storePassword'] keyAlias = props['keyAlias'] keyPassword = props['keyPassword'] } }}// deployment/keystore.properties storePassword = storePasswordkeyAlias = keyAliaskeyPassword = keyPassword#6 SIGNING CREDENTIALS// app/build.gradle signingConfigs { release { if(file('deployment/keystore.properties').exists()){ def props = new Properties() props.load(new FileInputStream(file('deployment/keystore.properties'))) storeFile = file('../deployment/production_keystore.jks') storePassword = props['storePassword'] keyAlias = props['keyAlias'] keyPassword = props['keyPassword'] } }}// deployment/keystore.properties storePassword = storePasswordkeyAlias = keyAliaskeyPassword = keyPassword#6 SIGNING CREDENTIALS// app/build.gradle signingConfigs { release { if(file('deployment/keystore.properties').exists()){ def props = new Properties() props.load(new FileInputStream(file('deployment/keystore.properties'))) storeFile = file('../deployment/production_keystore.jks') storePassword = props['storePassword'] keyAlias = props['keyAlias'] keyPassword = props['keyPassword'] } }}// deployment/keystore.properties storePassword = storePasswordkeyAlias = keyAliaskeyPassword = keyPassword#7 CONTINUOUS DELIVERYCrashlytics for Beta Testers distribution #7 CONTINUOUS DELIVERYCrashlytics for Beta Testers distribution Fastlane Supply to upload to PlayStore supply --apk path/to/app.apkWANT TO LEARN MORE?http://go.gradle.com/l/68052/2015-01-13/6dmhttp://go.gradle.com/l/68052/2016-07-05/7mlynphttp://go.gradle.com/l/68052/2015-01-26/23s5WANT TO LEARN MORE? Gradle for Android and Java by THANK YOU!Tania Pinheiro@tcmpinheiro