无法在Android手机上运行debug apk

时间:2017-04-27 04:42:17

标签: java android android-studio

我在Windows 10上使用Android studio 2.3.1。当我尝试在设备上运行应用程序时,当我的设备连接到android studio时,我就可以运行该应用程序了。但当我尝试在Android手机上安装其调试或发布apk时,它正在安装,但在打开应用程序时它会出现以下错误:

public class DbHelperTest {
private DbHelper mDb;

    @Before
    public void setUp() throws Exception {
        getContext().deleteDatabase(DbHelper.DATABASE_NAME);
        mDb = new DbHelper(getTargetContext());
    }

    @After
    public void tearDown() throws Exception {
        mDb.close();
    }

    @Test
    public void onCreate() throws Exception {
        mDb.onCreate(mDb.getWritableDatabase());
    }

    @Test
    public void onUpgrade() throws Exception {
        mDb.onUpgrade(mDb.getWritableDatabase(), 1, 2);
    }

    @Test
    public void dropTable() throws Exception {
        String tableName = "mesa";
        mDb.getReadableDatabase().execSQL("CREATE TABLE "
            + tableName + "(_id INTEGER PRIMARY KEY AUTOINCREMENT)");
        mDb.dropTable(mDb.getWritableDatabase(), tableName);
    }
}

任何帮助将不胜感激。 我的gradle代码

04-27 10:06:31.675 30541-30541/package name E/AndroidRuntime: FATAL EXCEPTION: main
Process: package_Name, PID: 30541
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{package Name/package_Name.SplashActivity}: java.lang.ClassNotFoundException: Didn't find class "package_Name.SplashActivity" on path: DexPathList[[zip file "/data/app/package_Name-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
at android.app.ActivityThread.access$800(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5253)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695)

Caused by: java.lang.ClassNotFoundException: Didn't find class "package_Name.SplashActivity" on path: DexPathList[[zip file "/data/app/package_Name-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
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:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2217)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376) 
at android.app.ActivityThread.access$800(ActivityThread.java:147) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5253) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:900) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:695) 
Suppressed: java.lang.ClassNotFoundException: package Name.SplashActivity
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)
... 13 more

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

5 个答案:

答案 0 :(得分:3)

你可以通过" Build(tab)/ Build APK"来解决这个问题。而不是运行' app'

答案 1 :(得分:0)

@ASK可以请你清理你的项目并重建它。这是在您的apk未正确创建时主要获得的错误

答案 2 :(得分:0)

  

您的包名称不应包含代码中的空格,它们是包名称中的空格

请将其更改为package.name

答案 3 :(得分:0)

问题可能已经发生,因为您可能已超出64k方法限制。

您应该考虑在您的应用中启用multidex。

defaultConfig {
    ...
    ...

    // Enabling multidex support.
    multiDexEnabled true
}

dependencies {
compile 'com.android.support:multidex:1.0.0'
}

同时将此添加到清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.android.multidex.myapplication">
   <application
       ...
       android:name="android.support.multidex.MultiDexApplication">
       ...
   </application>
</manifest>

答案 4 :(得分:-1)

取消选中即时运行.. 怎么做:

  1. 打开“设置”或“首选项”对话框:在Windows或Linux上,选择“文件”&gt;菜单栏中的设置。在Mac OSX上,选择Android Studio&gt;菜单栏中的首选项。
  2. 导航至构建,执行,部署&gt;即时跑步。
  3. 取消选中代码更改时重新启动活动旁边的复选框。