When I want to test an android application, I create a new AVD, start it in the emulator, wait for the emulator to finish booting, and then use ADB to install the application, and when I'm done delete the AVD. Are there any tools that automate all of those steps? I tried writing my own but I couldn't find a way to tell if the emulator was completely booted, as the Android SDK website says not to use "adb wait-for-device install file.apk".
You're right not to use wait-for-device. It does not wait for the package manager to be available, which is what you need. I'm not sure how eclipse does it but you can poll the emulator until the package manager is available using the command adb shell pm path android. The command should return 'package: something'. Check out this python script that uses the technique: www.netmite.com/android/mydroid/1.6/.../adb_interface.py. It's pretty big but if you search for the command above you'll find the relevant piece of the script.
Why do you want to delete the AVD every time?
If you are deleting it every time because the install command throws an error due to the app already existing on the AVD, you can do this: adb install -r file.apk. The -r part is used for reinstalling the app. Here is the full usage instructions for adb.
Are you deleting it to remove the application you are testing and revert to a 'clean' emulator? If so it's not necessary to delete the AVD every time. You can specify the -wipe-data option when starting the emulator. This effectively resets the AVD to how it was when you created it. Here is the emulator documentation.
Hopefully that helps simplify your script.
Related
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?
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:
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.
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.
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)
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"
http://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 :
Right click on your app dir + Open Module Settings + app + check sdk version + change target and minimum under "Flavor"
Sync gradle button
Rebuild project
https://www.youtube.com/watch?v=v4b7C6Q-9dI
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.
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.
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 !!!
I used ant to build my Eclipse project from the command line in a debug configuration. (Eclipse Luna and Android NDK-R10d is broken, so I can't use Eclipse any longer. Confer, Eclipse/ADT plugin cannot locate symbols for r10d NDK).
I then performed an install using adb:
<Project Directory>$ adb install bin/AndroidPrng-debug.apk
When I rummage for the program on the device in Apps, the program is not offered. When I attempt to search for it by name on the device (AndroidPrng and com.example.prng), I'm provided with useless web search results. When I go to Settings → Apps, the app is shown under the Downloaded tab (it shows the name as com.example.prng). It has the familiar Force Stop and Uninstall.
I have DDMS running and waiting to capture LogCat output from the program. But even though the app is on the device, I cannot figure out how to run it.
How do I run and debug the app when it does not show up under Apps?
Assuming that your app do have an Activity from where you can navigate into other parts of your app.
Try using below command:
$ adb shell am start -n com.example.yourpackagename/.YourMainActivity
or $ adb shell am start -n com.package.yourpackagename/com.example.yourpackagename.YourMainActivity
This am start command, is a command-line interface to the ActivityManager.
I'm working on an app that uses device admin. If I run the app on a device using eclipse, then make a minor change to the code, then run the app again, the app runs as you'd expect with the new change.
However, if the second time I run the app I use adb install I get:
Failure [INSTALL_FAILED_ALREADY_EXISTS]
If I try to uninstall then reinstall, the uninstall fails because the app is device admin. This has led me to wonder which adb commands eclipse executes when you select run. I've looked for some sort of "update" command but I couldn't find one. Anyone know?
You can use "adb install -r yourapp.apk" to install your system apk again.
If you want to run through command line, use
"adb shell am start -n acticityname_withpackage"
I have launched an emulator with a:
android avd
(although the android developers site said do it from platform-tools, i did it from tools because the android command was there ,and not in platform-tools). Anyway the AVD manager appeared and I started one, and it launched just fine.
Then I tried to send my app to the emulator so (following the android developers instructions) I do a:
adb install /newApp.apk
the command prompt jumps to the next line and just blinks.....when i check the emulator nothing has changed...where am i going wrong???
Once you have started the emulator try
adb devices
to check if you can see it
List of devices attached
emulator-5554 device
then you can proceed with the install
adb install <path-to>/newApp.apk
Something looks strange about that path. If the apk is in the same directory you are launching the command from then you don't need that '/'. If this is a linux machine it would be './' for the same directory unless your apk is all the way up on root but that would be bad :)
I am having a lot of trouble trying to get my computer to run an android app on my phone. My computer is running Ubuntu 11.10 and my phone is HTC Desire running 2.2. Here is the error I am getting in Console in Eclipse:
[2011-12-13 19:35:05 - InitialChoice2] Re-installation failed due to different application signatures.
[2011-12-13 19:35:05 - InitialChoice2] You must perform a full uninstall of the application. WARNING: This will remove the application data!
[2011-12-13 19:35:05 - InitialChoice2] Please execute 'adb uninstall com.android.taskreminder' in a shell.
[2011-12-13 19:35:05 - InitialChoice2] Launch canceled!
I have tried renaming the package but have just gotten the same error. My phone is also in HTC Sync mode and I have tried changing that around. I have tried to open the adb shell but to no avail. I am a bit confused how to use it in linux and when I navigate to the directory in Terminal that the adb is located in, I get another error that says it does not recognize adb command. I suppose I am not sure how to execute "adb uninstall com.android.taskreminder" properly. Any help is really appreciated.
try to uninstall it from your phone. go to "Settings" > "Applications" > "Manage Applications" Look for the application name. Select it. There should be an option to uninstall it.
if you want to use adb in a shell, try sudo adb....
Try uninstalling the application through the phone first. This error is usually when you have installed the application in two different ways, so it has a different development signature so cannot update or reinstall.