7 ways to improve your gradle build
TRANSCRIPT
7 WAYS TO IMPROVE YOUR
GRADLE BUILDTania Pinheiro@tcmpinheiro
Droidcon London 2016
WHY?
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
<application android:label=“@string/app_name” android:icon="${appIcon}" >
</application>
#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>
#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>
#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>
#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 DELIVERY
Crashlytics for Beta Testers distribution
#7 CONTINUOUS DELIVERY
Crashlytics for Beta Testers distribution
Fastlane Supply to upload to PlayStore
supply --apk path/to/app.apk
WANT TO LEARN MORE?
WANT TO LEARN MORE?
Gradle for Android and Java
by
THANK YOU!
Tania Pinheiro@tcmpinheiro