【问题标题】:Setting up Proguard with a Library project that depends on external jars使用依赖于外部 jar 的库项目设置 Proguard
【发布时间】:2014-04-23 11:17:58
【问题描述】:

我的 android 项目有很多依赖项,其中一个有一个带有一些 jar 的 libs 文件夹,在我尝试使用 proguard 之前一切正常。

在运行 proguard 时,我收到此日志的错误:

Warning: [!!few lines like this!!]: can't find superclass or interface [...]
Warning: [!!many lines like this!!]: can't find referenced class [...]
      You should check if you need to specify additional program jars.
Warning: there were 190 unresolved references to classes or interfaces.
         You may need to specify additional library jars (using '-libraryjars').
Warning: there were 6 unresolved references to program class members.
         Your input classes appear to be inconsistent.
         You may need to recompile them and try again.
         Alternatively, you may have to specify the option 
         '-dontskipnonpubliclibraryclassmembers'.
java.io.IOException: Please correct the above warnings first.

然后我尝试在我的 proguard 配置文件中添加 -libraryjars 标志,导致此附加警告高于其他警告:

Note: there were 698 duplicate class definitions.

我无法保护的库项目是 ShowcaseView (com.espian.showcaseview)。

其库的 libs 文件夹中的 jars 是:

  • android-support-v4.jar
  • mockito-all-1.9.5.jar
  • nineoldandroids-2.4.0.jar

我该怎么办?!

编辑

这是我的 proguard.cfg

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

#-libraryjars ../ShowcaseView-master/library/libs/android-support-v4.jar
#-libraryjars ../ShowcaseView-master/library/libs/mockito-all-1.9.5.jar
#-libraryjars ../ShowcaseView-master/library/libs/nineoldandroids-2.4.0.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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
    public static *** i(...);
    public static *** w(...);
}

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


#this is a try for all assets and res/raw/*html!
-keepclassmembers class **.R$* {
    public static <fields>;
}

-keep class **.R$*


#ACRA specifics
# Restore some Source file names and restore approximate line numbers in the stack traces,
# otherwise the stack traces are pretty useless
-keepattributes SourceFile,LineNumberTable

# ACRA needs "annotations" so add this... 
# Note: This may already be defined in the default "proguard-android-optimize.txt"
# file in the SDK. If it is, then you don't need to duplicate it. See your
# "project.properties" file to get the path to the default "proguard-android-optimize.txt".
-keepattributes *Annotation*

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {
    *;
}

# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
    *;
}

-keepnames class org.acra.sender.HttpSender$** {
    *;
}

-keepnames class org.acra.ReportField {
    *;
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
    public void addCustomData(java.lang.String,java.lang.String);
    public void putCustomData(java.lang.String,java.lang.String);
    public void removeCustomData(java.lang.String);
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
    public void handleSilentException(java.lang.Throwable);
}

【问题讨论】:

  • 我添加了完整的 proguard.cfg

标签: android proguard showcaseview


【解决方案1】:

试试这个

-libraryjars /libs/mail.jar
-libraryjars /libs/activation.jar
-libraryjars /libs/additionnal.jar

将你的 jar 文件路径写入 progurd.cfg 或 proguard-project.txt

【讨论】:

  • 正如我在问题中所写,我尝试添加 -libraryjars 但唯一的结果是获得新警告:注意:有 698 个重复的类定义。所以,我认为这不是解决方案。
【解决方案2】:

您应该为您的库添加这些行。他们不会警告 找不到参考类

-keep class com.nineoldandroids.** { *; }

-dontwarn -com.nineoldandroids.**

【讨论】:

    猜你喜欢
    • 2014-05-02
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 2016-04-22
    • 2016-11-04
    • 2013-02-16
    相关资源
    最近更新 更多