我正在尝试通过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中运行代码并且应用程序安装在设备中,之后如果我将尝试&# 34; adb shell am start "命令然后它工作正常,但如果我尝试通过" adb安装apk "那么这个命令不起作用。
答案 0 :(得分:1)
我偶然遇到过这种情况,但在将MultiDex添加到我的gradle后,一切都很顺利。
第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
请尝试这个技巧。
答案 1 :(得分:0)
英语不是我的母语;请原谅输入错误。
解决方案: 看看您的App项目文件AndroidMainfest.xml,查找包含此
的活动 <intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
在此范围内,请记住此活动名称属性。 使用此命令
adb shell am start -D -n com.mycompany.moba.lala/com.epicgames.ue4.SplashActivity
将com.epicgames.ue4.SplashActivity替换为以前的名称路径。