You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何找到proguard.cfg文件?需配置Otto库混淆规则

Solution for Adding Otto ProGuard Rules When Missing 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:

  1. Understand the file name change
    Modern Android projects use proguard-rules.pro instead of the old proguard.cfg by default. Looking at your build.gradle config, 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!

  2. 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.pro in that location.
  3. Add your Otto ProGuard rules
    Open proguard-rules.pro and paste the rules you need:

    -keepattributes *Annotation*
    -keepclassmembers class ** {
        @com.squareup.otto.Subscribe public *;
        @com.squareup.otto.Produce public *;
    }
    
  4. 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:46:38