使用 ProGuard 和 Android 应用程序时出现重复资源

发布于 2024-12-25 10:21:46 字数 2487 浏览 1 评论 0原文

我正在尝试将 ProGuard 与我的一个应用程序(假设为 A)一起使用。该应用程序包含另一个应用程序作为库(假设为 B)。这是我的 proguard 文件。

-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 *;
}

-injars      bin/classes
-libraryjars lib 

当我第一次执行它时,我收到以下错误:

 Proguard returned with error code 1. See console
[2012-01-05 12:18:55 - BSabadellHC-Entrega] Note: there were 1059 duplicate class     definitions.
[2012-01-05 12:18:55 - BSabadellHC-Entrega] java.io.IOException: Can't write     [/private/var/folders/19/321lw_654pzdqr8y34ysvsx80000gn/T/android_7971378611269030364.jar]     (Can't read     [/private/var/folders/19/321lw_654pzdqr8y34ysvsx80000gn/T/android_1457478862713006376.jar]     (Duplicate zip entry [com/ideaknowing/labs/android/ikarengine/e.class ==     android_1457478862713006376.jar:com/ideaknowing/labs/android/ikarengine/R$anim.class]))

对我来说相关的部分是:

  • 有重复的对象
  • 他们应该是因为 R 文件。控制台说R$anim中有重复的资源(当然,因为应用程序A和库B都包含动画、布局等)。

所以我的想法显然是从 ProGuard 中排除 R 文件,为此我添加了以下代码行:

-keep public class net.firsrproject.android.R
-keep public class com.ideaknowing.labs.android.ikarengine.R 

尽管如此,我仍然遇到相同的错误(所以我猜这些文件仍然包含在 Proguard 中)。有人有从 ProGuard 中删除 R 文件的经验吗?关于如何消除此错误有任何提示或建议吗?

谢谢,并致以问候

I'm trying to use ProGuard with one of my applications, let's say A. This application includes another application as a library (let's say B). This is my proguard file.

-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 *;
}

-injars      bin/classes
-libraryjars lib 

When I first executed it, I got the following error:

 Proguard returned with error code 1. See console
[2012-01-05 12:18:55 - BSabadellHC-Entrega] Note: there were 1059 duplicate class     definitions.
[2012-01-05 12:18:55 - BSabadellHC-Entrega] java.io.IOException: Can't write     [/private/var/folders/19/321lw_654pzdqr8y34ysvsx80000gn/T/android_7971378611269030364.jar]     (Can't read     [/private/var/folders/19/321lw_654pzdqr8y34ysvsx80000gn/T/android_1457478862713006376.jar]     (Duplicate zip entry [com/ideaknowing/labs/android/ikarengine/e.class ==     android_1457478862713006376.jar:com/ideaknowing/labs/android/ikarengine/R$anim.class]))

The relevant parts for me are:

  • There are duplicate objects
  • They should because of the R files. It is said by the console that there are duplicate resources in R$anim (of course, since both the application A and the library B are including animations, layouts and so on).

So my idea was obviously to exclude from ProGuard the R files, and for that I included the following lines of code:

-keep public class net.firsrproject.android.R
-keep public class com.ideaknowing.labs.android.ikarengine.R 

Nevertheless, I still get the same error (so I guess the files are still being included in Proguard). Has anybody experience with removing R files from ProGuard? Is there any tip or suggestion on how can I get rid of this error?

Thanks, and regards

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

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

发布评论

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

评论(1

最舍不得你 2025-01-01 10:21:46

如果您使用的是 android 库项目,请删除 -injars bin/classes ,因为库中的类文件会使用此选项处理两次(这对我来说与 这个)。

如果上述方法不起作用,请尝试 -dontnote 选项。

Remove the -injars bin/classes if you are using android library project as the class files from the library are processed twice with this option (This worked for me in combination with this).

If the above doesn't work try the -dontnote option.

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