4

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

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

所有这些文件都是小部件和视图。我怎样才能解决这个问题?

这是我的 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.**
4

2 回答 2

0

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

如果您确实需要指定 -injars/-outjars/-libraryjars 选项,则使用 -injars 指定的类可以依赖于使用 -libraryjars 指定的类,但不能反过来。参照。ProGuard 手册 > 疑难解答 >警告:库类 ... 取决于程序类 ...

于 2013-04-26T00:07:48.810 回答
0

即使我将我的库标记为 libraryjar,我也必须添加这些行

-keep public class android.content.** { *; }到项目 proguard 配置文件来解决问题。

于 2013-05-01T16:18:09.727 回答