没有在路径上找到MainActivity

时间:2016-12-29 18:42:48

标签: java android android-studio dex

我正在使用android studio 2.3 beta 1以及这些配置

compileSdkVersion 25

buildToolsVersion" 25.0.2"

applicationId" octave.foodster"

minSdkVersion 19

targetSdkVersion 25

问题是,当我通过android工作室运行一个应用程序一切正常但当我将同一个应用程序的apk发送到另一部手机时,它崩溃。我只是使用一个基本的活动所以只是android工作室的默认模板创建新项目的那一刻。我没有添加任何外部库或其他任何东西。

清单文件

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我得到的错误是

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: octave.foodster, PID: 8580
              java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{octave.foodster/octave.foodster.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "octave.foodster.MainActivity" on path: DexPathList[[zip file "/data/app/octave.foodster-1/base.apk"],nativeLibraryDirectories=[/data/app/octave.foodster-1/lib/arm64, /vendor/lib64, /system/lib64]]
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2566)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725)
                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572)
                  at android.os.Handler.dispatchMessage(Handler.java:111)
                  at android.os.Looper.loop(Looper.java:207)
                  at android.app.ActivityThread.main(ActivityThread.java:5896)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
               Caused by: java.lang.ClassNotFoundException: Didn't find class "octave.foodster.MainActivity" on path: DexPathList[[zip file "/data/app/octave.foodster-1/base.apk"],nativeLibraryDirectories=[/data/app/octave.foodster-1/lib/arm64, /vendor/lib64, /system/lib64]]
                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                  at android.app.Instrumentation.newActivity(Instrumentation.java:1072)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2556)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725) 
                  at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1572) 
                  at android.os.Handler.dispatchMessage(Handler.java:111) 
                  at android.os.Looper.loop(Looper.java:207) 
                  at android.app.ActivityThread.main(ActivityThread.java:5896) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
                Suppressed: java.lang.ClassNotFoundException: octave.foodster.MainActivity
                  at java.lang.Class.classForName(Native Method)
                  at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                  at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                  at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                        ... 12 more
               Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available  

1 个答案:

答案 0 :(得分:5)

当我试图在启用即时运行的情况下运行apk时,我遇到了同样的问题。

解决方案: -

  

禁用即时运行并在设备中安装该apk。

快乐的编码。享受。