【问题标题】:method ID not in [0, 0xffff]: 65536 error in a small app方法 ID 不在 [0, 0xffff] 中:小应用程序中出现 65536 错误
【发布时间】:2014-09-14 19:02:51
【问题描述】:

不过,我们确实有一个小应用程序,使用了大约 10 个罐子。我被它困住了。 我配置了 Proguard,它仍然说同样的话。根据 Proguard 结果,我们只有 500 多个未使用的方法。我可能做错了什么或遗漏了什么?

以下是gradle文件依赖:

我们的“图书馆”模块:

dependencies {
    compile 'com.android.support:support-v4:20.+'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/jackson-annotations-2.2.3.jar')
    compile files('libs/jackson-core-2.2.3.jar')
    compile files('libs/jackson-databind-2.2.3.jar')
    compile files('libs/okhttp-1.6.0.jar')
    compile files('libs/okhttp-urlconnection-1.6.0.jar')
    compile files('libs/okio-1.0.0.jar')
    compile files('libs/ormlite-android-4.48.jar')
    compile files('libs/ormlite-core-4.48.jar')
    compile files('libs/otto-1.3.4.jar')
    compile files('libs/picasso-2.3.2.jar')
    compile files('libs/retrofit-1.5.1.jar')
    compile project(':googlemapssdkm4b_lib')
}

应用模块:

dependencies {
    compile project(':sherpaTaxiLibrary')
    compile project(':facebookSDK')
    compile project(':v4PrefFragment')
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'com.android.support:support-v4:20.+'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.jakewharton:butterknife:5.1.1'
    compile 'com.braintreepayments.api:braintree:1.+'
    compile files('libs/twitter4j-core-4.0.2.jar')
}

下面是我的proguard代码:

##---------------Begin: proguard configuration common for all Android apps ----------
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt 
-printseeds seeds.txt 
-printusage unused.txt 
-printmapping mapping.txt 
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-repackageclasses ''

-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
-dontnote com.android.vending.licensing.ILicensingService

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
    native <methods>;
}

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

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

# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
  public static <fields>;
}

# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep public class * {
    public protected *;
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
##---------------End: proguard configuration common for all Android apps ----------

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

##---------------End: proguard configuration for Gson  ----------

-dontwarn rx.**, org.w3c.dom.**, com.squareup.okhttp.**, org.codehaus.mojo.**, 
java.nio.file.**, retrofit.** 

-libraryjars libs
-keep class com.google.gson.** { *; }
-keep class com.google.inject.* { *; }
-keep class org.apache.http.* { *; }
-keep class org.apache.james.mime4j.* { *; }
-keep class javax.inject.* { *; }
-keep class retrofit.* { *; }
-keep class com.example.testobfuscation.** { *; }
-keepattributes Signature
-keep class sun.misc.Unsafe { *; }


-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; } 

# Guava exclusions (http://code.google.com/p/guava-libraries/wiki/UsingProGuardWithGuava)
-dontwarn sun.misc.Unsafe
-dontwarn com.google.common.collect.MinMaxPriorityQueue
-keepclasseswithmembers public class * {
    public static void main(java.lang.String[]);
} 

# Guava depends on the annotation and inject packages for its annotations, keep them both
-keep public class javax.annotation.**
-keep public class javax.inject.**

提前致谢。

【问题讨论】:

  • We only have 500+ unused methods ... 仅限!尝试将您的方法分组,以便减少。请删除所有未使用的。
  • 您好 Frank,500 多个未使用的方法来自我们项目中包含的库。我们的课程非常小,只有大约 100 个非常短的课程。
  • 你有很多库。你确定你应该全部使用它们吗?
  • 是的,我们都使用它们。我们确实有用于 db 的 ormlite。杰克逊为 json。 okhttp、okio、picasso 和网络改造。用于位置、电子邮件登录、地点等的 google play 服务。用于地图的 google maps for business。用于注入视图的黄油刀和用于付款的大脑树。

标签: android gradle dependencies proguard dalvik


【解决方案1】:

所以,我能够修复它。 proguard 代码其实很好,但是我把它放在了错误的文件中。它应该在生成 dex 文件的模块中。我之前已经把它放在静态库中了。

另外,我使用https://gist.github.com/dmarcato/d7c91b94214acd936e42 删除了我不使用的 Google Play 服务包。 我将代码放在生成 APK 的模块的 gradle 文件中。

谢谢。 :)

【讨论】:

    【解决方案2】:

    ProGuard 可能会为您删除许多类和方法,但您的配置相当保守,明确保留了许多类、字段和方法:

    -keep class com.google.gson.** { *; }
    -keep class com.google.inject.* { *; }
    -keep class org.apache.http.* { *; }
    .....
    

    您可能在单独的文件中有更多选项,例如对于 Facebook SDK?

    请注意,文件proguard-project.txt 一开始可以基本上是空的,因为大部分配置已经在共享配置文件${sdk.dir}/tools/proguard/proguard-android.txt 中指定(引用自project.properties)。使用正确的 -keep 选项创建更好的配置可能需要一些研究和实验。

    您也不应该在配置文件中指定-injars-libraryjars 选项。 Gradle 构建过程已经自动为您指定了所有必要的-injars-outjars-libraryjars

    【讨论】:

    • 我刚刚意识到 Proguard 已打开,无需额外配置即可在没有任何模块依赖关系的项目中工作。我试图让它在一个模块中工作,该模块是我正在运行的主项目的依赖项。我试图将 Proguard 放在两者上,但它并没有删除所需的东西。谢谢
    • 嗨@EricLafortune,Proguard 现在可以工作了,但只能从 Google Play 服务中删除 400 多种方法。这是预期的吗?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多