Upgrade to Pro — share decks privately, control downloads, hide ads and more …

7_ways_to_improve_your_gradle_build.pdf

 7_ways_to_improve_your_gradle_build.pdf

Talk from Droidcon London 2016

Avatar for Tania Pinheiro

Tania Pinheiro

October 27, 2016

Other Decks in Programming

Transcript

  1. #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. #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
 } }
  3. #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
 } }
  4. #2 APPLICATIONID // app/build.gradle
 
 android {
 defaultConfig {
 applicationId

    applicationIdName
 }
 productFlavors {
 pro {
 applicationId applicationIdName + ".pro"
 }
 free {
 applicationId applicationIdName + ".free"
 }
 }
 buildTypes {
 debug {
 applicationIdSuffix ".debug"
 } } }
  5. #2 APPLICATIONID // app/build.gradle
 
 android {
 defaultConfig {
 applicationId

    applicationIdName
 }
 productFlavors {
 pro {
 applicationId applicationIdName + ".pro"
 }
 free {
 applicationId applicationIdName + ".free"
 }
 }
 buildTypes {
 debug {
 applicationIdSuffix ".debug"
 } } }
  6. #2 APPLICATIONID // app/build.gradle
 
 android {
 defaultConfig {
 applicationId

    applicationIdName
 }
 productFlavors {
 pro {
 applicationId applicationIdName + ".pro"
 }
 free {
 applicationId applicationIdName + ".free"
 }
 }
 buildTypes {
 debug {
 applicationIdSuffix ".debug"
 } } }
  7. #2 APPLICATIONID // app/build.gradle
 
 android {
 defaultConfig {
 applicationId

    applicationIdName
 }
 productFlavors {
 pro {
 applicationId applicationIdName + ".pro"
 }
 free {
 applicationId applicationIdName + ".free"
 }
 }
 buildTypes {
 debug {
 applicationIdSuffix ".debug"
 } } }
  8. #2 APPLICATIONID // app/build.gradle
 
 android {
 defaultConfig {
 applicationId

    applicationIdName
 }
 productFlavors {
 pro {
 applicationId applicationIdName + ".pro"
 }
 free {
 applicationId applicationIdName + ".free"
 }
 }
 buildTypes {
 debug {
 applicationIdSuffix ".debug"
 } } }
  9. #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>
  10. #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>
  11. #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>
  12. #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>
  13. #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 }
  14. #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 }
  15. #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 }
  16. #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 }
  17. #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 }
  18. #5 BUILD TYPE TO RUN TESTS // app/build.gradle 
 android

    {
 
 testBuildType ‘staging' }
  19. #5 BUILD TYPE TO RUN TESTS // app/build.gradle 
 android

    {
 
 testBuildType ‘staging' }
  20. #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 = storePassword
 keyAlias = keyAlias
 keyPassword = keyPassword
  21. #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 = storePassword
 keyAlias = keyAlias
 keyPassword = keyPassword
  22. #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 = storePassword
 keyAlias = keyAlias
 keyPassword = keyPassword
  23. #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 = storePassword
 keyAlias = keyAlias
 keyPassword = keyPassword
  24. #7 CONTINUOUS DELIVERY Crashlytics for Beta Testers distribution Fastlane Supply

    to upload to PlayStore supply --apk path/to/app.apk