如何找到proguard.cfg文件?需配置Otto库混淆规则
proguard.cfg Hey there! I see you're trying to add ProGuard rules for Square's Otto library but can't find the proguard.cfg file—let's get this sorted out quickly.
Here's what you need to do:
Understand the file name change
Modern Android projects useproguard-rules.proinstead of the oldproguard.cfgby default. Looking at yourbuild.gradleconfig, you already have this file specified in your release build type:buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }That's the correct setup!
Locate or create
proguard-rules.pro- This file is usually located in your module's root directory (e.g., the
app/folder of your project). - If it doesn't exist, just create a new text file named
proguard-rules.proin that location.
- This file is usually located in your module's root directory (e.g., the
Add your Otto ProGuard rules
Openproguard-rules.proand paste the rules you need:-keepattributes *Annotation* -keepclassmembers class ** { @com.squareup.otto.Subscribe public *; @com.squareup.otto.Produce public *; }Sync and build
After adding the rules, sync your Gradle project (click the "Sync Now" prompt in Android Studio) and run your release build. The rules will be applied correctly during minification.
Quick note:
The getDefaultProguardFile('proguard-android.txt') part loads Android's default ProGuard rules, and your custom proguard-rules.pro adds the Otto-specific rules on top—this is the recommended way to configure ProGuard in Android.
内容的提问来源于stack exchange,提问作者iFi

