调试APK解析错误(通过单击android studio运行按钮生成)

时间:2018-01-22 08:22:25

标签: android android-studio parsing apk adb

我在android studio 3.0.1上开发了应用程序,但是当我将apk安装到手机上时出现错误 手机通过USB连接mac,点击运行按钮

enter image description here

,apk将安装并运行没有错误。但是如果我在finder中复制apk(就像这样)

enter image description here

到手机并将其安装在手机中,会出现错误" APK解析错误"。
如果安装apk by" adb install xxx.apk" ,当打开应用程序时,它将崩溃和logcat如下:

12-20 16:35:09.562 14658-14658/? I/art: Late-enabling -Xcheck:jni
12-20 16:35:09.562 14658-14658/? I/art: Reinit property: dalvik.vm.checkjni= false
12-20 16:35:09.614 14658-14658/com.xxx.xxx I/InstantRun: starting instant run server: is main process
12-20 16:35:09.620 14658-14658/com.xxx.xxx E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: com.xxx.xxx, PID: 14658
                                                                        java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.xxx.xxx/com.xxx.xxx.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.xxx.xxx.MainActivity" on path: DexPathList[[zip file "/data/app/com.xxx.xxx-1/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx-1/lib/arm64, /data/app/com.xxx.xxx-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2867)
                                                                            at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:105)
                                                                            at android.os.Looper.loop(Looper.java:156)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:6595)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
                                                                         Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xxx.xxx.MainActivity" on path: DexPathList[[zip file "/data/app/com.xxx.xxx-1/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx-1/lib/arm64, /data/app/com.xxx.xxx-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/vendor/lib64, /product/lib64]]
                                                                            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                            at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                            at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                            at android.app.Instrumentation.newActivity(Instrumentation.java:1083)
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2685)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2867) 
                                                                            at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:105) 
                                                                            at android.os.Looper.loop(Looper.java:156) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:6595) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) 
12-20 16:35:09.624 14658-14658/com.xxx.xxx I/Process: Sending signal. PID: 14658 SIG: 9

但是如果点击Bulid> Build APK(s),然后将apk复制到同一个文件夹(这个:apk)到手机,它将安装并运行,没有错误...

它是android studio中的一个错误吗?

的manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.xxx">
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.CAMERA" />

    <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>
</manifest>

2 个答案:

答案 0 :(得分:0)

在新版本的VS中,你应该使用&#34; Bulid Apk&#34;菜单选项生成产品apk :) enter image description here

答案 1 :(得分:0)

尝试禁用Instant Run。它找到了

运行转到文件 - &gt;设置 - &gt;构建,执行,部署 - &gt;即时运行 - &gt;取消选中即时运行的复选框

来自设备之前的uninstall之前的应用。