Posted by on 9th January 2019

How to recompile with -Xlint:deprecation

adding this to build.gradle

allprojects {
    ...

    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:deprecation"
        }
    }   
}

Removing unused resources and Java classes via resource shrinking

The Gradle build system for Android supports resource shrinking at build time. This automatically removes resources that are unused from the packaged application. In addition to that, this also removes unnecessary resources from libraries you are depending on. This can hugely reduce the size of your application.

To enable resource shrinking, update your build file similar to the following snippet.

android {
    ...

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Defining dependencies and keeping the version external

1. Manage dependencies versions in same gradle file Module level

apply plugin: 'com.android.application'
android {
      ...
    defaultConfig {...}
    buildTypes {...}
    productFlavors {...}
}
...

ext {
    supportLibraryVersion = '25.0.0'
    playServiceVersion = '10.2.0'
}

dependencies {
    // Android supported libraries
    compile "com.android.support:appcompat-v7:$supportLibraryVersion"
    compile "com.android.support:design:$supportLibraryVersion"
    
    //Google play services
    compile "com.google.android.gms:play-services:$playServiceVersion"
    compile "com.google.android.gms:play-services-fitness:$playServiceVersion"
   ...
}

2. Manage dependencies versions in same gradle file Project level

build.gradle(Project level)

buildscript {
    ...
}

allprojects {
    ...
}
...

ext {
    supportLibraryVersion = '23.4.0'
    playServicesVersion = '9.2.1'
}

build.gradle(Module level)

apply plugin: 'com.android.application'
android {
      ...
    defaultConfig {...}
    buildTypes {...}
    productFlavors {...}
}
...

dependencies {
    // Android supported libraries
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.supportLibraryVersion" 

    //Google play services
    compile "com.google.android.gms:play-services:$rootProject.playServiceVersion"
    compile "com.google.android.gms:play-services-fitness:$rootProject.playServiceVersion"  
    ...
}

Please follow and like us:
Posted in: Android

Comments

Be the first to comment.

Leave a Reply


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*


Enjoy this blog? Please spread the word :)