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

如何使用ProGuard混淆接口方法?配置未生效求助

Fixing ProGuard Rule for Obfuscating Interface Methods

Hey there, let's break down why your current rule isn't working and get you a solution that actually does what you need.

First, the problem with your original rule:

-keep public interface * { !** <methods>; }

That syntax isn't valid in ProGuard. The !** pattern doesn't work like that inside the method block of a -keep rule—ProGuard doesn't recognize it, so the rule gets ignored entirely.

Scenario 1: Keep Public Interfaces, Obfuscate Their Methods

If your goal is to keep all public interfaces intact (not deleted or renamed) but obfuscate their method names, use these rules:

# Keep the public interface definitions themselves (prevents deletion/renaming)
-keep public interface * {
    <methods>; # Ensures methods aren't removed, but allows name obfuscation
}

# Explicitly allow obfuscation of the interface method names
-allowobfuscation public interface * {
    <methods>;
}

Scenario 2: Keep Specific Interface Methods, Obfuscate the Rest

If you need to preserve certain methods (like a callback method) but obfuscate all others, adjust the rules to target only the methods you want to keep:

# Keep the public interface itself
-keep public interface * {
    # Retain this specific method's name and signature
    public void onCompleted();
    # Include all other methods (they'll be eligible for obfuscation)
    <methods>;
}

# Allow obfuscation for all methods except the one we explicitly kept
-allowobfuscation public interface * {
    !public void onCompleted();
    <methods>;
}

Important Note: Interface Implementations

If your interfaces are implemented by other classes, ProGuard will retain interface method names to maintain consistency with the implemented methods. To fix this, you also need to allow obfuscation of the implemented methods:

# Allow obfuscation of methods in classes that implement any interface
-allowobfuscation class * implements * {
    <methods>;
}

This ensures that both the interface methods and their implementations get their names obfuscated together, avoiding breaking changes.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 06:30:23