7 ways to improve your gradle build

30
7 WAYS TO IMPROVE YOUR GRADLE BUILD Tania Pinheiro @tcmpinheiro Droidcon London 2016

Upload: tania-pinheiro

Post on 16-Apr-2017

54 views

Category:

Software


4 download

TRANSCRIPT

Page 1: 7 Ways to improve your gradle build

7 WAYS TO IMPROVE YOUR

GRADLE BUILDTania Pinheiro@tcmpinheiro

Droidcon London 2016

Page 2: 7 Ways to improve your gradle build

WHY?

Automate tasks

Customise the build to the current project

Integrate continuous delivery

Page 3: 7 Ways to improve your gradle build

#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 } }

Page 4: 7 Ways to improve your gradle build

#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 } }

Page 5: 7 Ways to improve your gradle build

#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 } }

Page 6: 7 Ways to improve your gradle build

#2 APPLICATIONID

// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }

Page 7: 7 Ways to improve your gradle build

#2 APPLICATIONID

// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }

Page 8: 7 Ways to improve your gradle build

#2 APPLICATIONID

// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }

Page 9: 7 Ways to improve your gradle build

#2 APPLICATIONID

// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }

Page 10: 7 Ways to improve your gradle build

#2 APPLICATIONID

// app/build.gradleandroid { defaultConfig { applicationId applicationIdName } productFlavors { pro { applicationId applicationIdName + ".pro" } free { applicationId applicationIdName + ".free" } } buildTypes { debug { applicationIdSuffix ".debug" } } }

Page 11: 7 Ways to improve your gradle build

#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

<application android:label=“@string/app_name” android:icon="${appIcon}" >

</application>

Page 12: 7 Ways to improve your gradle build

#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

<application android:label=“@string/app_name” android:icon="${appIcon}" >

</application>

Page 13: 7 Ways to improve your gradle build

#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

<application android:label=“@string/app_name” android:icon="${appIcon}" >

</application>

Page 14: 7 Ways to improve your gradle build

#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

<application android:label=“@string/app_name” android:icon="${appIcon}" >

</application>

Page 15: 7 Ways to improve your gradle build

#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 }

Page 16: 7 Ways to improve your gradle build

#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 }

Page 17: 7 Ways to improve your gradle build

#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 }

Page 18: 7 Ways to improve your gradle build

#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 }

Page 19: 7 Ways to improve your gradle build

#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 }

Page 20: 7 Ways to improve your gradle build

#5 BUILD TYPE TO RUN TESTS

// app/build.gradle android { testBuildType ‘staging'

}

Page 21: 7 Ways to improve your gradle build

#5 BUILD TYPE TO RUN TESTS

// app/build.gradle android { testBuildType ‘staging'

}

Page 22: 7 Ways to improve your gradle build

#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

Page 23: 7 Ways to improve your gradle build

#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

Page 24: 7 Ways to improve your gradle build

#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

Page 25: 7 Ways to improve your gradle build

#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

Page 26: 7 Ways to improve your gradle build

#7 CONTINUOUS DELIVERY

Crashlytics for Beta Testers distribution

Page 27: 7 Ways to improve your gradle build

#7 CONTINUOUS DELIVERY

Crashlytics for Beta Testers distribution

Fastlane Supply to upload to PlayStore

supply --apk path/to/app.apk

Page 29: 7 Ways to improve your gradle build

WANT TO LEARN MORE?

Gradle for Android and Java

by

Page 30: 7 Ways to improve your gradle build

THANK YOU!

Tania Pinheiro@tcmpinheiro