我更新到最新版本的Android Studio和Android SDK后。我不能让它在OS 5以下的设备上运行。 我有multidex,应用程序很大。这是问题吗? 我将此添加到我的应用程序类的代码中:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
Log.i("","multidex installed BEFORE");
MultiDex.install(this);
Log.i("","multidex installed DONE");
}
有时它起作用,有时它不起作用。 我很多次都这样做,这是一个错误:
01-13 13:13:22.296: E/AndroidRuntime(13134): FATAL EXCEPTION: main
01-13 13:13:22.296: E/AndroidRuntime(13134): Process: nl.hgrams.passenger, PID: 13134
01-13 13:13:22.296: E/AndroidRuntime(13134): java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: java.lang.ClassNotFoundException: nl.hgrams.passenger.PSLocationCenter
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4703)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.ActivityThread.access$1600(ActivityThread.java:175)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.os.Handler.dispatchMessage(Handler.java:102)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.os.Looper.loop(Looper.java:146)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.ActivityThread.main(ActivityThread.java:5602)
01-13 13:13:22.296: E/AndroidRuntime(13134): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 13:13:22.296: E/AndroidRuntime(13134): at java.lang.reflect.Method.invoke(Method.java:515)
01-13 13:13:22.296: E/AndroidRuntime(13134): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
01-13 13:13:22.296: E/AndroidRuntime(13134): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
01-13 13:13:22.296: E/AndroidRuntime(13134): at dalvik.system.NativeStart.main(Native Method)
01-13 13:13:22.296: E/AndroidRuntime(13134): Caused by: java.lang.IllegalStateException: java.lang.ClassNotFoundException: nl.hgrams.passenger.PSLocationCenter
01-13 13:13:22.296: E/AndroidRuntime(13134): at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:218)
01-13 13:13:22.296: E/AndroidRuntime(13134): at com.android.tools.fd.runtime.BootstrapApplication.attachBaseContext(BootstrapApplication.java:230)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.Application.attach(Application.java:201)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.Instrumentation.newApplication(Instrumentation.java:997)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.Instrumentation.newApplication(Instrumentation.java:981)
01-13 13:13:22.296: E/AndroidRuntime(13134): at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
01-13 13:13:22.296: E/AndroidRuntime(13134): ... 11 more
01-13 13:13:22.296: E/AndroidRuntime(13134): Caused by: java.lang.ClassNotFoundException: nl.hgrams.passenger.PSLocationCenter
01-13 13:13:22.296: E/AndroidRuntime(13134): at java.lang.Class.classForName(Native Method)
01-13 13:13:22.296: E/AndroidRuntime(13134): at java.lang.Class.forName(Class.java:251)
01-13 13:13:22.296: E/AndroidRuntime(13134): at java.lang.Class.forName(Class.java:216)
01-13 13:13:22.296: E/AndroidRuntime(13134): at com.android.tools.fd.runtime.BootstrapApplication.createRealApplication(BootstrapApplication.java:206)
01-13 13:13:22.296: E/AndroidRuntime(13134): ... 16 more
01-13 13:13:22.296: E/AndroidRuntime(13134): Caused by: java.lang.VerifyError: nl/hgrams/passenger/PSLocationCenter
01-13 13:13:22.296: E/AndroidRuntime(13134): ... 20 more
有时它确实设法加载应用程序类,但后来我收到的错误是它无法识别googlemaps或Fabric或其他,例如:
01-13 13:25:04.086: E/AndroidRuntime(18218): FATAL EXCEPTION: main
01-13 13:25:04.086: E/AndroidRuntime(18218): Process: nl.hgrams.passenger, PID: 18218
01-13 13:25:04.086: E/AndroidRuntime(18218): java.lang.NoClassDefFoundError: com.google.android.gms.location.LocationRequest
01-13 13:25:04.086: E/AndroidRuntime(18218): at nl.hgrams.passenger.PSLocationCenter.onCreate(PSLocationCenter.java:167)
01-13 13:25:04.086: E/AndroidRuntime(18218): at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:263)
01-13 13:25:04.086: E/AndroidRuntime(18218): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
01-13 13:25:04.086: E/AndroidRuntime(18218): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4730)
01-13 13:25:04.086: E/AndroidRuntime(18218): at android.app.ActivityThread.access$1600(ActivityThread.java:175)
01-13 13:25:04.086: E/AndroidRuntime(18218): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
01-13 13:25:04.086: E/AndroidRuntime(18218): at android.os.Handler.dispatchMessage(Handler.java:102)
01-13 13:25:04.086: E/AndroidRuntime(18218): at android.os.Looper.loop(Looper.java:146)
01-13 13:25:04.086: E/AndroidRuntime(18218): at android.app.ActivityThread.main(ActivityThread.java:5602)
01-13 13:25:04.086: E/AndroidRuntime(18218): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 13:25:04.086: E/AndroidRuntime(18218): at java.lang.reflect.Method.invoke(Method.java:515)
01-13 13:25:04.086: E/AndroidRuntime(18218): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
01-13 13:25:04.086: E/AndroidRuntime(18218): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
01-13 13:25:04.086: E/AndroidRuntime(18218): at dalvik.system.NativeStart.main(Native Method)
我猜测在MultiDex.install完成之前它会到达代码,这就是它崩溃的原因吗?我对吗?如果是的话,如何解决这个问题?
PS:构建文件:http://pastebin.com/Y2F4zYnu 申请类:http://pastebin.com/QuuxxxbW