I'd like to use proguard on my library, but the file (rules) should be set inside the library. That means I don't want to set the rules w(hich belong to the library) explicitly in my app module.
I found that there is something like consumerProguardFiles property. My settings:
library gradle:
buildTypes {
debug {
debuggable true
minifyEnabled false
}
release {
minifyEnabled true
consumerProguardFiles 'proguard-rules.pro'
}
}
app gradle:
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
release {
debuggable false
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Why does configuration above doesn't work? I get errors that packages/symbols from the library cannot be found.
Edited:
What is important my proguard-rules.pro for the library and proguard-rules.pro for the main app module are both empty.
Exemplary errors:
Error:(3, 60) error: package (my library package here) does not exist
(...)
Error:(16, 9) error: cannot find symbol class NavigationStructureModel
(...)
More then one handrued errors. As I can see my all classes from the library are missing.
Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Library Dependency in the dropdown. In the Add Library Dependency dialog, use the search box to find the library to add.
consumerProguardFiles 'consumer-rules.pro'} A consumer proguard rules file is like any other proguard rules files with the caveat that the rules inside it are automatically applied to the consuming application when the application is being built in a proguard enabled mode.
You need to figure out if you want to
That's BEFORE it reaches the application. Your library proguard rules are responsible for making all code accessible and present but you may obfuscate internal classes.
Here's the library build.gradle:
android {
defaultConfig {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
buildTypes {
release {
minifyEnabled true // Yes, run proguard on the library itself.
}
}
}
If you release this library as open source you don't need this. If you don't release the library to public you don't need this.
I get errors that packages/symbols from the library cannot be found.
Proguard builds a graph of dependencies among classes. At this point the library is a standalone unit so if you didn't supply any rules, none of the classes are ever used so proguard removes them all.
Let the consumer (application) know, which classes of the library are to be kept.
Here's the library build.gradle:
android {
defaultConfig {
// Here's what proguard on the app should do on the library's behalf.
consumerProguardFiles 'proguard-consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false // No, don't proguard the library itself.
}
}
}
You need to tell proguard what code to keep and what names to keep. Proguard removes all unused code and scrambles names you didn't want to stick around.
You don't tell proguard what to remove, you tell proguard what to keep.
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