Currently, I’m working on an Android library that relies on other libraries like Gson and Glide. Our senior developer mentioned that when using Proguard, we should include Proguard rules for these dependent libraries in the consumer-proguard-rules.pro
file.
However, when I create a new Android project, add dependencies for libraries like Gson and Glide, and perform obfuscation, no errors occur. Many sources on the Internet suggest that adding Proguard rules is necessary to avoid errors, which contradicts my experience.
I have the following (related) questions:
Why don’t errors occur even without adding Proguard rules for the dependent libraries?
Have there been any recent updates to Proguard or the Android Gradle plugin that might explain this?
What potential issues might arise if I don’t add Proguard rules for these dependencies?
Below, I have attached the contents of the build.gradle
file from the newly created project:
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
kotlin("plugin.serialization") version "1.9.21"
}
android {
namespace = "com.example.proguarddemo"
compileSdk = 34
defaultConfig {
applicationId = "com.example.proguarddemo"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
debug {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
configurations {
create("resolvedImplementation") {
extendsFrom(implementation.get())
isCanBeResolved = true
}
}
}
dependencies {
implementation("com.google.code.gson:gson:2.10.1")
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
I tried googling, and I created a new Android project and tested it and no errors occurred.
I want to know if I should include Proguard rules of dependent libraries in my consumer-proguard-rules.pro
file or not?
Park hyundeok is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.