7 Ways to improve your gradle build

  • Published on
    16-Apr-2017

  • View
    41

  • Download
    4

Embed Size (px)

Transcript

<ul><li><p>7 WAYS TO IMPROVE YOUR </p><p>GRADLE BUILDTania Pinheiro@tcmpinheiro</p><p>Droidcon London 2016</p></li><li><p>WHY?</p><p>Automate tasks </p><p>Customise the build to the current project </p><p>Integrate continuous delivery</p></li><li><p>#1 EXTRA PROPERTIES</p><p>// app/build.gradle </p><p>ext { applicationIdName = "com.example.myapplication" minVersion = 16 targetVersion = 24} android { compileSdkVersion targetVersion defaultConfig { applicationId applicationIdName minSdkVersion minVersion targetSdkVersion targetVersion } }</p></li><li><p>#1 EXTRA PROPERTIES</p><p>// app/build.gradle </p><p>ext { applicationIdName = "com.example.myapplication" minVersion = 16 targetVersion = 24} android { compileSdkVersion targetVersion defaultConfig { applicationId applicationIdName minSdkVersion minVersion targetSdkVersion targetVersion } }</p></li><li><p>#1 EXTRA PROPERTIES</p><p>// app/build.gradle </p><p>ext { applicationIdName = "com.example.myapplication" minVersion = 16 targetVersion = 24} android { compileSdkVersion targetVersion defaultConfig { applicationId applicationIdName minSdkVersion minVersion targetSdkVersion targetVersion } }</p></li><li><p>#2 APPLICATIONID</p><p>// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }</p></li><li><p>#2 APPLICATIONID</p><p>// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }</p></li><li><p>#2 APPLICATIONID</p><p>// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }</p></li><li><p>#2 APPLICATIONID</p><p>// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }</p></li><li><p>#2 APPLICATIONID</p><p>// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }</p></li><li><p>#3 APP NAME / ICON// app/build.gradle </p><p>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"] }}</p><p>// app/AndroidManifest.xml </p></li><li><p>#3 APP NAME / ICON// app/build.gradle </p><p>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"] }}</p><p>// app/AndroidManifest.xml </p></li><li><p>#3 APP NAME / ICON// app/build.gradle </p><p>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"] }}</p><p>// app/AndroidManifest.xml </p></li><li><p>#3 APP NAME / ICON// app/build.gradle </p><p>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"] }}</p><p>// app/AndroidManifest.xml </p></li><li><p>#4 CUSTOM SCRIPTS</p><p>// scripts/dependencies.gradle </p><p>ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }</p><p>// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }</p></li><li><p>#4 CUSTOM SCRIPTS</p><p>// scripts/dependencies.gradle </p><p>ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }</p><p>// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }</p></li><li><p>#4 CUSTOM SCRIPTS</p><p>// scripts/dependencies.gradle </p><p>ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }</p><p>// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }</p></li><li><p>#4 CUSTOM SCRIPTS</p><p>// scripts/dependencies.gradle </p><p>ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }</p><p>// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }</p></li><li><p>#4 CUSTOM SCRIPTS</p><p>// scripts/dependencies.gradle </p><p>ext { androidSupportVersion = '24.2.0' presentationDependencies = [ appCompatSupport : "com.android.support:appcompat-v7:${androidSupportVersion}", designSupport : "com.android.support:design:${androidSupportVersion}" ] }</p><p>// app/build.gradle apply from: '../scripts/dependencies.gradle'dependencies { compile presentationDependencies.appCompatSupport compile presentationDependencies.designSupport }</p></li><li><p>#5 BUILD TYPE TO RUN TESTS</p><p>// app/build.gradle android { testBuildType staging' </p><p>}</p></li><li><p>#5 BUILD TYPE TO RUN TESTS</p><p>// app/build.gradle android { testBuildType staging' </p><p>}</p></li><li><p>#6 SIGNING CREDENTIALS</p><p>// app/build.gradle </p><p>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'] } }}</p><p>// deployment/keystore.properties </p><p>storePassword = storePasswordkeyAlias = keyAliaskeyPassword = keyPassword</p></li><li><p>#6 SIGNING CREDENTIALS</p><p>// app/build.gradle </p><p>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'] } }}</p><p>// deployment/keystore.properties </p><p>storePassword = storePasswordkeyAlias = keyAliaskeyPassword = keyPassword</p></li><li><p>#6 SIGNING CREDENTIALS</p><p>// app/build.gradle </p><p>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'] } }}</p><p>// deployment/keystore.properties </p><p>storePassword = storePasswordkeyAlias = keyAliaskeyPassword = keyPassword</p></li><li><p>#6 SIGNING CREDENTIALS</p><p>// app/build.gradle </p><p>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'] } }}</p><p>// deployment/keystore.properties </p><p>storePassword = storePasswordkeyAlias = keyAliaskeyPassword = keyPassword</p></li><li><p>#7 CONTINUOUS DELIVERY</p><p>Crashlytics for Beta Testers distribution </p></li><li><p>#7 CONTINUOUS DELIVERY</p><p>Crashlytics for Beta Testers distribution </p><p>Fastlane Supply to upload to PlayStore </p><p>supply --apk path/to/app.apk</p></li><li><p>WANT TO LEARN MORE?</p><p>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/23s5</p></li><li><p>WANT TO LEARN MORE?</p><p> Gradle for Android and Java </p><p> by </p></li><li><p>THANK YOU!</p><p>Tania Pinheiro@tcmpinheiro</p></li></ul>