好朋友在Stack Overflow
我最近在Android应用中实施Fiksu SDK时遇到了问题。简短的介绍,Fiksu SDK是一个注册安装和事件的营销工具。与Fiksu相关的所有方法都在名为“ASOTracking.jar”的.jar文件中
问题:
库设置正确,Gradle在项目编译时没有报告错误,我甚至可以调试apk。但是,它在尝试初始化SDK时会在运行时抛出“java.lang.NoClassDefFoundError”。
日志:
01-27 14:06:54.801 31166-31166/com.example.myapp I/dalvikvm﹕ Could not find method com.fiksu.asotracking.FiksuDeviceSettingsManager.getInstance, referenced from method com.fiksu.asotracking.FiksuTrackingManager.getClientId
01-27 14:06:54.801 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve static method 13738: Lcom/fiksu/asotracking/FiksuDeviceSettingsManager;.getInstance ()Lcom/fiksu/asotracking/FiksuDeviceSettingsManager;
01-27 14:06:54.801 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0000
01-27 14:06:54.806 31166-31166/com.example.myapp I/dalvikvm﹕ Could not find method com.fiksu.asotracking.FiksuConfigurationManager.getInstance, referenced from method com.fiksu.asotracking.FiksuTrackingManager.initialize
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve static method 13733: Lcom/fiksu/asotracking/FiksuConfigurationManager;.getInstance ()Lcom/fiksu/asotracking/FiksuConfigurationManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x000f
01-27 14:06:54.806 31166-31166/com.example.myapp I/dalvikvm﹕ Could not find method com.fiksu.asotracking.FiksuDeviceSettingsManager.getInstance, referenced from method com.fiksu.asotracking.FiksuTrackingManager.isAppTrackingEnabled
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve static method 13738: Lcom/fiksu/asotracking/FiksuDeviceSettingsManager;.getInstance ()Lcom/fiksu/asotracking/FiksuDeviceSettingsManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0000
01-27 14:06:54.806 31166-31166/com.example.myapp I/dalvikvm﹕ Could not find method com.fiksu.asotracking.FiksuDeviceSettingsManager.getInstance, referenced from method com.fiksu.asotracking.FiksuTrackingManager.setAppTrackingEnabled
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve static method 13738: Lcom/fiksu/asotracking/FiksuDeviceSettingsManager;.getInstance ()Lcom/fiksu/asotracking/FiksuDeviceSettingsManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0010
01-27 14:06:54.806 31166-31166/com.example.myapp I/dalvikvm﹕ Could not find method com.fiksu.asotracking.FiksuDeviceSettingsManager.getInstance, referenced from method com.fiksu.asotracking.FiksuTrackingManager.setClientId
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve static method 13738: Lcom/fiksu/asotracking/FiksuDeviceSettingsManager;.getInstance ()Lcom/fiksu/asotracking/FiksuDeviceSettingsManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0010
01-27 14:06:54.806 31166-31166/com.example.myapp I/dalvikvm﹕ Could not find method com.fiksu.asotracking.FiksuConfigurationManager.getInstance, referenced from method com.fiksu.asotracking.FiksuTrackingManager.setDebugModeEnabled
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve static method 13733: Lcom/fiksu/asotracking/FiksuConfigurationManager;.getInstance ()Lcom/fiksu/asotracking/FiksuConfigurationManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0001
01-27 14:06:54.806 31166-31166/com.example.myapp E/dalvikvm﹕ Could not find class 'com.fiksu.asotracking.CustomEventTracker', referenced from method com.fiksu.asotracking.FiksuTrackingManager.uploadCustomEvent
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve new-instance 2112 (Lcom/fiksu/asotracking/CustomEventTracker;) in Lcom/fiksu/asotracking/FiksuTrackingManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x000f
01-27 14:06:54.806 31166-31166/com.example.myapp E/dalvikvm﹕ Could not find class 'com.fiksu.asotracking.PurchaseEventTracker', referenced from method com.fiksu.asotracking.FiksuTrackingManager.uploadPurchase
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve new-instance 2125 (Lcom/fiksu/asotracking/PurchaseEventTracker;) in Lcom/fiksu/asotracking/FiksuTrackingManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0022
01-27 14:06:54.806 31166-31166/com.example.myapp E/dalvikvm﹕ Could not find class 'com.fiksu.asotracking.PurchaseEventTracker', referenced from method com.fiksu.asotracking.FiksuTrackingManager.uploadPurchaseEvent
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve new-instance 2125 (Lcom/fiksu/asotracking/PurchaseEventTracker;) in Lcom/fiksu/asotracking/FiksuTrackingManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0014
01-27 14:06:54.806 31166-31166/com.example.myapp E/dalvikvm﹕ Could not find class 'com.fiksu.asotracking.RegistrationEventTracker', referenced from method com.fiksu.asotracking.FiksuTrackingManager.uploadRegistration
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve new-instance 2126 (Lcom/fiksu/asotracking/RegistrationEventTracker;) in Lcom/fiksu/asotracking/FiksuTrackingManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x001e
01-27 14:06:54.806 31166-31166/com.example.myapp E/dalvikvm﹕ Could not find class 'com.fiksu.asotracking.RegistrationEventTracker', referenced from method com.fiksu.asotracking.FiksuTrackingManager.uploadRegistrationEvent
01-27 14:06:54.806 31166-31166/com.example.myapp W/dalvikvm﹕ VFY: unable to resolve new-instance 2126 (Lcom/fiksu/asotracking/RegistrationEventTracker;) in Lcom/fiksu/asotracking/FiksuTrackingManager;
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0010
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ DexOpt: unable to opt direct call 0x35ce at 0x2b in Lcom/fiksu/asotracking/FiksuTrackingManager;.initialize
01-27 14:06:54.806 31166-31166/com.example.myapp D/dalvikvm﹕ DexOpt: unable to opt direct call 0x35c5 at 0x2e in Lcom/fiksu/asotracking/FiksuTrackingManager;.initialize
01-27 14:06:54.811 31166-31166/com.example.myapp D/dalvikvm﹕ DexOpt: unable to opt direct call 0x359b at 0x15 in Lcom/fiksu/asotracking/FiksuTrackingManager;.uploadCustomEvent
01-27 14:06:54.811 31166-31166/com.example.myapp D/dalvikvm﹕ DexOpt: unable to opt direct call 0x35cf at 0x30 in Lcom/fiksu/asotracking/FiksuTrackingManager;.uploadPurchase
01-27 14:06:54.811 31166-31166/com.example.myapp D/dalvikvm﹕ DexOpt: unable to opt direct call 0x35cf at 0x23 in Lcom/fiksu/asotracking/FiksuTrackingManager;.uploadPurchaseEvent
01-27 14:06:54.811 31166-31166/com.example.myapp D/dalvikvm﹕ DexOpt: unable to opt direct call 0x35d1 at 0x26 in Lcom/fiksu/asotracking/FiksuTrackingManager;.uploadRegistration
01-27 14:06:54.811 31166-31166/com.example.myapp I/dalvikvm﹕ DexOpt: unable to optimize static field ref 0x1507 at 0x16 in Lcom/fiksu/asotracking/FiksuTrackingManager;.uploadRegistrationEvent
01-27 14:06:54.811 31166-31166/com.example.myapp D/dalvikvm﹕ DexOpt: unable to opt direct call 0x35d1 at 0x19 in Lcom/fiksu/asotracking/FiksuTrackingManager;.uploadRegistrationEvent
01-27 14:06:54.811 31166-31166/com.example.myapp D/AndroidRuntime﹕ Shutting down VM
01-27 14:06:54.811 31166-31166/com.example.myapp W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41ecb700)
01-27 14:06:54.821 31166-31166/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.fiksu.asotracking.FiksuConfigurationManager
at com.fiksu.asotracking.FiksuTrackingManager.initialize(FiksuTrackingManager.java:83)
at com.example.userinterface.MyApplication.onCreate(MyApplication.java:56)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4684)
at android.app.ActivityThread.access$1400(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)
我的本地环境:
我尝试了什么:
Android Studio - Importing external Library/Jar
Android Studio: Add jar as library?
Android studio Gradle Could not find method compile()
Getting "Caused by: java.lang.VerifyError:"
Unable to find classes in Android library file
NoClassDefFoundError with libraries in Android Studio
最后的想法:
我需要一些认真的帮助,因为我已经尝试过我所知道的一切。在从Eclipse迁移此项目之前,此SDK工作正常。现在,它在Android Studio中运行时抛出奇怪的异常。
最后一件事有点可疑--- Android Studio中的类路径文件(***。imi文件),我重新安排了它中的类路径条目,但它仍然不起作用。
谢谢你们提前帮忙!
答案 0 :(得分:23)
新发现
我的GS4(Android 4.3)无法运行此应用,但HTC One M8(Android 5.0.1)可以运行它
根本原因
65K方法限制 请参阅此文档:https://developer.android.com/tools/building/multidex.html 基本上有方法参考限制,唯一的解决方案是使用multidex配置。然而,对于5.0之前和5.0之后的平台有实现。
<强>解决方案强>
解决方案描述于: https://developer.android.com/tools/building/multidex.html https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html 对于我的项目,由于它支持旧版Android,我使用“multidex支持库”解决方案。
dexOptions {
incremental true
javaMaxHeapSize "4g"
}