从 Eclipse 迁移到 Android Studio 导致问题,应用程序未启动

Migrating from Eclipse to Android Studio causing problems, app not starting

我将我的应用程序从 eclipse 转移到 android studio,但该应用程序出现 "could not find class" 错误。我已经包含了所有必需的库、jar 等。与 S.O 上的其他问题不同,我的错误与我自己的 classes 有关,而不是来自其他图书馆的 classes。它主要在 class 中的 Handler 上崩溃。 这是日志猫:

06-25 10:44:09.112    4006-4006/? E/dalvikvm﹕ Could not find class'com.Mylocation.MyLocation1$MyLocationListener', referenced from method com.Mylocation.MyLocation1.startGPS
06-25 10:44:09.114    4006-4006/? E/dalvikvm﹕ Could not find class 'com.GetDetailBean.OrderDetailsBean', referenced from method com.taxi_customer_sharedpreference.Sharedpreferences.getOrderDetails
06-25 10:44:09.123    4006-4024/? E/dalvikvm﹕ Could not find class 'com.server_connection.AppClient$JSONEntity', referenced from method com.server_connection.AppClient.execute
06-25 10:44:09.763    4006-4012/? E/jdwp﹕ Failed sending reply to debugger: Success
06-25 10:44:10.417    4006-4024/? E/dalvikvm﹕ Could not find class 'com.asiApp.NewOtherDriver', referenced from method com.parsing.ParsingClass.getDriversList
06-25 10:44:10.418    4006-4024/? E/dalvikvm﹕ Could not find class 'com.asiApp.NewOtherDriver', referenced from method com.parsing.ParsingClass.getDriversList
06-25 10:44:10.423    4006-4024/? E/dalvikvm﹕ Could not find class 'com.GetDetailBean.HistoryDetailBean', referenced from method com.parsing.ParsingClass.getHistoryDetail
06-25 10:44:10.535    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap', referenced from method com.asiApp.MyMap.<init>
06-25 10:44:10.538    4006-4006/? E/dalvikvm﹕ Could not find class 'com.taxiConstant.Rotate3dAnimation', referenced from method com.asiApp.MyMap.applyRotation    
06-25 10:44:10.547    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap$GetAddressAsync', referenced from method com.asiApp.MyMap.moveTocurrent
06-25 10:44:10.548    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap', referenced from method com.asiApp.MyMap.updateDriversList
06-25 10:44:10.548    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap', referenced from method com.asiApp.MyMap.LogoutOtherDevice
06-25 10:44:10.551    4006-4006/? E/dalvikvm﹕ Could not find class 'com.map.Overlay.MyItemizedOverlay', referenced from method com.asiApp.MyMap.drawPoints
06-25 10:44:10.553    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap', referenced from method com.asiApp.MyMap.onActivityCreated
06-25 10:44:10.554    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap$GetAddressAsync2', referenced from method com.asiApp.MyMap.onActivityResult
06-25 10:44:10.555    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap', referenced from method com.asiApp.MyMap.onActivityResult
06-25 10:44:10.559    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap$GetAddressAsync2', referenced from method com.asiApp.MyMap.onCameraChange
06-25 10:44:10.561    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap', referenced from method com.asiApp.MyMap.onCreateDialog
06-25 10:44:10.561    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap', referenced from method com.asiApp.MyMap.onCreateDialog
06-25 10:44:10.564    4006-4006/? E/dalvikvm﹕ Could not find class 'com.asiApp.MyMap', referenced from method com.asiApp.MyMap.payOptions
06-25 10:44:10.576    4006-4006/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.asiApp.MyMap
        at com.asiApp.MyMap.<init>(MyMap.java:886)
        at com.asiApp.SlidingMain.displayView(SlidingMain.java:229)
        at com.asiApp.SlidingMain.onCreate(SlidingMain.java:161)
        at android.app.Activity.performCreate(Activity.java:5125)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2289)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2377)
        at android.app.ActivityThread.access0(ActivityThread.java:167)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:153)
        at android.app.ActivityThread.main(ActivityThread.java:5341)
        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:929)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
        at dalvik.system.NativeStart.main(Native Method)

这是第 886 行的代码:

private Handler changeaddtHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        chageAddresstoGeoThread.interrupt();
        if (msg.obj.toString().equalsIgnoreCase("change_success")) {
            if (changeGeopoint != null) {
                CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(changeGeopoint).zoom(16).build();
                mMap.animateCamera(CameraUpdateFactory
                        .newCameraPosition(cameraPosition));
            } else {
                Toast.makeText(context, "Sorry did't find your location.",
                        Toast.LENGTH_SHORT).show();
            }
        }
    }
};

代码在 Eclipse 上运行良好,没有任何问题。 任何帮助,将不胜感激。谢谢

我通过向我的应用程序添加 MultiDex 支持解决了这个问题。 我没有完全实现 MultiDex 支持,所以我的一些 classes 不在正确的 dex 文件中。要修复它,您要做的不仅仅是在 defaultConfig 块中设置 multiDexEnabled = true。您还必须:

  1. 在您的依赖项中包含编译 'com.android.support:multidex:1.0.0'
  2. 让您的应用程序 class 扩展 MultiDexApplication 而不仅仅是应用程序。或者,您可以在应用程序的 attachBaseContext() 中调用 MultiDex.install()。

有关详细信息,请参阅 https://developer.android.com/tools/building/multidex.html

最初引用自 this question from stack overflow