9

Im trying to run an application on my GS5 from android studio and Im getting this:

Waiting for device.
Target device: samsung-sm_g900v-f3af9744
Uploading file
local path: D:\Android\Projects\TestProject\build\outputs\apk\TestProject-debug.apk
remote path: /data/local/tmp/com.brian.testproject
Installing com.datascan.mobilescripts
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.brian.testproject"
Aborted

It seems to be copying the file to the device, I can see it in the /data/local/tmp directory. Its just failing at the "pm install" stage.

On the phone I turned on USB Debugging and authorized the computer. Here is what I get when I run ADB devices:

D:\Android\sdk\platform-tools>adb devices
List of devices attached
f3af9744        device

So that seems to be correct. Im not really sure what the problem is. Google search on the problem didnt give me any relevant results.

Does anyone know how to get more information beyond "Aborted"? Any help is appreciated, Thanks!

EDIT:

As suggested by @AlexP. I ran "adb logcat -d -s PackageManager:*", this was the result:

D:\Android\sdk\platform-tools>adb logcat -d -s PackageManager:*
--------- beginning of main
--------- beginning of system

Not much help, but I did decide to watch the logcat as the pm install was being run and I found this error entry:

Tag=appproc  |  Text= ERROR: Could not find class 'com.android.commands.pm.Pm'
Tag=art      |  Text= art.runtime/thread.cc:1105] No pending exeption expected: java.lang.ClassNotFoundException: Didn't find class "com.android.commands.pm.Pm" on path: DexPathList[[zip file "/system/framework/pm.jar"],nativeLibraryDirectories=]/vendor/lib, /system/lib]]

Followed by a whole slew of art error entries.

So it seems as though my phone is missing something, maybe?

Brian Tacker
  • 1,091
  • 2
  • 18
  • 37
  • 1
    Is the app already installed? If yes, did you try to uninstall it manually? – cygery May 27 '15 at 16:04
  • 1
    @cygery Its not installed, I was able to install it manually by transferring the apk to the sd card and installing it from the phone. I tried while the app was installed and got the same result. – Brian Tacker May 27 '15 at 16:20
  • 1
    check the logs right after the failure `adb logcat -d -s PackageManager:*` – Alex P. May 27 '15 at 19:28
  • 1
    @AlexP. Thank you for the suggestion, it lead to an interesting discovery, please see my edit. – Brian Tacker May 27 '15 at 20:14
  • 1
    Have you tried using 'adb install' to install the APK generated by Android Studio? – Rajiv Makhijani May 29 '15 at 15:57
  • 1
    @RajivMakhijani When I run that I still get the ClassNotFoundException in logcat and the app does not get intalled – Brian Tacker May 29 '15 at 16:03
  • 1
    there is obviously something wrong with your device. My guess is you don't have a stock build on your GS5 – Alex P. May 29 '15 at 17:51
  • 1
    @AlexP. My phone is rooted but the ROM is fully stock – Brian Tacker May 29 '15 at 18:25
  • 1
    Does the app install on other devices or emulators? Any chances you may share the apk for local testing? – ozbek May 31 '15 at 12:41
  • @ozbek Yes it works on other devices and emulators. Any idea what could be missing from my phone that would cause this? – Brian Tacker Jun 02 '15 at 14:47
  • 1
    try this cmd to check if the pm.jar exists. . If it exists, run to see if the 'pm' cmd is executable. – wrkwrk Jun 03 '15 at 02:41
  • @wrkwrk That file does exist, when i run adb shell pm, I get no output to the command console and I get the same logcat errors as above – Brian Tacker Jun 03 '15 at 14:13
  • My mistake. But the 'adb shell pm' should print the help info of the 'pm' cmd. 'pm' actually located in /system/bin/pm, run 'adb sehll "cat /system/bin/pm" ' you can see it executes the class in the pm.jar. Is the 'am' cmd working ? – wrkwrk Jun 03 '15 at 15:43
  • You could try installing a 3rd party apk via the "adb shell pm install " command.does that work? – Droidekas Jun 04 '15 at 09:00

4 Answers4

8

The reason that Android Studio fails on Galaxy S5 is because the adbd (ADB service on the phone not your PC), on rooted version of this phone does not run as root, which is a security measure. You can verify this by manually trying to execute the Android Studio apk and execute commands on the device and finding out that they are failing to execute, but retrying them using "su ..." and see that the app installs and starts on the device. There are three options to resolve this and unblock Android Studio:

Options:

  1. Flash a ROM that includes the modification - not desired as from my understanding you would like to stay on the stock image; also a good security measure not to have adbd running as root all the time. Older roms fall in this category as well, but then you are missing Stock Rom updates and security patches.
  2. Create a custom boot.img and flash it to your phone - this is basically a custom kernel and not desired for a similar reasons than above option 1.
  3. Restart adbd on your device with root privileges when doing app development - preferred and achievable fairly easy thru various methods including:

Preferred Solution:

a. Restart adbd with root privileges (insecure mode) by killing the service on the phone and using a terminal app or so to restart it using "su". After you are done with your app development, restart your phone and adbd will be back in secure mode, restoring the security measures.

b. Use Chainfire's ADB insecure app, which is free on XDA (download/link below) or pay for it on Google Play to support his work. You can toggle the mode in the app. In the app, you also have an option to auto re-enable the insecure mode on reboots.

References:

https://android.stackexchange.com/questions/5884/is-there-a-way-for-me-to-run-adb-shell-as-root-without-typing-in-su

http://forum.xda-developers.com/showthread.php?t=1687590 (includes free download link)

https://play.google.com/store/apps/details?id=eu.chainfire.adbd (for supporting Chainfire's work)

Community
  • 1
  • 1
YasharF
  • 633
  • 5
  • 10
5

Possible Solutions :

1. Check if your app had left any datas :

First if the app is already installed, then clean cache data and uninstall it Under "System Settings" then "Application Manager" https://i.stack.imgur.com/b3oys.jpg

Then

  • Force uninstall by running & adb shell pm uninstall com.brian.testproject
  • Check "/data/data/com.brian.testproject/" and delete it
  • Remove any entries of your package on /data/system/packages.xml
  • Remove any entries of your package on /data/system/packages.list
  • Also you could install SDMaiD and clean your device, especially with "CorpseFinder" and "AppCleaner"

2. Try to install the app manually and debug the result :

In your case you have an issue with pm over android studio... install it manually to have a more detailed message over command line

$ adb push D:\Android\..\TestProject-debug.apk /sdcard/myapp.apk
$ adb shell pm install /sdcard/myapp.apk

3. Check Android Studio and your app sources

Change the targeted api level :


  • Update your android studio if you don't have the last release
  • If your app use libraries, you have to recompile them.

4. Check System Settings :

  • Check BOOTCLASSPATH of your init.rc. BOOTCLASSPATH must include /system/framework/ext.jar and /system/framework/framework.jar and so on.

  • Check DEXPREOPT_BOOT_JARS of build/core/dex_preopt.mk. DEXPREOPT_BOOT_JARS must include ext and framework and so on.

  • The order of all items on BOOTCLASSPATH must be equal to the order of all items on DEXPREOPT_BOOT_JARS.


5. Try pm command directly on the device :

if pm command does not work try that command with a terminal directly on the phone to see if it's a connection issue between pc and phone

pm install /sdcard/myapp.apk

6. Reinstall your rom once again (just reinstall it) no need to erase.

intika
  • 8,448
  • 5
  • 36
  • 55
  • Thank you very much for this detailed answer. In regards to #4, Looks like BOOTCLASSPATH is actually in my init.environ.rc file. It does not contain pm.jar or am.jar. Should those be added? Also, I dont have a file called dex_preopt.mk. Im guessing that might also be a problem? – Brian Tacker Jun 03 '15 at 13:57
  • "/system/framework/pm.jar" is the package manager also if you miss that file it would explain why it's not working – intika Jun 03 '15 at 14:10
  • you can not just edit init.rc it's part of the kernel i believe, did you install a custom kernel ? this may be the problem. in you case reinstalling the stock rom+kernel seem to be the appropriate solution, otherwise if your phone is not bootlocked, you can try an other kernel – intika Jun 03 '15 at 14:12
  • I also tried your #5 suggestion about running pm install directly on the device and it worked, what could that mean? – Brian Tacker Jun 03 '15 at 14:17
  • if #5 work this mean that pm is not working on the remote device like your computer but pm is operational on your device so related to the connection between the the phone and the computer – intika Jun 03 '15 at 14:22
  • you could then try an other way to connect your phone, first try with an otherwire, then try with wifi adb, the feature should be available on developper settings – intika Jun 03 '15 at 14:23
  • Wifi ADB (it's the same as connecting your phone over usb, but it's over your wifi network) to use that feature, you have to enable it on developer menu, then on your computer run this 3 commands : 1 adb connect tcp 2 adb connect 192.168.PHONE.IP:5555 3 adb shell – intika Jun 03 '15 at 14:29
  • 1
    I ended up installing an older ROM (older kernel as well) and I am able to run the pm and am commands from adb now. Although it's not the ideal solution, I am awarding you with the bounty since your answer led to it. – Brian Tacker Jun 05 '15 at 04:23
  • Thanks i am glad that my answer helped you ;) – intika Jun 05 '15 at 04:24
  • 1
    I'm sorry, since your answer did not have the specific solution I added a separate answer. – Brian Tacker Jun 05 '15 at 04:34
  • Perfect i just up voted it, and edit it to avoid other user downvote – intika Jun 05 '15 at 04:39
  • What if app is installable from /sdcard/ via `adb shell pm install /sdcard/myapp.apk` but not from HDD via `adb pm install ~/myapp.apk`? I get `Aborted` with the latter. What does it mean? – Suncatcher Feb 08 '17 at 13:42
1

For anyone having this same issue, unfortunately the only solution that I could find was to downgrade my ROM version (to OA8). Once I did that, adb works perfectly. If anyone finds a better solution I'd be definitely like to know.

Brian Tacker
  • 1,091
  • 2
  • 18
  • 37
-1

Android Studio

step 1: Go to file--> invalidate and restart.

step 2: Clean and rebuild project.

step 3: go to project folder run

gradle clean

step 4: restart phone/Emulator.

Done !!!

Uzair
  • 1,529
  • 14
  • 17