Test App
Test App

Reputation: 43

adb shell am start giving ClassNotFoundException

I am trying to launch an apk through adb command, soon after installing the apk but i am getting ClassNotFoundException and app is crashing.

My Log :

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) 

Flow :

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

I am trying above adb shell commands but app is failing to launch but one scenario i have observed, if i will run the code in Android Studio and app gets installed in the device and after that if i will try "adb shell am start" command then it works fine but if i try through "adb install apk" then this command is not working.

Upvotes: 1

Views: 747

Answers (2)

jdir.s
jdir.s

Reputation: 131

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

Solution: take a look in your App project file AndroidMainfest.xml , look for the activity contain this

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

in this scope ,remember this activity name property. use this command

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

replace the com.epicgames.ue4.SplashActivity with the previous name path.

Upvotes: 0

Anshuman Pattnaik
Anshuman Pattnaik

Reputation: 933

I came across this situation once, but after adding MultiDex to my gradle , everything works great.

Step 1

defaultConfig {
         minSdkVersion minVersion+
         targetSdkVersion targetVersion+

         multiDexEnabled true
     }

 dexOptions {
      incremental true
      javaMaxHeapSize "4g"
 }

Step 2

add gradle

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

Step 3 Change gradle properties

org.gradle.jvmargs=-Xmx4096m

Please try this trick.

Upvotes: 1

Related Questions