无法在小米米4c上从Android Studio运行应用程序(想想设备可能是原因)

时间:2017-01-12 14:55:10

标签: android android-studio adb

我正在使用最新的android studio,启用了usb调试,AS识别的手机以及在模拟器上运行的代码,但是当我尝试运行应用程序时,它会因此错误而失败:

$ adb shell am start -n "com.example.ph.myapplication/com.example.ph.myapplication.OnlyTetstBBBAct" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "com.example.ph.myapplication/com.example.ph.myapplication.OnlyTetstBBBAct" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.ph.myapplication/.OnlyTetstBBBAct }
Error type 3
Error: Activity class {com.example.ph.myapplication/com.example.ph.myapplication.OnlyTetstBBBAct} does not exist.

Error while Launching activity

同时我可以在android监视器窗口中看到类似的内容(但我不确定它是100%相关的):

01-12 17:50:19.111 18352-18352/? E/appproc: ERROR: could not find class 'com.android.commands.pm.Pm'
01-12 17:50:19.111 18352-18352/? A/art: art/runtime/thread.cc:1143] No pending exception expected: java.lang.ClassNotFoundException: Didn't find class "com.android.commands.pm.Pm" on path: DexPathList[[zip file "/system/framework/pm.jar"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
01-12 17:50:19.111 18352-18352/? A/art: art/runtime/thread.cc:1143]   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
01-12 17:50:19.111 18352-18352/? A/art: art/runtime/thread.cc:1143]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:511)
01-12 17:50:19.111 18352-18352/? A/art: art/runtime/thread.cc:1143]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:469)
01-12 17:50:19.111 18352-18352/? A/art: art/runtime/thread.cc:1143] 
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289] Runtime aborting...
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289] Aborting thread:
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289] "main" prio=5 tid=1 Runnable
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   | group="" sCount=0 dsCount=0 obj=0x12c41100 self=0x55bed629b0
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   | sysTid=18352 nice=0 cgrp=default sched=0/0 handle=0x7fb6243e80
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   | state=R schedstat=( 347813798 1653280 115 ) utm=22 stm=12 core=1 HZ=100
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   | stack=0x7fddc23000-0x7fddc25000 stackSize=8MB
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   | held mutexes= "abort lock" "mutator lock"(shared held)
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   native: #00 pc 000039a4  /system/lib64/libbacktrace_libc++.so (_ZN9Backtrace6UnwindEmP8ucontext+28)
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   native: #01 pc 0000001c  ???
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   (no managed stack frames)
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289] Pending exception java.lang.ClassNotFoundException thrown by 'unknown throw location'
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289] java.lang.ClassNotFoundException: Didn't find class "com.android.commands.pm.Pm" on path: DexPathList[[zip file "/system/framework/pm.jar"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:511)
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289]   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:469)
01-12 17:50:19.231 18352-18352/? A/art: art/runtime/runtime.cc:289] Dumping all threads without appropriate locks held: thread list lock
...

对我来说这是一个非常烦人的问题,我正在尝试解决它已经很多时间,但我找到的唯一答案是安装不同的ROM,甚至没有解释为什么这样做,所以我是寻找更好的选择,对我来说理解为什么会发生这种情况非常重要。如果你能帮助我解决这个问题和/或解释那里发生了什么,那么我将是超级优秀的。

Upd1:我可以手动在设备上安装应用程序,它运行得很好,我甚至可以用AS调试它,但是如果我对代码进行任何更改然后重新运行应用程序,它仍然是旧版本的代码在设备上运行,直到我手动删除旧的apk /安装新的。

3 个答案:

答案 0 :(得分:1)

当我看到这个问题时,我看到$ adb shell开始......并且认为他正在输入,但不是,这是由AS自动生成并显示在日志中(我的坏)。


我(故意)通过添加" XXX"在它面前像这样:

adb shell am start -n "XXXcom.hotveryspicy.maskimage/info.androidhive.slidingmenu.SlidingMenuActivity"
  

开始:意图{   CMP = XXXcom.hotveryspicy.maskimage / info.androidhive.slidingmenu.SlidingMenuActivity   }

     
    

错误类型3错误:活动类     {XXXcom.hotveryspicy.maskimage / info.androidhive.slidingmenu.SlidingMenuActivity}     不存在。

  

这会产生与您相同的错误(如果您的活动路径错误,也会出现错误) 您是否 100%确定您的活动包名称和完整路径正确无误?
检查AndroidManifest.xml以获取OnlyTetstBBBAct活动和包名称的完整路径:

    package="com.example.ph.myapplication"
<activity android:name="com.example.ph.myapplication.OnlyTetstBBBAct" >

发布您的AndroidManifest.xml所以我们检查是否存在愚蠢的错误,并希望这不是很难解决的问题。
从apk获取您的包名:

aapt dump badging <path-to-apk> 

(例如C:\ Android \ sdk \ build-tools \ 25.0.0 \ aapt dump badging app-debug.apk)
一些有用的命令:

adb uninstall com.example.ph.myapplication
adb -d install C:\Android\MaskActivity\app\build\outputs\apk\app-debug.apk
adb install -r app-debug.apk //(re-install preserving data)
adb shell rm /data/local/tmp/*.apk
adb devices
adb shell pm list packages

要查看logcat:

adb logcat


打开一个监视器来查看logcat:

C:\Android\sdk\tools\monitor

答案 1 :(得分:0)

尝试将以下代码添加到build.gradle(app)

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
}

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

答案 2 :(得分:0)

所以,不幸的是,我无法在没有手机的情况下使其工作。但是今天我最终根据它,安装adbd insecure,在adbd insecure内我检查了所有选项,现在它们都按预期工作了。