How to make runProguard work for android-library Gradle plugin?

I would like to launch ProGuard in the release of my Android library. Below is my build.gradle file, which is in my project.

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android-library' repositories { mavenCentral() } android { compileSdkVersion 18 buildToolsVersion "18.0.1" defaultConfig { minSdkVersion 10 targetSdkVersion 18 } sourceSets { main { java { srcDir 'src/main/java' } resources { srcDir 'src/../lib' } } } buildTypes { release { runProguard true proguardFile getDefaultProguardFile('proguard-android.txt') } } } 

Running gradlew clean or gradlew build returns the following error:

> Could not find method buildTypes() for arguments [ build_25r1m0a3etn5cudtt5odlegprd$_run_closure2_closure10@5f3306a d] on project

It seems that the android-library plugin is missing the buildTypes method. If I change apply plugin to android , gradlew is successful. However, this is a library project, and I would like to keep it. Other parts of my my gradle.build (not mentioned here) rely on the library project.

Is there any way to make the android-library plugin run ProGuard when building?

+6
source share
1 answer

Solved my problem by selecting release from buildTypes as follows:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android-library' repositories { mavenCentral() } android { compileSdkVersion 18 buildToolsVersion "18.0.1" defaultConfig { minSdkVersion 10 targetSdkVersion 18 } sourceSets { main { java { srcDir 'src/main/java' } resources { srcDir 'src/../lib' } } } release { runProguard true proguardFile getDefaultProguardFile('proguard-android.txt') proguardFile 'proguard-android.txt' } } 

Also note that I added another proguardFile under release . This fixed another problem that occurred after solving the initial buildTypes problem.

+2
source

Source: https://habr.com/ru/post/954963/


All Articles