方法ID不在[0,0xffff]中:小应用程序中的65536错误

时间:2014-07-23 14:24:22

标签: android gradle dependencies proguard dalvik

我们确实有一个小应用程序,使用大约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')
}

以下是我的程序代码:

##---------------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.**

先谢谢。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

所以,我能够解决它。 proguard代码实际上很好,但我将它放在错误的文件中。它应该在生成dex文件的模块中。我之前把它放在静态库中。

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

感谢。 :)