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

matt lohkamp picture matt lohkamp · Nov 27, 2013 · Viewed 13.9k times · Source

After adb install-ing my app, I can verify that it's there with adb shell pm list packages AppName:

package:air.com.client.AppName

So I know it's there, but when I try to launch it with adb shell am start -a android.intent.action.MAIN -n air.com.client/.AppName, I get this error:

Starting: Intent { cmp=air.com.client/.AppName}

Error type 3

Error: Activity class {air.com.client/air.com.client.AppName} does not exist.

If it matters, this is, as you may have noticed, an AIR app that's been packaged as an Android app. Any ideas? Did I miss something somewhere? When I use aapt dump xmltree I can see that my .apk includes an android.intent.action.MAIN entry in the intent-filter node, for what it's worth.

And finally, for sanity's sake, using the same command template I can launch the settings app with no problems:

adb shell am start -a android.intent.action.MAIN -n com.android.settings/.Settings

Answer

Juan José Melero Gómez picture Juan José Melero Gómez · Feb 8, 2018

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