我的应用程序在我们必须测试的所有设备上都运行良好,但是在运行Android 4.1.2的Galaxy S3中,启动时失败了。在那个设备中,我得到一个与类相关的NoClassDefFoundError,当然就是在那里。我知道问题也可能与该类的依赖关系有关。这是它导入的类
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Iterator;
import javax.net.ssl.HttpsURLConnection;
由于我使用了很多库,我的Gradle文件中有multiDexEnabled = true
我正在阅读很多帖子,但我仍然不清楚为什么有些设备会抛出NoClassDefFoundError。有人说这是三星手机上的常见问题,但无论如何三星不是一个不容忽视的品牌。 我的直觉是问题可能与库之间的问题有关,但这一点很难调试。
任何帮助都会受到欢迎; - )
编辑: 错误日志是:
04-01 11:37:15.927 31708-31708/ie.aaireland.android.theaa E/dalvikvm: Could not find class 'io.realm.rx.RealmObservableFactory$4', referenced from method io.realm.rx.RealmObservableFactory.getObjectObservable
04-01 11:37:15.927 31708-31708/ie.aaireland.android.theaa E/dalvikvm: Could not find class 'io.realm.rx.RealmObservableFactory$3', referenced from method io.realm.rx.RealmObservableFactory.getRealmResultsObservable
04-01 11:37:15.932 31708-31708/ie.aaireland.android.theaa E/dalvikvm: Could not find class 'io.realm.rx.RealmObservableFactory$2', referenced from method io.realm.rx.RealmObservableFactory.from
04-01 11:37:15.937 31708-31708/ie.aaireland.android.theaa E/dalvikvm: Could not find class 'io.realm.rx.RealmObservableFactory$1', referenced from method io.realm.rx.RealmObservableFactory.from
04-01 11:37:16.112 31708-31708/ie.aaireland.android.theaa E/dalvikvm: Could not find class 'ie.aaireland.android.theaa.webservices.JSONConnection', referenced from method ie.aaireland.android.theaa.DataModel.<init>
04-01 11:37:16.112 31708-31708/ie.aaireland.android.theaa E/dalvikvm: Could not find class 'ie.aaireland.android.theaa.DataModel$1', referenced from method ie.aaireland.android.theaa.DataModel.geocodeLookup
04-01 11:37:16.117 31708-31708/ie.aaireland.android.theaa E/dalvikvm: Could not find class 'ie.aaireland.android.theaa.DataModel$TaskData', referenced from method ie.aaireland.android.theaa.DataModel.getTrafficRegions
04-01 11:37:16.117 31708-31708/ie.aaireland.android.theaa E/dalvikvm: Could not find class 'ie.aaireland.android.theaa.DataModel$2', referenced from method ie.aaireland.android.theaa.DataModel.run
04-01 11:37:16.117 31708-31708/ie.aaireland.android.theaa E/ACRA: ACRA caught a NoClassDefFoundError exception for ie.aaireland.android.theaa. Building report.
04-01 11:37:20.417 31708-31862/ie.aaireland.android.theaa E/ACRA: ie.aaireland.android.theaa fatal error : ie.aaireland.android.theaa.webservices.JSONConnection
java.lang.NoClassDefFoundError: ie.aaireland.android.theaa.webservices.JSONConnection
at ie.aaireland.android.theaa.DataModel.<init>(DataModel.java:92)
at ie.aaireland.android.theaa.TheAAApp.onCreate(TheAAApp.java:49)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1003)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4228)
at android.app.ActivityThread.access$1300(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
我的依赖项:
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/jsoup-1.8.3.jar')
compile "com.android.support:support-v4:${supportLibVersion}"
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.okio:okio:1.0.1'
compile 'com.sothree.slidinguppanel:library:3.0.0'
compile 'com.google.maps.android:android-maps-utils:0.4+'
compile 'com.pulsatehq.sdk:PulsateSdk:2.6.5'
JSONConnection是一个继承类,它正在进行大量的JSON - 对象转换(在两个方向上)。它是在我的包裹上,我的意思是,不属于任何图书馆
编辑:我的主要意图基本上是了解这类问题,正在发生什么。我的意思是,我的应用程序正在使用第三方SDK(Pulsate),它的库发生冲突,并且只在这个设备中重复,Retrofit使用了两个库(我的应用程序正在使用Retrofit)。完全相同的APK在其他较新的三星设备上运行顺畅。 Pulsate库崩溃的是Dagger和Realm。如果一些明智的开发人员可以启发我们,那将是非常好的。