控制 Android 中方法的 Proguard 瘦身

发布于 2024-11-14 19:43:27 字数 2491 浏览 3 评论 0原文

我正在使用 Eclipse 和最新 Android 版本中包含的 ProGuard 构建,试图混淆我的 Android 应用程序,但它不断删除重要的方法。我尝试编辑 proguard.cfg 文件以通过键入各种排除来保留方法,例如以下

  • keep public void myMethod(String myString)

  • keep public class myInterface

  • keep public class com.help.app.myInterface.**

但这些都不起作用。当我查看 use.txt 文件时,方法仍然存在,但我的应用程序无法运行。我不明白我做错了什么。我希望得到一些帮助。

这是我的类的样子

package com.whoiam.whatido;

public class MainClass extends Activity {
    ......
    public void onCreate(Bundle savedInstanceState) {
        ....

    }

    ....
    ....

    final class myInterface {

        myInterface() {}    

        public void dontDeleteMePlease(String message) {
            ....

        }
        public void leaveMeBe(String message) {
            ...

        }


        .....

    }
    final class MyWebChromeClient extends WebChromeClient {
        @Override 
        public boolean onJsAlert(WebView view) {
            ....
        }
}

这是我的 proguard.cfg 文件的示例(除了中间附近的三个“keep”之外,它是默认的):

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService

-keep public class com.whoiam.whatido.myInterface.**

-keep public class com.whoiam.whatido.myInterface.** {
    <methods>;}

-keep public void leaveMeBe(String message);

-keepclasseswithmembernames class * {
    native <methods>; }

-keepclasseswithmembernames class * {
    public <init>(android.content.Context,
android.util.AttributeSet); }

-keepclasseswithmembernames class * {
    public <init>(android.content.Context,
android.util.AttributeSet, int); }

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String); }

-keep class * implements android.os.Parcelable {   public
static final
android.os.Parcelable$Creator *; }

我还尝试了 -dontshrink 因为我真的不希望我的代码被削减。但可惜它还是缩小了。我也连续几个小时尝试了尽可能多的变体,但没有什么可以拯救我的方法。

如何将我的“donDontDeleteMePlease”从 ProGuard 的愤怒中拯救出来?我需要在 proguard.cfg 文件中输入什么才能使它像我一样?

I am using Eclipse and the built of ProGuard included with the latest Android release, trying to obfuscate my android app but it keeps removing important methods. I have tried editing the proguard.cfg file to keep the methods by typing various exclusions, such as the following

  • keep public void myMethod(String myString)

  • keep public class myInterface

  • keep public class com.help.app.myInterface.**

but none of these are working. When I look in the usage.txt file the methods are still there and my app doesn't function. I do not understand what I am doing wrong. I would appreciate some help.

Here is what my class looks like

package com.whoiam.whatido;

public class MainClass extends Activity {
    ......
    public void onCreate(Bundle savedInstanceState) {
        ....

    }

    ....
    ....

    final class myInterface {

        myInterface() {}    

        public void dontDeleteMePlease(String message) {
            ....

        }
        public void leaveMeBe(String message) {
            ...

        }


        .....

    }
    final class MyWebChromeClient extends WebChromeClient {
        @Override 
        public boolean onJsAlert(WebView view) {
            ....
        }
}

Here is an example of my proguard.cfg file (it is default except for the three 'keep' near the middle):

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService

-keep public class com.whoiam.whatido.myInterface.**

-keep public class com.whoiam.whatido.myInterface.** {
    <methods>;}

-keep public void leaveMeBe(String message);

-keepclasseswithmembernames class * {
    native <methods>; }

-keepclasseswithmembernames class * {
    public <init>(android.content.Context,
android.util.AttributeSet); }

-keepclasseswithmembernames class * {
    public <init>(android.content.Context,
android.util.AttributeSet, int); }

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String); }

-keep class * implements android.os.Parcelable {   public
static final
android.os.Parcelable$Creator *; }

I also tried -dontshrink since I don't really want my code slashed... but alas it shrinks anyway. I have also tried as many variations as I can think of for hours on end, but nothing saves my methods.

How do I save my "donDontDeleteMePlease" from ProGuard's wrath? What do I need to type into that proguard.cfg file to make it like me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2024-11-21 19:43:27

这应该可行:

-keep class com.whoiam.whatido.MainClass$myInterface {
  public void dontDeleteMePlease(java.lang.String);
  public void leaveMeBe(java.lang.String);
}

请注意,内部类是用 $ 指定的,并且它不是公共的。

您可以在 ProGuard 手册中找到更多信息和示例。

This should work:

-keep class com.whoiam.whatido.MainClass$myInterface {
  public void dontDeleteMePlease(java.lang.String);
  public void leaveMeBe(java.lang.String);
}

Note that the inner class is specified with a $ and that it is not public.

You can find more information and examples in the ProGuard manual.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文