Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proguard - also use proguard files from modules

My projects build.gradle looks like following:

android { 
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "..."
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':androKnife')
}

And my androKnife module does have it's own proguard file. How can I make my main project use this file as well?

Is there some way to auto merge all proguard files of all modules, if I compile a project? Is there another way a module can specify it's proguard rules and a project can inherit it?

like image 540
prom85 Avatar asked Jun 11 '15 14:06

prom85


People also ask

Where do I put ProGuard file?

You can manually create the file in the \StudioProjects\your_project\app folder and you can add the custom rules.

What is difference between R8 and ProGuard?

R8 has more Kotlin support than that of Proguard. R8 is having a faster processing time than Proguard which reduces build time. R8 gives better output results than Proguard. R8 reduces the app size by 10 % whereas Proguard reduces app size by 8.5 %.

Does ProGuard obfuscate package name?

Obfuscating package names myapplication. MyMain is the main application class that is kept by the configuration. All other class names can be obfuscated. Note that not all levels of obfuscation of package names may be acceptable for all code.

Does ProGuard remove unused resources?

It will help you not only to remove unused resources, but also to find potential bugs. The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names.


1 Answers

The solution is to add following line to the libraries build.gradle: consumerProguardFiles 'proguard-rules.pro'

So my androKnife library looks like following:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            consumerProguardFiles 'proguard-rules.pro'
        }
    }
}

dependencies {

    ...
}
like image 150
prom85 Avatar answered Sep 19 '22 10:09

prom85