Stretch0
Stretch0

Reputation: 9251

How to start Android APK on device via ADB?

I have a simple android app .apk file create with Expo (react native) using the expo build:android script.

I am trying to run this on a device which is locked down by the provider so their is no access to Expo client. The only interface is via ADB.

I have successfully installed the app using the following command:

adb -s <device_id> install <package-name>.apk

I am then trying to start the app via the following:

adb shell am start -n host.exp.myapp

But I get the following error:

Exception: java.lang.IllegalArgumentException: Bad component name: host.exp.myapp

When I run adb shell cmd package list packages, I can see the package:host.exp.myapp listed and I am sure it's following naming conventions with lowercase and no special characters.

How can I start my app via ADB?

Upvotes: 1

Views: 1511

Answers (2)

Mritunjay Gupta
Mritunjay Gupta

Reputation: 411

Use the command

adb shell monkey -p com.package.name  -c android.intent.category.LAUNCHER 1
It starts the activity as if it was launched using the launcher. Replace com.package.name with desired package name in the command.

Upvotes: 1

Diego Torres Milano
Diego Torres Milano

Reputation: 69228

If you only know the package name and not the Activity you can use AndroidViewClient/culebra which resolves it.

For example, if you only knows the Chrome package name com.android.chrome you can run

#! /usr/bin/env python3

from com.dtmilano.android.viewclient import ViewClient


device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(package='com.android.chrome')

and it is resolved to the main Activity and then started.

If you want to do it from adb without using python you can take a look at the source here.

Upvotes: 0

Related Questions