java - 配置混淆器以排除扩展 android.content.Context 的库 jar

标签 java android proguard

我正在将一个库集成到一个项目的设备中,该项目将被嵌入到设备操作系统中。为此,我们正在集成一个覆盖 Android 框架上下文的库 jar。

因此,尝试为应用程序启用 Proguard 时出现以下错误 - “有 220 个库类实例,具体取决于程序类”。

所有这些文件都是小部件和 View 。我该如何解决这个问题?

这是我的proguard-project.txt的内容

-injars      bin/classes
-outjars     bin/classes-processed.jar
-libraryjars /Users/me/android-sdk-mac_86/platforms/android-15/android.jar
-libraryjars libs/library-that-overrides-context.jar

-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.content.Context

这是我的proguard-android.txt的内容

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

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

-keepclassmembers class **.R$* {
    public static <fields>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

最佳答案

Android Ant/Eclipse 构建会自动为您指定所有必要的 -injars/-outjars/-libraryjars 选项。如果您有自定义构建过程,您应该只指定这些选项。否则,您会收到很多关于重复类和其他可能问题的警告。

如果您确实需要指定 -injars/-outjars/-libraryjars 选项,则使用 -injars 指定的类可以依赖于使用 -libraryjars 指定的类,但反之则不然。 CFR。 ProGuard 手册 > 故障排除 > Warning: library class ... depends on program class ...

关于java - 配置混淆器以排除扩展 android.content.Context 的库 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16215106/

相关文章:

java - finishActivity() 在 Android 中未按预期工作

android - 根据哪个 Activity 包含 fragment 执行 Intent

java - Libgdx 写入文件不起作用?

java - ProGuard 混淆、java、Google Gson 和通用集合——如何保留成员?

java - 使用 Apache Tika + Tesseract 提取扫描 PDF 的速度很慢

java - 使用字符串查找 Java 非字符串键控 Java HashMap

android - 使用 Scala 编写的库在 Android 应用程序上运行 Proguard

Android Proguard 重复定义

java - 使用 Mockito 和 CDI 时如何不模拟对象?

java - 在 Tomcat 7 上部署 War 错误