Pass adb options/parameters to android gradle tasks (install, connectedCheck, etc) - android

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?

Related

What files do I need to push so that my changes are reflected in AOSP:?

I am new to Android Open Source Project (AOSP) and trying to build my own version of Android OS. Currently, I am trying to learn to modify the codes of Android 10 and trying to find whether it works or not. To do that, I have firstly added a few codes in "LocationManager" class in the framework. I just added some Log code to output some message in the code like in the below:
Log.i(TAG,"Lets see");
After that, I have built the code using the following code:
. build/envsetup.sh
lunch sdk-eng aosp_x86-eng
make sdk
What should be my next step if I want to see whether my changes works or not in an Genymotion emulator device? I have been trying to understand some online sources but not understanding them totally. I have also been trying to use "adb sync" command and finding out the emulator not working. I have also pushed some files as well but no result. I would be glad if someone can direct me in the right path. Thanks in advance for your kind assistance. Have a good day.
Building the system image and then trying it out would be the ideal way, but here's a hacky approach: Replace xxx with the actual path intermediate.
adb root && adb remount
adb push out\target\product\xxx\system\framework\services.jar /system/framework/
adb push out\target\product\xxx\system\framework\services.jar.prof /system/framework
adb push out\target\product\xxx\system\framework\oat\arm64\services.art /system/framework/oat/arm64/
adb push out\target\product\xxx\system\framework\oat\arm64\services.odex /system/framework/oat/arm64/
adb push out\target\product\xxx\system\framework\oat\arm64\services.vdex /system/framework/oat/arm64/
adb reboot

How can I resolve "adb server is out of date" error

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.

Build Unity project with Jenkins failed

I'm trying to build Unity project with Jenkins on Mac OS Server.
But when I try to run the following script
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode ${PROJECT_PATH} -executeMethod BuildScript.DevelopmentBuild
The script shows this,
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
Does anyone knows how to fix the problem?
Try write from Terminal:
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
sudo mv /Library/LaunchDaemons/org.jenkins-ci.plist /Library/LaunchAgents/org.jenkins-ci.plist
Then log out and log in again.
Now Jenkins will run as agent and can access WindowServer.
Make sure you have -nographics parameter among your startup parameters
I tried
sudo launchctl unload /Library/LaunchDaemons/org.jenkins-ci.plist
sudo mv /Library/LaunchDaemons/org.jenkins-ci.plist /Library/LaunchAgents/org.jenkins-ci.plist
Then Restarted my Mac
And then sudo launchctl load /Library/LaunchAgents/org.jenkins-ci.plist after restarting
It worked
I had this same issue. The problem is with how Jenkins and Unity work individually.
The only way I could find a cleaner work around was:
Ideally have your Jenkins master only do assignments to slave and do not build anything by itself. So your slaves would build the project.
In case above is not easily doable here is a quick workaround:
On your Jenkins master create a slave.
Add a label to execute your Unity project on the newly created slave.
Configure the job to run on dedicated slave that you created above.
All works now!
You also get this error if the user you are running as is not currently logged in graphically.
It looks like you're missing the --projectPath option prior to specifying your project's path?

Why does MonkeyRunner fail when called using TeamCity

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.

What do you use the Android Terminal Emulator for?

Why is there a terminal emulator in the Android App Market?
So you can get direct access to the commandline?
Android is based on Linux, so it's essentially the Linux commandline you'd be accessing here
If you don't know the Linux commandline:
http://linuxcommand.org/learning_the_shell.php
Please note that it'll be a somewhat limited environment - you might need to root your phone to get access to everything, also some commands won't be available, you probably want to install something like Busybox to get a more featureful environment.
Cheers,
Victor
As above - it's for shell access, once you have root.
I've mainly just used it for browsing the file structure to get a better idea of where everything sits.
We use terminal emulator on Android for executing Linux core shells or other shells and program like that. It is a very useful app for Android developers.

Categories

Resources