Android 中的 Proguard

发布于 2024-12-17 04:13:44 字数 1307 浏览 0 评论 0原文

我正在使用 proGuard 来混淆我的应用程序。我在应用程序中包含了库 jar,并且使用 ant 来构建应用程序。但在构建阶段我遇到了以下异常。

-dex:
      [dex] Converting compiled files and external libraries into /home/fiberlink/Desktop/Work/MaaS360/Maas360ControlAgent/bin/classes.dex...
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] java.util.zip.ZipException: error in opening zip file
       [dx]     at java.util.zip.ZipFile.open(Native Method)
       [dx]     at java.util.zip.ZipFile.<init>(ZipFile.java:127)
       [dx]     at java.util.zip.ZipFile.<init>(ZipFile.java:144)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:206)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
       [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:418)
       [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
       [dx]     at com.android.dx.command.dexer.Main.run(Main.java:206)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:174)
       [dx]     at com.android.dx.command.Main.main(Main.java:95)
       [dx] 1 error; aborting

我不明白问题是什么...请有人帮忙...

I am using proGuard to obfuscate my application. I included library jars in my application and I am using ant to build the application. But in the building phase I am getting the following exception.

-dex:
      [dex] Converting compiled files and external libraries into /home/fiberlink/Desktop/Work/MaaS360/Maas360ControlAgent/bin/classes.dex...
       [dx] 
       [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
       [dx] java.util.zip.ZipException: error in opening zip file
       [dx]     at java.util.zip.ZipFile.open(Native Method)
       [dx]     at java.util.zip.ZipFile.<init>(ZipFile.java:127)
       [dx]     at java.util.zip.ZipFile.<init>(ZipFile.java:144)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:206)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
       [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
       [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:418)
       [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
       [dx]     at com.android.dx.command.dexer.Main.run(Main.java:206)
       [dx]     at com.android.dx.command.dexer.Main.main(Main.java:174)
       [dx]     at com.android.dx.command.Main.main(Main.java:95)
       [dx] 1 error; aborting

I am not getting what the problem is... Somebody Please help...

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

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

发布评论

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

评论(2

蓝梦月影 2024-12-24 04:13:44

您的 proguard.cfg 文件是什么样的?您还需要在 default.properties 文件中添加 proguard.config=proguard.cfg(稍后在 API 级别进行更改)。

我的在下面,并且工作正常。

-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 * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

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

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

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

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

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

What does your proguard.cfg file look like? You'll also want proguard.config=proguard.cfg in your default.properties file (changed later on API level).

Mine is below, and works fine.

-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 * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

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

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

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

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

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
一紙繁鸢 2024-12-24 04:13:44

确保在使用 Proguard 时不要忘记有关 Android 的任何特殊信息的最佳方法是将 SDK 中的文件作为基本文件,位于此处:

C:\SDK\Android\sdk\tools\proguard\examples\android.pro

该文件有详细记录并预设了需要为 Android 应用程序设置的每个参数。

The best way to be sure not to forget anything special regarding Android when using Proguard is to take as a base file the one from the SDK, located here :

C:\SDK\Android\sdk\tools\proguard\examples\android.pro

This file is well documented and preset every parameters that need to be set for an Android application.

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