I'm developing apps for Android Wear and Android Phone devices. Both apps are in a common project in Android Studio. In fact this application uses three wear devices that work together with a single phone. So when I recompile for app testing, I need to build and install the apps on one phone AND three wear devices every time. Is there a way to automatically build and install to all four of these devices with one command? I imagine that a script could be run from the terminal in Android Studio, but I'm not sure where to start. Thanks.
Following the recommendations above from cricket_007, I started digging around Android Studio to see if it would report the commands for installation. I found the commands, put them in a shell script file and am now able to install the apk to four wear devices at once.
So first, in Android Studio, I go to: Build | Build APK. The generates the wear apk file. Then I execute a shell script with the following commands:
echo "Installing 422E..."
adb -s G6NZCJ00401422E push /Users/fred/abcdec/apps/myWearApp/wear/build/outputs/apk/wear-debug.apk /data/local/tmp/com.xyz.myWearApp
adb -s G6NZCJ00401422E shell pm install -r "/data/local/tmp/com.xyz.myWearApp"
echo "Starting 422E..."
adb -s G6NZCJ00401422E shell am start -n "com.xyz.myWearApp/com.xyz.myWearApp.MainWearActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo "Installing 6227..."
adb -s G6NZCJ004076227 push /Users/fred/abcdec/apps/myWearApp/wear/build/outputs/apk/wear-debug.apk /data/local/tmp/com.xyz.myWearApp
adb -s G6NZCJ004076227 shell pm install -r "/data/local/tmp/com.xyz.myWearApp"
echo "Starting 6227..."
adb -s G6NZCJ004076227 shell am start -n "com.xyz.myWearApp/com.xyz.myWearApp.MainWearActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo "Installing 922a..."
adb -s G5NZCJ02746922A push /Users/fred/abcdec/apps/myWearApp/wear/build/outputs/apk/wear-debug.apk /data/local/tmp/com.xyz.myWearApp
adb -s G5NZCJ02746922A shell pm install -r "/data/local/tmp/com.xyz.myWearApp"
echo "Starting 922A..."
adb -s G5NZCJ02746922A shell am start -n "com.xyz.myWearApp/com.xyz.myWearApp.MainWearActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo "Done."
echo "Installing Moto…”
adb -s localhost:4444 push /Users/fred/abcdec/apps/myWearApp/wear/build/outputs/apk/wear-debug.apk /data/local/tmp/com.xyz.myWearApp
adb -s localhost:4444 shell pm install -r "/data/local/tmp/com.xyz.myWearApp"
echo "Starting Moto…”
adb -s localhost:4444 shell am start -n "com.xyz.myWearApp/com.xyz.myWearApp.MainWearActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
echo "Done."
Of course, this could be extended to install the mobile app as well. I'm sure that I can find the gradle command to actually compile the .apk file as part of the script. If I find that, I will also post it.
Related
I tried to use the following code, but reported to me "shell does not declare android.permission.REQUEST_INSTALL_PACKAGES"
adb shell am start -a android.intent.action.VIEW -t "application/vnd.android.package-archive" -d "file:///sdcard/Download/a.apk"
I am sad that for some reasons, adb install is not allowed, even if I run the following command, I still cannot install the application
adb shell settings put global verifier_verify_adb_installs 0
adb shell settings put global package_verifier_enable 0
log:Failure [INSTALL_FAILED_VERIFICATION_FAILURE: adb install not allowed!]
Android Studio, click Run, and the app could be installed and launched.
WM-C02WM0T3HTD8:mep_login_android zgong$ adb shell cmd package list packages | grep com.visa.mobileEnablement.loginFeatureDemo
package:com.visa.mobileEnablement.loginFeatureDemo
In Run section in Android Studio
11/19 11:51:07: Launching 'demoApp' on Google Pixel 3 XL.
Install successfully finished in 1 s 290 ms.
$ adb shell am start -n "com.visa.mobileEnablement.loginFeatureDemo/com.visa.mobileEnablement.loginFeatureDemo.DemoActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 27798 on device 'google-pixel_3_xl-8BBY0WYAG'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
Using the same apk built from Run, and use adb install
WM-C02WM0T3HTD8:mep_login_android zgong$ adb install -t demoApp/build/outputs/apk/classic/debug/demoApp-classic-debug.apk
Performing Streamed Install
Success
However, the app is not in the package list.
WM-C02WM0T3HTD8:mep_login_android zgong$ adb shell cmd package list packages | grep com.visa.mobileEnablement.loginFeatureDemo
What is the difference between adb install and Android Studio installation process?
In Android Studio, i want run my app in my device but i have an error message:
$ adb shell pm install -r "/data/local/tmp/my.model" /system/bin/sh:
pm: can't execute: Permission denied
(It launch perfectly in emulator with 0 error.)
I have a Samsung S3 Mini rooted phone. My phone is visible with command adb devices.
I have try: run Android Studio in administrator, add ADB path on environment variable, Remove build folder and rebuild project, but i have always this error.
I guess that's why it does not start my Activity.
$ adb push C:\Users\me\AndroidStudioProjects\Model\app\build\outputs\apk\app-debug.apk
/data/local/tmp/my.model
$ adb shell pm install -r "/data/local/tmp/my.model"
/system/bin/sh: pm: can't execute: Permission denied
$ adb shell am start -n "my.model/my.model.MainActivity" -a
android.intent.action.MAIN -c android.intent.category.LAUNCHER
Error while executing: am start -n "my.model/my.model.MainActivity"
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER] cmp=my.model/.MainActivity }
Error type 3
Error: Activity class {my.model/my.model.MainActivity} does not
exist.
Error while Launching activity
Where is the issue? Thank you.
I have found why it not working. Because pm manager is disabled.
For resolve this issue:
Connect your phone to the pc
Open a command line and write adb shell and press enter
Write su and press enter
Now write chmod 777 /system/bin/pm
Enjoy!
You do this using adb
adb root (root access)
adb shell (Enter as root)
mount -o rw,remount / (for permission write access)
rm system/app -r Instagram (remove folder)
rm system/app -r Instagram/instagram.apk (remove apk)
I am trying to use adb to launch activites for testing,But it does not work for the debug version :
This works
adb shell am start -n com.xx.xx/.main.ParentActivity
This doesn't
adb shell am start -n com.xx.xx.debug/.main.ParentActivity
Both debug and release packages are available under /data/data
If you have class com.xx.xx.main.ParentActivity and your application id is com.xx.xx.debug then you have to specify FQCN like this:
adb shell am start -n com.xx.xx.debug/com.xx.xx.main.ParentActivity
Dot just after slash is shortcut which can be used only if FQCN starts with application id.
use adb shell am start -D -n com.xx.xx.debug/.main.ParentActivity -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
then you will be able to attach your debugger (via your IDE) and the app will start (see https://blog.jetbrains.com/idea/2011/05/new-in-105-attach-debugger-to-a-running-android-process/)
I can use all adb features, but when i try to adb -r install /package.adb it just gives me:
"2858 KB/s (4116553 bytes in 1.406s)"
and thats it, nothing happens. When I do it on another computer it deploys application and restarts it. What can be wrong?
Try running this command after your install:
adb shell am start -a android.intent.action.MAIN -n your.package/.possibleSubfolder.MyMainActivity