New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can no longer connect to Android Emulator with Android SDK Tools 25.1.1 #150

Closed
garyjohnson opened this Issue Apr 7, 2016 · 23 comments

Comments

Projects
None yet
4 participants
@garyjohnson
Contributor

garyjohnson commented Apr 7, 2016

Just got appium up and running yesterday on an Android project. Updated the tools this morning (and nothing else), then noticed that appium started raising errors when attempting to talk to the android emulator.

Behavior: When appium driver is started, the configured AVD emulator will start, but then appium will fail to communicate with it and raise an exception. On a second run, it will fail to see the running emulator and start another instance, then fail again for the same issue.

Full appium log: https://gist.github.com/garyjohnson/7690fa79a1aeb1ee9f26cbb5082d8868

Details: appium-adb appears to fail specifically when running avd name over telnet connection. One thing I noticed is that it looks like there is loopback data on the telnet connection (i.e., you can see "avd name" returned in the telnet data along with the emulator name), but unsure if this is how it behaved previously:

[debug] [ADB] Sending telnet command to device: avd name
[debug] [ADB] Getting running emulator port
[debug] [ADB] Socket connection to device created
[debug] [ADB] Socket connection to device ready
[debug] [ADB] Telnet command got response: a�[K�[Dav�[K�[D�[Davd�[K�[D�[D�[Davd �[K�[D�[D�[D�[Davd n�[K�[D�[D�[D�[D�[Davd na�[K�[D�[D�[D�[D�[D�[Davd nam�[K�[D�[D�[D�[D�[D�[D�[Davd name�[K
Testing
[debug] [ADB] Emulator Testing not running

Running Appium 1.5.1, NPM 3.3.12, OSX El Capitan 10.11.4, Node 5.4.0, Android SDK Tools 25.1.1, Android SDK Build-Tools 23.0.2

@garyjohnson

This comment has been minimized.

Show comment
Hide comment
@garyjohnson

garyjohnson Apr 7, 2016

Contributor

Wanted to follow up on this -- I did a test of stripping the first line from the telnet response in lib/tools/adb-commands.js:

232         if (readyRegex.test(data)) {
233           res = dataStream.replace(readyRegex, "").trim();
234           var newlineIndex = res.indexOf("\n");
235           res = res.substr(newlineIndex + 1);
236           log.debug(`Telnet command got response: ${res}`);
237           conn.write("quit\n");

This did fix the issue and allow me to connect to AVD. I don't have enough context around this to know 1) if this will break some other telnet command routing through adb-commands, 2) how to handle this for people who have not upgraded, 3) why this happens in the first place.

Ideally this behavior could just be disabled somehow? Stripping the first line unconditionally is a total hack.

I'm going to try to roll back to a previous version of the SDK tools and verify that it starts working again, just to rule out the idea of some other environmental change causing this issue (and as a workaround).

Contributor

garyjohnson commented Apr 7, 2016

Wanted to follow up on this -- I did a test of stripping the first line from the telnet response in lib/tools/adb-commands.js:

232         if (readyRegex.test(data)) {
233           res = dataStream.replace(readyRegex, "").trim();
234           var newlineIndex = res.indexOf("\n");
235           res = res.substr(newlineIndex + 1);
236           log.debug(`Telnet command got response: ${res}`);
237           conn.write("quit\n");

This did fix the issue and allow me to connect to AVD. I don't have enough context around this to know 1) if this will break some other telnet command routing through adb-commands, 2) how to handle this for people who have not upgraded, 3) why this happens in the first place.

Ideally this behavior could just be disabled somehow? Stripping the first line unconditionally is a total hack.

I'm going to try to roll back to a previous version of the SDK tools and verify that it starts working again, just to rule out the idea of some other environmental change causing this issue (and as a workaround).

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie Apr 7, 2016

Member

Interesting. Thanks for the report!

The quick answer to (3) is that Android changes things at its own whim.

I will look into the other changes and try to find a way that supports old and new.

Member

imurchie commented Apr 7, 2016

Interesting. Thanks for the report!

The quick answer to (3) is that Android changes things at its own whim.

I will look into the other changes and try to find a way that supports old and new.

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie Apr 7, 2016

Member

I'm having a problem getting the latest SDK tools. Could you try something for me?

Replace the code in the connected block (where you made the change before) with:

res = dataStream.replace(readyRegex, "").trim();
res = _.last(res.split('\n'));
log.debug(`Telnet command got response: ${res}`);
conn.write("quit\n");

And then run your test. This supports the old way, and ought to do the same as you were doing for the new.

Member

imurchie commented Apr 7, 2016

I'm having a problem getting the latest SDK tools. Could you try something for me?

Replace the code in the connected block (where you made the change before) with:

res = dataStream.replace(readyRegex, "").trim();
res = _.last(res.split('\n'));
log.debug(`Telnet command got response: ${res}`);
conn.write("quit\n");

And then run your test. This supports the old way, and ought to do the same as you were doing for the new.

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie Apr 8, 2016

Member

Sorry, the added line needs to be res = _.last(res.trim().split('\n')); in order to not fail if there is a newline at the end.

Member

imurchie commented Apr 8, 2016

Sorry, the added line needs to be res = _.last(res.trim().split('\n')); in order to not fail if there is a newline at the end.

@garyjohnson

This comment has been minimized.

Show comment
Hide comment
@garyjohnson

garyjohnson Apr 8, 2016

Contributor

Appears to work well (testing by directly calling getRunningAVD). I'll patch it in locally and make sure it's working okay in my project.

Contributor

garyjohnson commented Apr 8, 2016

Appears to work well (testing by directly calling getRunningAVD). I'll patch it in locally and make sure it's working okay in my project.

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@dduphorn

dduphorn May 4, 2016

I'm running into the same issue. How can I get this fixed?

dduphorn commented May 4, 2016

I'm running into the same issue. How can I get this fixed?

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie May 4, 2016

Member

What version of appium are you running? It will only work on 1.5.2 or later.

Member

imurchie commented May 4, 2016

What version of appium are you running? It will only work on 1.5.2 or later.

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@dduphorn

dduphorn May 4, 2016

Thanks for getting back to me so quickly.

I’m on Version 1.5.2 (Ara)

Darin

On May 4, 2016, at 1:17 PM, Isaac A. Murchie <notifications@github.commailto:notifications@github.com> wrote:

What version of appium are you running? It will only work on 1.5.2 or later.


You are receiving this because you commented.
Reply to this email directly or view it on GitHubhttps://github.com/appium/appium-adb/issues/150#issuecomment-216954328

dduphorn commented May 4, 2016

Thanks for getting back to me so quickly.

I’m on Version 1.5.2 (Ara)

Darin

On May 4, 2016, at 1:17 PM, Isaac A. Murchie <notifications@github.commailto:notifications@github.com> wrote:

What version of appium are you running? It will only work on 1.5.2 or later.


You are receiving this because you commented.
Reply to this email directly or view it on GitHubhttps://github.com/appium/appium-adb/issues/150#issuecomment-216954328

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie May 4, 2016

Member

Can you provide a gist of the full Appium server logs, then?

Member

imurchie commented May 4, 2016

Can you provide a gist of the full Appium server logs, then?

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@dduphorn

dduphorn May 4, 2016

My bad, it actually did fix the issue when I used the Launch button from Appium. It failed when I start appium server programmatically. Using the below code.

public void startServer()
{
CommandLine command = new CommandLine("/Applications/ Appium.app/Contents/Resources/node/bin/node");
//OLD command.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js",false);
command.addArgument("/Users/darinduphorn/node_modules/appium/bin/appium.js",false);
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");
//command.addArgument("--full-reset", false);
//command.addArgument("--no-reset", true);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {executor.execute(command, resultHandler);Thread.sleep(5000);System.out.println("Appium server started.");}
catch (IOException e) {e.printStackTrace();}
catch (InterruptedException e)
{e.printStackTrace();}
}

dduphorn commented May 4, 2016

My bad, it actually did fix the issue when I used the Launch button from Appium. It failed when I start appium server programmatically. Using the below code.

public void startServer()
{
CommandLine command = new CommandLine("/Applications/ Appium.app/Contents/Resources/node/bin/node");
//OLD command.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js",false);
command.addArgument("/Users/darinduphorn/node_modules/appium/bin/appium.js",false);
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");
//command.addArgument("--full-reset", false);
//command.addArgument("--no-reset", true);
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {executor.execute(command, resultHandler);Thread.sleep(5000);System.out.println("Appium server started.");}
catch (IOException e) {e.printStackTrace();}
catch (InterruptedException e)
{e.printStackTrace();}
}

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie May 4, 2016

Member

That is an entirely different issue. Please file an issue with it (probably on the Java client).

Member

imurchie commented May 4, 2016

That is an entirely different issue. Please file an issue with it (probably on the Java client).

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@dduphorn

dduphorn May 4, 2016

Ok, I am getting the same telnet error: Telnet command got response: a�[K�[Dav�[K�[D�[Davd�[K�[D�[D�[Davd �[K�[D�[D�[D�[Davd n�[K�[D�[D�[D�[D�[Davd na�[K�[D�[D�[D�[D�[D�[Davd nam�[K�[D�[D�[D�[D�[D�[D�[Davd name�[K.. I guess I could include this thread in the issue.

dduphorn commented May 4, 2016

Ok, I am getting the same telnet error: Telnet command got response: a�[K�[Dav�[K�[D�[Davd�[K�[D�[D�[Davd �[K�[D�[D�[D�[Davd n�[K�[D�[D�[D�[D�[Davd na�[K�[D�[D�[D�[D�[D�[Davd nam�[K�[D�[D�[D�[D�[D�[D�[Davd name�[K.. I guess I could include this thread in the issue.

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie May 4, 2016

Member

We need the entire logs. As a gist.

Member

imurchie commented May 4, 2016

We need the entire logs. As a gist.

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie May 4, 2016

Member

Yes. But this is for version 1.4.16. There is no chance of it ever working. The fix is in 1.5.2.

Member

imurchie commented May 4, 2016

Yes. But this is for version 1.4.16. There is no chance of it ever working. The fix is in 1.5.2.

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@dduphorn

dduphorn May 4, 2016

Ah, I see what you are saying. I when I upgraded Appium it removed the below file.
/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js

I searched my machine for appium.js, and it found it here.
/Users/darinduphorn/node_modules/appium/bin/appium.js

Where that is probable the 1.4.16 version.

Any idea where appium would have put the new appium.js?

Thanks

dduphorn commented May 4, 2016

Ah, I see what you are saying. I when I upgraded Appium it removed the below file.
/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js

I searched my machine for appium.js, and it found it here.
/Users/darinduphorn/node_modules/appium/bin/appium.js

Where that is probable the 1.4.16 version.

Any idea where appium would have put the new appium.js?

Thanks

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie May 4, 2016

Member

It doesn't exist anymore. 1.5 runs from build/lib/main.js. You can download a beta of the app for 1.5.2 from https://bitbucket.org/appium/appium.app/downloads

Member

imurchie commented May 4, 2016

It doesn't exist anymore. 1.5 runs from build/lib/main.js. You can download a beta of the app for 1.5.2 from https://bitbucket.org/appium/appium.app/downloads

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@dduphorn

dduphorn May 4, 2016

Sorry for my confusion, but where is build/lib/main.js? Is that what I need to download?

When I open that link I don't see any thing call main.js.

dduphorn commented May 4, 2016

Sorry for my confusion, but where is build/lib/main.js? Is that what I need to download?

When I open that link I don't see any thing call main.js.

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie May 4, 2016

Member

You are running in the downloaded app, correct? With the GUI on Mac? The 1.5.2 version of the app will have it inside, no need to change anything.

Member

imurchie commented May 4, 2016

You are running in the downloaded app, correct? With the GUI on Mac? The 1.5.2 version of the app will have it inside, no need to change anything.

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@dduphorn

dduphorn May 4, 2016

I got it working when I run from the GUI on Mac. I'm trying to programmatically start the appium server. I've updated my Arguments to include build/lib/main.js.

CommandLine command = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
command.addArgument("build/lib/main.js",false);
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");

The error I get is:

module.js:341
throw err;
^

Error: Cannot find module '/Users/darinduphorn/git/TestAutomation/TestAutomation/build/lib/main.js'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
at node.js:404:3

So I'm wondering where build/lib/main.js is located so I can start Appium server programmatically.

Thanks

dduphorn commented May 4, 2016

I got it working when I run from the GUI on Mac. I'm trying to programmatically start the appium server. I've updated my Arguments to include build/lib/main.js.

CommandLine command = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
command.addArgument("build/lib/main.js",false);
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");

The error I get is:

module.js:341
throw err;
^

Error: Cannot find module '/Users/darinduphorn/git/TestAutomation/TestAutomation/build/lib/main.js'
at Function.Module._resolveFilename (module.js:339:15)
at Function.Module._load (module.js:290:25)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
at node.js:404:3

So I'm wondering where build/lib/main.js is located so I can start Appium server programmatically.

Thanks

@imurchie

This comment has been minimized.

Show comment
Hide comment
@imurchie

imurchie May 4, 2016

Member

If you don't care about the GUI, just install appium locally from npm.

In your current directory, run npm install appium and it should create a directory node_modules inside of which will be a directory appium. The runnable file is in there.

Member

imurchie commented May 4, 2016

If you don't care about the GUI, just install appium locally from npm.

In your current directory, run npm install appium and it should create a directory node_modules inside of which will be a directory appium. The runnable file is in there.

@dduphorn

This comment has been minimized.

Show comment
Hide comment
@dduphorn

dduphorn May 4, 2016

I got it to work. Thanks for your help.

CommandLine command = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
command.addArgument("/Users/darinduphorn/node_modules/appium/build/lib/main.js",false);
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");

dduphorn commented May 4, 2016

I got it to work. Thanks for your help.

CommandLine command = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
command.addArgument("/Users/darinduphorn/node_modules/appium/build/lib/main.js",false);
command.addArgument("--address", false);
command.addArgument("127.0.0.1");
command.addArgument("--port", false);
command.addArgument("4723");

@HarshavardhanShastry

This comment has been minimized.

Show comment
Hide comment
@HarshavardhanShastry

HarshavardhanShastry Oct 6, 2016

Getting the same error can any one help me out.Presently i have 1.4.13.1, but showing latest update to update is 1.4.16.1.how can i solve this. Stuck with not able to run the app itself. It's in windows machine.
screenshot 29

HarshavardhanShastry commented Oct 6, 2016

Getting the same error can any one help me out.Presently i have 1.4.13.1, but showing latest update to update is 1.4.16.1.how can i solve this. Stuck with not able to run the app itself. It's in windows machine.
screenshot 29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment