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

如何阻止ProGuard向类中添加“compiled from:”注释?

Hey there, great question! That /* compiled from: BaseAdapter */ comment you're seeing isn't actually added by ProGuard itself—it's a leftover from Android's default code shrinking tool, R8 (which replaced traditional ProGuard a while back). R8 keeps source file association info by default, which ends up as those comments when you decompile.

Luckily, it's super easy to disable this. Here's what you need to do:

Step 1: Update your ProGuard rules

Open your proguard-rules.pro file and add these lines:

# Wipe out source file attribute values to eliminate compiled-from comments
-renamesourcefileattribute ""
# Tell R8/ProGuard not to retain source file or line number attributes at all
-dontkeepattributes SourceFile,LineNumberTable

The first line blanks out the value of the SourceFile attribute (which is what shows up in the comment), while the second line tells the tool to discard those attributes entirely—double protection against these traces.

Step 2: Adjust your build.gradle if needed

If you're testing this in a debug build (like your snippet shows with debuggable true), note that debug mode can retain extra debugging info. If you don't need to debug the obfuscated debug APK, set debuggable false in your debug build type to tighten things up:

buildTypes {
    debug {
        debuggable false
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

Why this works

Those compiled from comments come from the SourceFile attribute that R8 adds to class files during compilation. By either blanking its value or discarding the attribute entirely, you remove the data that decompilers use to generate those comments.

After adding these changes, rebuild your APK and decompile it again—those annoying comments should be gone, keeping your obfuscation cleaner.

内容的提问来源于stack exchange,提问作者Itay Feldman

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:35:09