How to install over existing Android app on device using adb? - android

During development, I use something like
$ adb -s 192.168.1.77:5555 uninstall com.myApp.app
$ adb -s 192.168.1.77:5555 install /path/to/android-debug.apk
to uninstall the existing app, then push and install the updated app to my device. However, this seems to erase my existing data associated with the app so that each time I run the updated app I need to input the new data again. However, simply running the install command gives:
[ 10%] /data/local/tmp/android-debug.apk
[100%] /data/local/tmp/android-debug.apk
pkg: /data/local/tmp/android-debug.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]
With iOS you can simply install your updated app over the existing app on the device.
What is the equivalent for Android preferably using adb?
Edit: This question is really similar to this one, but I think this should be kept because the way my question is phrased will help many people trying to find an answer that are coming from a different angle– the angle being of reinstalling/overwriting versus updating.

from adb --help
adb install [-lrtsdg] <file>
- push this package file to the device and install it
(-l: forward lock application)
(-r: replace existing application)
(-t: allow test packages)
(-s: install application on sdcard)
(-d: allow version code downgrade (debuggable packages only))
(-g: grant all runtime permissions)
Therefore you can just add -r option
$ adb -s 192.168.1.77:5555 install -r /path/to/android-debug.apk

Related

Install APK in Work Profile via ADB in Android

Let's say we have a Work Profile (Android For Work) enabled in Android device. Does anyone know how to install an APK via ADB in Work Profile rather than personal profile.
I have seen the ADB documentation and there's a way to get the User ID but using the same ID I am unable to install an APK.
To get ID : adb shell pm list users
Install command : adb install -r --user 12 app_name.apk
Error message :
Performing Streamed Install
adb: failed to install app-prodDebug.apk: Security exception: Shell does not have permission to access user 12
com.android.server.am.ActivityManagerService.handleIncomingUser:22541 android.app.ActivityManager.handleIncomingUser:3989 com.android.server.pm.PackageManagerShellCommand.translateUserId:2434
java.lang.SecurityException: Shell does not have permission to access user 12
com.android.server.am.ActivityManagerService.handleIncomingUser:22541 android.app.ActivityManager.handleIncomingUser:3989 com.android.server.pm.PackageManagerShellComma
Any way to get around this ? My use case here is to replace an App with debug option enabled so that I can troubleshoot any issue that is happening with that specific app which is installed in work profile.
adb push android.apk /data/local/tmp
adb shell pm install --user 12 /data/local/tmp/android.apk
Above solution from #jtmcodle works fine.
But to findout userid please use below command
adb shell dumpsys user
In my case above command gave following output
UserInfo{11:10100030} serialNo=11
So I ran below command to make it work
adb shell pm install --user 12 /data/local/tmp/android.apk
According Android Developer site, if you install an app via usb with adb command, it will be installed in both profiles:
Android Developer Site
If you manually install an app over a USB cable to a device which has a work profile, the app is installed on both the personal and the work profile. Once you have installed the app, you can test the app under the following conditions:
If the accepted answer (https://stackoverflow.com/a/59148545/1667216) doesn't work, then invoke the following command from your DPC before you run those 2 steps:
devicePolicyManager.clearUserRestriction(componentName,UserManager.DISALLOW_DEBUGGING_FEATURES
where 'componentName' is the ComponentName of the class that extends DeviceAdminReceiver.

Restrict Android Studio from installing in Work Profile [duplicate]

Android 4.2 on tablets added support for multiple users per device (similar to desktop OSes), each of which can install and remove apps independently. Currently, using adb install /path/to/app.apk installs the app globally; every user can see and launch it (as if every user installed the same app from the Play store for example).
Is there a way to adb install an app onto a device so that only one user can see it in the launcher menu?
adb install now supports --user USER_ID argument, so in order to install APK for a certain user, use:
adb install --user USER_ID PATH_TO_APK
In order to find out USER_ID, use adb shell pm list users.
See https://source.android.com/devices/tech/admin/multi-user-testing for details.
pm enable [--user USER_ID] PACKAGE_OR_COMPONENT
pm disable [--user USER_ID] PACKAGE_OR_COMPONENT
pm enable --user 12 org.mozilla.firefox_beta
It may not have a per-user 'adb install', but it does have a per-user 'start' option when you want actual run the APK for testing. By default the documentation says 'start' will just start for the currently running user, but you can do
adb shell am start --user USER activity...
to start the APK as someone else. To get a list of users, run
adb shell pm list users
Here is the full documentation of the adb tool: http://developer.android.com/tools/help/adb.html
adb install doesn't provide any way to specify the target users.
I stumbled across this post when I was having issues installing a React Native app on a phone with a separate Work Profile on it. For some reason, it felt like it was randomly choosing which profile to install the app on.
Here's what I did to specify the user manually:
Build the app at least once:
npx react-native run-android
Uninstall if needed:
adb uninstall <your package name here>
Install the app manually. The APK path should be relative to the top level of your project:
adb install --user 0 ./android/app/build/outputs/apk/debug/app-debug.apk

Where does android studio save sqlite db on Linux dev machine?

I'd like to insert data directly into the sqlite database of my app but I cannot find it anywhere on android studio path, even on my root path:
$sudo find / -type f -name 'myapp.db'
I know several similar questions have been asked before but the answers for Windows did not help me on Ubuntu Linux. So appreciate your help.
Android Studio does not store the database locally in your computer. The databases only exist in the devices & every time you deploy to a new device, your database will be created new in that new device. That is why you can't find it in your computer. Here is where the database is located in the device:
/data/data/full_qualified_java_package_name/databases/database_name.db
Now if you would like to insert data directly, you can use the terminal in Android Studio & use ADB to pull the database off the emulator, modify it, and push it back in. Heck I am sure that if you know enough Linux you could probably insert what you need into it without pulling it from the device. Here are some sample commands for the Android Studio terminal for that:
~/Android/Sdk/platform-tools/adb devices
Get the device number, then:
~/Android/Sdk/platform-tools/adb -s emulator-#### pull /data/data/full_qualified_java_package_name/databases/database_name.db <local-filepath>
And to send it back in, it is just:
~/Android/Sdk/platform-tools/adb -s emulator-#### push <local-filepath> /data/data/full_qualified_java_package_name/databases/database_name.db
Example:
~/Android/Sdk/platform-tools/adb -s emulator-5554 pull /data/data/com.danielkaparunakis.stackoverflowquestions/databases/Questiondatabase.db /Users/DanielKaparunakis/Desktop
Additional tip: If you leave the blank when you pull like this:
~/Android/Sdk/platform-tools/adb -s emulator-5554 pull /data/data/com.danielkaparunakis.stackoverflowquestions/databases/Questiondatabase.db
It will automatically pull it to your project's root folder.
It will save it in the internal storage of every device, if you don't have a rooted device it will not allow you to pull it, but, if you are using an emulator you will be able to pull it.
https://developer.android.com/training/basics/data-storage/databases.html
You app's db is only on the device. You can pull it from any connected device – non-rooted physical devices as well. This script pulls it from the first device.
This trick is run-as <package name> which runs a shell the app's directory with full access to the app's data.
Replace $package with your app's package name and replace $db with the name of you app's db.
$ LC_ALL=C adb exec-out run-as $package cat databases/$db >db.sqlite
LC_ALL=C is to avoid some strange locale behavior on some systems.
adb is by default installed by Android Studio to ~/Android/Sdk/platform-tools/adb.
Update
The program 'adb' is currently not installed. To run 'adb' please ask your administrator to install the package 'android-tools-adb'
This is Ubuntu telling you that you can install it from the Ubuntu package manager.
Normally you would already have it as a part of Android Studio.
Update 2
I don't have a script yet for pushing it back since push and run-as don't work together. You would have to do something like this (untested).
$ adb push db.sqlite /sdcard/temp.sqlite
$ cat <<EOF | adb shell
run-as $package
cat /sdcard/temp.sqlite >databases/$db
exit
exit
EOF

adb uninstall failed

I am writing some sample apps.
After I debug these apps, I don't see an uninstall button in my device's application management.
When I do adb uninstall, it always says Failure without any reason.
In DDMS I saw that my apk is stored in /data/app/com.k2g.leaveDemo-1.apk.
I am not sure what am I missing.
I always have to reset my device to get rid of these apps :(
Do I need to do sign something?
Do I need to do something in debug mode?
Or does it depend on the version?
I am using Samsung S2.
I assume that you enable developer mode on your android device and you are connected to your device and you have shell access (adb shell).
Once this is done you can uninstall application with this command pm uninstall --user 0 <package.name>. Where 0 is ID of main user in Android system. This way you don't need to root your device.
Here is an example how I did on my Huawei p10 lite device.
# gain shell access
$ adb shell
# check who you are
$ whoami
shell
# obtain user id
$ id
uid=2000(shell) gid=2000(shell)
# list packages
$ pm list packages | grep google
package:com.google.android.youtube
package:com.google.android.ext.services
package:com.google.android.googlequicksearchbox
package:com.google.android.onetimeinitializer
package:com.google.android.ext.shared
package:com.google.android.apps.docs.editors.sheets
package:com.google.android.configupdater
package:com.google.android.marvin.talkback
package:com.google.android.apps.tachyon
package:com.google.android.instantapps.supervisor
package:com.google.android.setupwizard
package:com.google.android.music
package:com.google.android.apps.docs
package:com.google.android.apps.maps
package:com.google.android.webview
package:com.google.android.syncadapters.contacts
package:com.google.android.packageinstaller
package:com.google.android.gm
package:com.google.android.gms
package:com.google.android.gsf
package:com.google.android.tts
package:com.google.android.partnersetup
package:com.google.android.videos
package:com.google.android.feedback
package:com.google.android.printservice.recommendation
package:com.google.android.apps.photos
package:com.google.android.syncadapters.calendar
package:com.google.android.gsf.login
package:com.google.android.backuptransport
package:com.google.android.inputmethod.latin
# uninstall google play services (warning: take backup first!)
pm uninstall --user 0 com.google.android.gms
Yes, mobile device management would bring its own problems, but i bet 'Failure' is a dos2unix problem. On my Linux machines, adb is appending a DOS newline which causes 'Failure' because uninstall thinks the CR character is part of the package name. Also remove '-1.apk' from the end of the package-1.apk filename.
adb root
adb shell
pm list packages
pm uninstall com.android.chrome
In my case, i have a phone that is in permanent 'Safe mode' so only apps under /system/app/ have a chance of running. So i install them to get the .apk files copied off, then uninstall in bulk and copy to /system/app/, wipe the /cache and reboot. Now i have more apps running even though in safe mdoe.
# adb root
# pm list packages -3 > /root/bulkuninstall.txt
# vi /root/bulkuninstall.txt and check ^M characters at end of each line.
If ^M, then must run dos2unix /root/bulkuninstall.txt.
Remove '-1.apk' using vi search and replace:
:%s/-1\.apk//g
Or sed...
# cp /data/app/* /storage/sdcard1/APKs/
# for f in `cat /root/bulkuninstall.txt`; do echo $f; pm uninstall $f; done;
#
# echo Now remount system and copy the APK files to /system/app/
# mount | grep system
# mount -o remount,rw /dev/block/(use block device from previous step) /system
# cp /storage/sdcard1/APKs/* /system/app/
# reboot
wipe cache
power on.
This is not an exact answer, but if you're looking to uninstall the app because you have an updated .apk to install, you can try this:
adb install -r yourapp.apk
The -r option tells adb to reinstall the app
If it is an Android internal app you may need to:
adb shell
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system
rm /system/app/your_app
rm /data/data/your_app
remove any entries in /data/system/packages.xml
remove any entries in /data/system/packages.list
edit AndroidManifest.xml and get rid of android:sharedUserId="android.uid.shared"
This is at your own risk;-|, try in emulator first...
Just run ADB and use the following command:
adb shell pm uninstall -k --user 0 <package name>
And you should get this return:
successful
okey I was in same situation I tried all of this without result.. and the last answer was close.. I got it doing the follow:
in order to get the right name of your package do the follow:
adb shell pm list packages | grep "name of your app here"
you should see the right name of your app.. so now this one just works:
adb uninstall com.your-real-app-name
finally the command run works again:
ionic run android
Seems like you have an app that contains a hidden Device Administrator like this one here: http://www.symantec.com/security_response/writeup.jsp?docid=2013-060411-4146-99
you can only uninstall such an app when you disable the device admin first. You can use https://play.google.com/store/apps/details?id=com.trendmicro.mtrt.hiddenDAcleaner to disable it or do it by your own by sending the intent to the app that invokes the receiver that will disable the device admin.
I find that adb shell pm uninstall <package> works consistently, where adb uninstall <package> does not.
Try disable "Instant run" from settings window
Open your application Manifest and check the application's package first.
After that, be sure that your device is set into debugger mode.
Check if ADB can interact with your device:
adb devices
If your device is listed, then run:
adb uninstall PACKAGE_WRITTEN_IN_MANIFEST
Maybe you're trying to uninstall an app that is a phone administrator.
To be able to uninstall it, go to Seetings > Security > Phone Administrators.
If the app is listed, uncheck it and confirm the operation.
After that, you should be able to uninstall it using the App settings area or adb.
You should have to manually delete apps. got to Setting-> Application Management -> Running application, tap on it and you can remove, stop apps from there.
This worked for me:
This is the directory where all the APKs are stored:
cd /system/app
List them:
ls
Choose one to remove.
pm install -r <app_to_remove>.apk
Example:
$ pm install -r Google-Play-services.apk
pkg: Google-Play-services.apk
Success
I noticed that I get failure if the application I'm trying to remove is running, so kill it first.
Also, I noticed you might have to run (on a rooted device):
$ su
# mount -o remount +rw /
In my case I often get this issue when I first complise a app in debug mode and later try to install the google signed app.
That is because both apps have the same package name but diffent signatures.
Since I upgraded to Android lollypop I sometimes even get this error if I uninstall the app via the settings\Apps.
If you have this problem check if the app is installed in a other User profile and uninstall it in all user accounts.
If you have problems uninstalling through adb, I can recommend the following tool:
https://github.com/patrickfav/uber-adb-tools
you can use wildcards and supports multiple devices, also has some better error handling than the vanilla ADB (but uses it in background of course). Will work on your platform.
Full disclaimer: I am the developer
Make sure you enter the full package name with application name:
com.domain.app
I had a instance of an emulator running and a device connected.
When I ran command `adb -d uninstall PACKAGE_NAME', I got an error 'DELETE_FAILED_INTERNAL_ERROR' but when I killed the Emulator instance, I got a 'success' in un-installation process.
It can be something as simple as typing the package name in the wrong case...
I had the same problem - turned out I was entering the package name in all lower case when the actual package name included upper case characters.
adb uninstall -k <packageName - eg. com.test.app>
( If you're explicitly uninstalling you probably don't want the -k which keeps the app data and cache directories around. )
You can follow below steps to uninstall the app from the device via command prompt.
execute the command : adb -s [devicename] uninstall -k [packagename].
this command will retain the data and cache in the device but will remove the app from the device.
To remove the data and cache also from the device along with the application execute the command below.
adb shell pm uninstall -k [packagename].
if it shows sucess your app is uninstalled successfully'
If You use Xiomi Device then You need to Login in MI Account.
After Successful Registration you can install and Uninstall via ADB.
You have the name of the apk and not the package name:
You should first know the package name. Fot this tape:
adb shell pm list packages
Once you have the package name (be carefull, package name is like com.intel.... and not package:com.intel...), tape:
adb shell pm uninstall -k "package_name"
and Bingo!
In my case this was happening because I was trying to uninstall the wrong APK. I didn't realize that my bundleId had appended .demo to the ID.
I had a failure when using adb shell uninstall com.package.app/
removed / (so adb shell uninstall com.package.app) and it works
Try disable "Instant run" from Preference!
It's working for me.

Is it possible to install APK file if more than one emulators/devices are connected [duplicate]

This question already has answers here:
How to use ADB Shell when Multiple Devices are connected? Fails with "error: more than one device and emulator"
(15 answers)
Closed 7 years ago.
I know how to install the apk file in to the emulator by command prompt and all that.
But i want to know is it possible to install same apk file in to multiple emulator by giving any specific name ?
Actually i have to test one apk file in to many device. and for that i have started many device. I know how to install it. if the all device are open then it will not get install. So is there any alternate to install that apk file by giving any specific device Emulator id or any name ???
Please help me if there is any idea for it. . .
Thanks.
Yes, you can install an apk on a particular device.
In command, type:
adb devices
// list of devices and its unique ID...
Then type:
adb -s "<deviceIDfromlist>" install "<path-to-apk>"
Step 1: Get the device Ids of all connected device
adb devices
Step 2: Install to a particular device you want to install
adb -s deviceId install path+apk
Example:
Step 1:
C:\Android\android-sdks\platform-tools>adb devices
List of devices attached emulator-5554 device 014FD87107021017
device
Step 2:
C:\Android\android-sdks\platform-tools>adb -s 014FD87107021017 install C:\Users\
user\Documents\appname.apk
Use the following scripts to install apk on multiple devices/emulators.
for SERIAL in $(adb devices | grep -v List | cut -f 1);
do adb -s $SERIAL install -r /path/to/product.apk;
done
Remove -r if you are not reinstalling the apk. Also you can replace "install -r /path/to/product.apk" to other adb commands like working on one single device.
It works for me on real devices but I believe it should also works for emulators.
It is possible to issue install command simultaneously on all connected devices.
The key is to launch adb in a separate process (&).
I came up with the following script to simultaneously fire-off installation on all of the connected devices of mine and finally launch installed application on each of them:
#!/bin/sh
function install_job {
adb -s ${x[0]} install -r PATH_TO_YOUR_APK
adb -s ${x[0]} shell am start -n "com.example.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
}
#iterate over devices IP-addresses or serial numbers and start a job
while read LINE
do
eval x=($LINE)
install_job ${x[0]} > /dev/null 2>&1 &
done <<< "`adb devices | cut -sf 1`"
echo "WATING FOR INSTALLATION PROCESSES TO COMPLETE"
wait
echo "DONE INSTALLING"
Note 1: the STDOUT and STDERR are suppressed. You won't see any "adb install" operation result. This may be improved, I guess, if you really have to
Note 2: you could also improve script by providing args instead of hardcoded path and activity names.
That way you:
Don't have to manually perform install on each device
Don't have to wait for one install to finish in order to execute another one (adb tasks are launched in parallel)
yes you can install your apk file in multiple emulator for that you have to give the name in command prompt here is the link for guidance
http://developer.android.com/guide/developing/tools/emulator.html
You can install on multiple devices at a time using USB debugging.
In Eclipse
Run--> Run Configurations --> choose your project (on left) -->Target --> Launch on All compatible devices.
The selected project will be installed on all the connected devices

Categories

Resources