I have a monkeyrunner script that connects to an Android device and deploys an APK on it.
serial = '12345JKL'
device = MonkeyRunner.waitForConnection(deviceId=serial)
device.installPackage(path_to_apk)
This works flawlessly when I execute the script using the Windows command shell.
"C:\dev\android\tools\monkeyrunner.bat" "C:\dev\my_script.py" -psome_parameter
The problem is that I want to have my_script.py executed by a TeamCity (Enterprise 6.0.3) build configuration on the same PC: this fails.
Please find the stack trace here: http://pastebin.com/CjWy95c3
First I thought that TC was messing with the parameters of the script. But the command from the TC build log
[00:55:12]: Starting: "C:\dev\android\tools\monkeyrunner.bat" "C:\dev\my_script.py" -psome_parameter
in directory: C:\some_dir
was the same as in the command shell and accordingly the script could connect to the device and worked fine when I copied the command into a command shell while C:\some_dir was my current directory.
I was not able to reproduce this error outside of TC.
I want to emphasize that this all happens on the same PC (Win 7 x64). The script works when executed from the command shell but fails (always when trying to connect to a device) when triggered by the TC build configuration.
I can't think of a reason why this happens and would be very happy if somebody could point me in the right direction.
Many thanks in advance
Edit: As it turns out the problem isn't limited to MonkeyRunner.waitForConnection() but also occurs when calling MonkeyRunner.sleep(5). Stacktrace
Can it be that MonkeyRunner and TeamCity don't go along well with each other?
This is probably caused by a problem with your imports. The problem with your imports is likely because of the way that TeamCity calls MonkeyRunner. I would guess that it has to do with the current directory being messed up. Try using
import os
os.chdir("path")
to change your current directory at the top of your .py script. (Before you import monkeyrunner) I would try changing it to the directory with MonkeyRunner.
After a colleague and I have investigated the problem for three days, we could not find the source of this problem. But when we used another machine as the build agent, the issue was gone. We still don't know what caused this NullPointerException.
Related
Suddenly my "adb pull" command will stuck in the middle of the process.
I'm not sure what cause it, after install some application or driver.
Happens for Pull one files or multiple files.
Does anyone encounter the same issue before? thanks.
Example:
U:\batch>adb pull /sdcard/xxxlog/mobilelog .\xxxlog\
[ 94%] /sdcard/xxxlog/mobilelog/APLog_xxx/main_log_1__xxx: 87%
Here a screenshot from my console
for my specific answer, and provide a possible answer to who encounter similar problem.
after I reinstall the whole os, testing different adb version,
the issue still remains.
during testing adb version,
I found the issue will not happens if i use Local Disk...
where issue happens when using Network Drive..
So a possible solution, is don't use Network drive
I encountered similar problem on adb server (v 1.0.40) started on Windows 7 machine. When tried to pull files from device on other machine running Linux in same local network (I used: "adb -H pull ...") the adb was freezing occasionally.
The solution was to not use Windows for ADB server.
This problem was NOT visible, when adb server was running on Linux VM (Ubuntu 16.4/ VirtualBox). Hope that this helps.
BR,
Ziggy
Every time I encounter this, it ends up being a max path length issue. Open a shell on the device using adb and review the file names within the directories that you are pulling. If any have exceedingly long names, they will silently fail and adb will hang
The thing that really throws you for a loop is that it usually fails after giving a percentage complete which makes you think it's a faulty connection or some other issue.
I haven't found a good way to recursively list out file names in shell and test their name length prior to doing the pull in order to know that the issue is going to happen, but when I have the same issue and rename long files, it ends up working on the next attempt.
I encountered the same problem when trying to transfer a large amount of data from an Android phone to a Raspberry Pi 3B+, and the logcat output seemed to reveal that adb was silently failing due to an issue with USB buffer reads (unfortunately, I don't have the exact message with me).
After the initial failure, it was possible to get another few files individually by unplugging the phone, running adb kill-server and adb start-server, and plugging it back in between each one, but the only longer-term fix I could find was restarting the Raspberry Pi. This solution, however, is not permanent, and must be repeated occasionally.
I was not able to replicate this issue on Windows or on a traditional Ubuntu system.
I encountered this problem while copying files from My Ubuntu machine to my Pixel 7.
A workaround based on this bug report, is to run
adb shell exit
in another terminal whenever it gets stuck until all files are copied. You can also run
watch -n 30 adb shell exit
to run the command every 30 seconds so you don't have to keep watching the process. I hope this helps someone.
I understand that this question has been asked 1000 times but every answer I can find on Stackoverflow and other websites are all the same: Either (1) The user is using Genymotion, (2) the user is using HTC Sync in Windows.
I am doing neither. I am currently running in OS/X (10.11.6) and am using a Moto X (2nd gen) phone running Android 6.0.
Many times (not every time) when I run "adb logcat", I get
adb server is out of date. killing...
* daemon started successfully *
This is a problem because I am trying to run some automated tests using gradlew (since using "adb shell am instrument" doesn't produce the JUnit style report I need) and collect logs... but every time I start "adb logcat", something in gradlew (apparently) tries to startup adb, which then kills all running instances of adb.
Has anyone seen this problem without using Genymotion/HTCSync/Windows and knows a solution?
Thanks!
The root cause of the server is out of date issue is still the same regardless the OS and/or other software used - you have multiple copies of adb binary in your system. And the solution is also the same:
kill all running adb processes
make sure you have the only copy of adb (remove the duplicates)
update it to the latest version
reconfigure all your software packages to use that copy
Just check that every tool you use is using the same adb version. For example, delete all versions except the latest.
Please check all your environmental paths which ADB has.
Your system may have several ADB.exe files so that mismatches makes the issue.
I am new to Android development. I have been going through the tutorials.
I would like to know which is the right way to debug / log an application during its execution. I am guessing I should be able to execute my application directly on my android device and be able to view a log or so to catch runtime errors and logs?
How could I accomplish this ?
I am using this to install the application on my phone
adb install <path to apk>
p.s. I am sure this question might seem like something I should already know. But I could not figure it out :) Hence I am here :)
You can build on the command line with ant. See this guide.
& install it by using adb on the command line.
adb install MyApp.apk
path of apk with file extension
update
for getting logcat or crash report
do this way:
adb logcat
note: make sure only one device is connected to adb bridge
for filtering:
check this & this.
In the Android gradle plugin there are options for aapt and dex but I can't find where I can pass parameters to the adb used by tasks such as install and connectedCheck (and any other that would use adb to complete).
My problem is that I want to pass the -H flag pointing to a remote adb. The use case is to run my tests on a remote machine (and then maybe, machineS). I believe this was possible with Android Maven plugin but I want to do it in Gradle now.
I have access to both machines and have tested that I can list and install a package using the -H flag but it seems like that android-gradle is hard coding 127.0.0.1.
If anyone has a working example of running the tests on different adb hosts could you please share it here?
I ran into the same issue and found a working solution by setting the environment variable ANDROID_ADB_SERVER_ADDRESS. I discovered it by digging through the adb source code.
You can see it also checks for ANDROID_ADB_SERVER_PORT and ANDROID_SERIAL if you need to change either of those too.
I'm facing the same problem. This guy wrote a java app (linked in the third comment to the post) that forwards adb connections to a remote adb server. This might be a workaround?
My Phonegap app refuses to load onto my Android device (even the HellowWorld default app is refusing to load)
Everything was running just great until today.
Here's my console log:
***\>adb devices
List of devices attached
4c05609b device
***\>phonegap run --device -V android
[phonegap] detecting Android SDK environment...
[phonegap] using the local environment
[phonegap] compiling Android...
[phonegap] Generating config.xml from defaults for platform "android"
[phonegap] Compiling app on platform "android" via command "cmd" /c ***\platforms\android\cordova\build
[phonegap] Platform "android" compiled successfully.
[phonegap] successfully compiled Android app
[phonegap] installing app onto device
[phonegap] Generating config.xml from defaults for platform "android"
[phonegap] Running app on platform "android" via command "cmd" /c ***\platforms\android\cordova\run --device
It just sits there saying running... forever.
I have another terminal window open with adb logcat running and at some point (maybe 10-15 seconds into that last line getting printed) it stops logging. Termination of the process and subsequent calls to adb logcat result in more hanging (no logging at all)
So then I have to do a kill-server, start-server to break out of this endless hanging at which point the phonegap process terminates with:
[error] An error occurred while running the android project.
***\platforms\android\cordova\node_modules\q\q.js:126
throw e;
^
ERROR: Failed to launch application on device: ERROR: Failed to install apk to d
evice: Error executing "adb -s 4c05609b install -r "***\platforms\android\bin\Po
ached-debug-unaligned.apk"": protocol failure
I have tried::
deleting my .cordova folder in C:\Users\Name
running the adb install directly (without phonegap)
deploying to an emulator (same problem)
unplugging / replugging the device
rebooting all devices
toggling "developer mode" on the device and revoking USB debugging privileges
I am all out of ideas!
Would greatly appreciate any tips or leads.
ADB version 1.0.31
Galaxy S3 running Android v4.3
EDIT:
Deploying to an emulator claims to complete successfully, but the app never opens and does not appear in the app list inside the emulator. So I have no way of actually testing it on the emulator either.
Would really appreciate some assistance.
EDIT 2:
After some further tinkering I've discovered my issue can be more specifically described as ADB hangs (freezes) when I attempt to talk to my device. I've determined this because adb shell, adb install, and adb push all fail the same way as described above. No error, just finite waiting.
adb logcat, adb devices, and other read functions work perfectly fine until one of the aforementioned write functions hangs in which case I need to do a adb kill-server or TASKKILL to get adb logcat working again.
Not sure if this added information helps, but there you go. The last thing I haven't yet tried is to do a factory reset on my phone as suggested by this fellow. If I can't find a solution soon I will back up my data as best I can and attempt this...
Please save me before this becomes my last option!
In case this helps others I had a problem with similar symptoms. ADB install -r "apk path" would hang indefinitely.
I troubleshooted a myriad of things and identified that it was my USB cable length.
I have an USB extender cable as that I plug my devices into. The combined length of my device's cable and the USB extender cable caused this issue. Removing the extension cable fix the issue and eventually I replaced my USB extender cable with a shorter extension cable for the final solution.
The issues seems to resolve itself randomly. As others suggested, an arbitrary combination of ADB kill-server, restarting the device, and re-installing SDKs seems to alleviate the problem (even if only for a couple pushes).
I still have no idea what causes this hanging and, though superstitiously believe the arbitrary combination described above fixes it, am unsure how to permanently resolve it.
To future people reading this, until a solid explanation is given my only advice is to square away an hour or so to restart / rebuild your dev environment... and make sure you buy a durable stress ball.
Shot in the dark here, but some more things to try:
Are you on a work PC or something? Make sure you have USB write permissions. Also, try different USB ports and cables. You have the latest USB driver for your devices right?
Try updating the SDK tools. Or maybe something got corrupted and a re-install might do the trick.
You have free space on your devices right?
Unknown sources is checked on both devices?
What version of Android are you targeting?
Do try restart the device like other suggested. From my experience, kill the adb process, then run the cordova run command helps magically sometimes.
In my case adb seemed to hang, but in fact the data transfer from Mac to emulator was really slow:
$ adb push platforms/android/build/outputs/apk/android-debug.apk /data/local/tmp/
150 KB/s (15587200 bytes in 101.223s)
It's a lot faster on USB connected real device. Don't know why...
Had the same (original) issue (with cordova / testing on an old device) ie. hang during install.
Tried running adb install directly from cmd line ...
adb [-s <deviceID>] install <apk>
...and same issue so not cordova specific....
Opened android device monitor (ADM) ...
..sdk\tools>monitor
..and ran install from cmd line again and saw logcat message saying package was sdk 16 / device was 15...doh!
So went back to AndroidManifest.xml and changed android:minSdkVersion to 15 and all back to normal again - install worked fine.
( Issue arose because I had installed something else which had changed the minSdkVersion and then removed the something else and never reset the minSdkVersion )
So, possibly device sdk / android version is too low for your build. If not, a look at the ADM logcat output as you initiate the install from the command line might indicate what the issue is.
Unplugging and plugging device again usually helps.