adb shell 我开始给出 ClassNotFoundException

adb shell am start giving ClassNotFoundException

我正在尝试通过 adb 命令启动 apk,安装 apk 后不久,但我收到 ClassNotFoundException 并且应用程序崩溃。

我的日志:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sample.test.one/com.sample.test.one.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.sample.test.one.MainActivity" on path: DexPathList[[zip file "/data/app/com.sample.test.one-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sample.test.one-1/lib/arm, /system/lib, /vendor/lib]]
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2849)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
     at android.app.ActivityThread.-wrap14(ActivityThread.java)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:154)
     at android.app.ActivityThread.main(ActivityThread.java:6776)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
  Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sample.test.one.MainActivity" on path: DexPathList[[zip file "/data/app/com.sample.test.one-1/base.apk"],nativeLibraryDirectories=[/data/app/com.sample.test.one-1/lib/arm, /system/lib, /vendor/lib]]
     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:1086)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2839)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
     at android.app.ActivityThread.-wrap14(ActivityThread.java) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:154) 
     at android.app.ActivityThread.main(ActivityThread.java:6776) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1518) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408) 

流量:

adb install test.apk

adb shell am start -n com.sample.test.one/com.sample.test.one.MainActivity

or 

adb shell am start -a android.intent.action.Main -n com.sample.test.one/.MainActivity

我正在尝试 adb shell commands 但应用程序无法启动,但我观察到一种情况,如果我愿意 运行 Android Studio 中的代码和应用程​​序安装在设备,然后如果我尝试“adb shell am start”命令那么它工作正常但如果我尝试通过“adb install apk" 则此命令无效。

我曾经遇到过这种情况,但是在我的 gradle 中添加了 MultiDex 之后,一切都很好。

步骤 1

defaultConfig {
         minSdkVersion minVersion+
         targetSdkVersion targetVersion+

         multiDexEnabled true
     }

 dexOptions {
      incremental true
      javaMaxHeapSize "4g"
 }

步骤 2

添加gradle

compile 'com.android.support:multidex:1.0.0'

步骤 3 更改 gradle 属性

org.gradle.jvmargs=-Xmx4096m

请试试这个技巧。

English is not my native language; please excuse typing errors.

解决方法: 看看你的 App 项目文件 AndroidMainfest.xml ,寻找 activity 包含这个

        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

在此范围内,记住此 activity 名称 属性。 使用这个命令

adb shell am start -D -n com.mycompany.moba.lala/com.epicgames.ue4.SplashActivity 

将 com.epicgames.ue4.SplashActivity 替换为之前的名称路径。