I am using an Appium service to automate a flutter application on Android. I was able to connect to my host’s ADB
and install Appium Settings
and the flutter application. But I was not able to connect to AndroidUiautomator2Driver
as shown in the logs below:
[ADB] Running '/usr/lib/android-sdk/platform-tools/adb -P 5037 -s RR8W802EFNN install -r -g /home/myuser/app-debug.apk'
[ADB] The installation of 'app-debug.apk' took 7979ms
[ADB] Install command stdout: Performing Streamed Install
[ADB] Success
[AndroidUiautomator2Driver@9de5 (9d152cd0)] Performing shallow cleanup of automation leftovers
[AndroidUiautomator2Driver@9de5 (9d152cd0)] No obsolete sessions have been detected (connect ECONNREFUSED 127.0.0.1:8200)
[ADB] Running '/usr/lib/android-sdk/platform-tools/adb -P 5037 -s RR8W802EFNN shell am force-stop io.appium.uiautomator2.server.test'
[AndroidUiautomator2Driver@9de5 (9d152cd0)] Starting UIAutomator2 server 5.12.16
[AndroidUiautomator2Driver@9de5 (9d152cd0)] Using UIAutomator2 server from '/home/myuser/.appium/node_modules/appium-flutter-driver/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v5.12.16.apk' and test from '/home/myuser/.appium/node_modules/appium-flutter-driver/node_modules/appium-uiautomator2-driver/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk'
[AndroidUiautomator2Driver@9de5 (9d152cd0)] Waiting up to 30000ms for UiAutomator2 to be online...
[ADB] Creating ADB subprocess with args: ["-P","5037","-s","RR8W802EFNN","shell","am","instrument","-w","-e","disableAnalytics","true","io.appium.uiautomator2.server.test/androidx.test.runner.AndroidJUnitRunner"]
[AndroidUiautomator2Driver@9de5 (9d152cd0)] Matched '/status' to command name 'getStatus'
[AndroidUiautomator2Driver@9de5 (9d152cd0)] Proxying [GET /status] to [GET http://127.0.0.1:8200/status] with no body
[AndroidUiautomator2Driver@9de5 (9d152cd0)] connect ECONNREFUSED 127.0.0.1:8200
[AndroidUiautomator2Driver@9de5 (9d152cd0)] Matched '/status' to command name 'getStatus'
[AndroidUiautomator2Driver@9de5 (9d152cd0)] Proxying [GET /status] to [GET http://127.0.0.1:8200/status] with no body
[AndroidUiautomator2Driver@9de5 (9d152cd0)] connect ECONNREFUSED 127.0.0.1:8200
And this is how I configure the environment in my Dockerfile
:
RUN apt-get update
&& yes | apt-get install -y maven
&& yes | apt-get install usbutils
&& apt install wget
&& yes | apt-get install android-sdk
&& yes | apt-get install android-tools-adb
&& apt clean
&& rm -rf /var/lib/apt/lists/*
ENV ANDROID_HOME "/usr/lib/android-sdk"
ENV ANDROID_SDK_ROOT $ANDROID_HOME
ENV PATH $PATH:$ANDROID_HOME/platforms:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools
ENV ANDROID_ADB_SERVER_ADDRESS "host.docker.internal"
RUN useradd -ms /bin/bash myuser
&& usermod -aG root myuser
USER myuser
SHELL ["/bin/bash", "--login", "-c"]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
&& source $HOME/.nvm/nvm.sh
&& nvm install v16.18.1
&& npm install -g appium@latest
&& appium driver install uiautomator2
&& appium driver install xcuitest
&& appium driver install --source=npm appium-flutter-driver
&& appium plugin install relaxed-caps
&& appium plugin install execute-driver
&& appium plugin install --source=npm appium-wait-plugin
And this is how my compose.yml
look like:
services:
service:
image: image
network_mode: host
hostname: localhost
volumes:
- /Users/.m2:/home/myuser/.m2
I even tried to curl to http://127.0.0.1:8200
on the container, and was Connection refused
. But when I curl from my laptop it works fine. I do not understand what am I doing wrong. Since the network_mode
is set to host
, the container should be able to connect to any localhost port no? How can I make this work?
2
Answers
The issue you are experiencing is probably a docker network issue.
Try updating your dockerfile :
And your docker compose :
Ensure your device is connected and visible in ADBm then build and run the docker compose to see if the issue is resolved
port and IP address for the
AndroidUiautomator2Driver
network_mode: host
, ensure that no firewall or securitygroup settings on your host or Docker daemon are blocking the
connection.
sure it is accessible on 0.0.0.0.
If this not solve your issue try to change the docker file
Update your Dockerfile
and docker-compose.yml
ANDROID_ADB_SERVER_ADDRESS
tohost.docker.internal
to ensurethe container can communicate with the host’s ADB server.