I would like to run ProGuard on release build of my Android library. Below is my build.gradle
file that is within 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@5f3306ad] on project
It seems that plugin android-library
is missing the buildTypes
method. If I change apply plugin
to android
, gradlew
runs successfully. However, this is a library project and I would like to keep it so. Other parts my my gradle.build
(not mentioned here) rely on the project being a library.
Is there any way to make the android-library
plugin run ProGuard on build?
There are two general types of plugins in Gradle, binary plugins and script plugins.
The Android Gradle plugin (AGP) is the official build system for Android applications. It includes support for compiling many different types of sources and linking them together into an application that you can run on a physical Android device or an emulator.
The Android Gradle plugin generates proguard-android-optimize. txt , which includes rules that are useful to most Android projects and enables @Keep* annotations. By default, when creating a new module using Android Studio, the module-level build. gradle file includes this rules file in your release build for you.
Solved my issue by taking release
out of buildTypes
like so:
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 issue I was having after solving the initial buildTypes
problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With