error "activity class does not exist" when launching android app with adb shell am start

Watch out for applicationIdSuffix!!

When using applicationIdSuffix in build.gradle the suffix only applies to your application id, not to the actual package structure in the generated .apk, meaning that referencing your activity the short way (.MainActivity, instead of using its fully qualified name) will add the application id suffix to the path of the activity too and hence AS will fail to locate it. E.g.:

My application's package name is my.application.package, and I have this in my app module's build.gradle:

buildTypes {

    someBuildType {
        [...]
        applicationIdSuffix ".dev"
    }
}

When trying to execute, let's say `MainActivity (which is located in the root package) from the command line:

$ adb shell am start -n my.application.package.dev/.MainActivity

actually resolves to

$ adb shell am start -n my.application.package.dev/my.application.package.dev.MainActivity

But MainActivity is actually located in my.application.package.MainActivity, not in my.application.package.dev.MainActivity, because applicationIdSuffix changes only the application id, not the actual package structure, so it will fail to locate it.

Therefore, you should use the activity's fully qualified name:

$ adb shell am start -n my.application.package.dev/my.application.package.MainActivity

Managed to figure it out - I left a prompt open with adb logcat, then launched my app on the device - out of this corresponding log entry:

I/ActivityManager( 2115): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=air.com.client.AppName/.AppEntry} from pid 2453

I put together a new command line:

adb shell start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n air.com.client.AppName/.AppEntry

... which does exactly what I wanted. I'll be honest, I don't understand exactly why it works, but that's good enough for now.


At lease for me the issue was solved once I entered a full path to the main activity in the application manifest file.

Instead of:

<activity android:name=".MyMainActivity"/>

Use:

<activity android:name="com.fullPathToActivityPackage.MyMainActivity"/>

and then use the regular:

adb shell am start -n com.myAppPackage/com.fullPathToActivityPackage.MyMainActivity

Tags:

Android

Air

Adb