Accessing a forwarded port from Android Emulator - android

I have a Vagrant box which runs a nodejs server with port 3000 which I have forwarded to my host with vagrant ssh -- -L 3000:localhost:3000. For some reason, using 10.0.2.2:3000 on the Android Emulator does not reach this server. Is there anything else that I have to do to access an already-forwarded ip and port from within an Android Emulator instance?
It does work from my host, but not within Android Emulator.
Thank you!

This turned out to be my application's issue. From nc in adb shell I can access the interface in question.

Related

Connect Android Device over Proxy Server via SSH and VNC

I try to use SSH on Android the first time, i had read a lot about it but i cant find much, only from Android to Computer. Maybe someone can help me here:)
I have coded an APK for my own Android Device wheres create an SSH Connection over my PHP Script using Proxy Server.
I use an Debian VPS as Proxy Server. With this IP, the Android creates an Proxy.
Now i use this Comment:
ssh -N -L 34836:127.0.0.1:34836 newgenerateduser#23.106.XXX.XX
Port is generated also random every time i create an new proxy over PHP Script.
I use now an Virtual Machine with Ubuntu and enter the Comment in my Terminal with the Passwort after asking.
I start my VNC Client and want get remote Control over my Android device using VNC or SSH with this IP and Port:
127.0.0.1:34836
I got this Message:
lxs#linux-virtual-machine:~$ ssh -N -L 34836:127.0.0.1:34836 newgenerateduser#23.106.XXX.XX
newgenerateduser#23.106.XXX.XX's password:
channel 2: open failed: connect failed: Connection refused
I also tried using localhost instead of IP.
There are special requirements for the Proxy Server? Or just Port blocking on it?
Thanks for your help!

Getting "error: closed" twice on "adb reverse"

I am trying to reverse-forward port through ADB, but it just returns cryptic error of error: closed. Normal forwarding works. Session snippet:
$ adb forward tcp:59778 tcp:59778
$ adb forward --list
015d2109ce0c1a0f tcp:59778 tcp:59778
$ adb forward --remove-all
$ adb forward --list
$ adb reverse --list
error: closed
error: closed
$ adb reverse tcp:59778 tcp:59778
error: closed
error: closed
I am connecting via USB to non-rooted Nexus 7 2012 Android 4.4.4 from Windows 7 Pro x64 on Boot Camp.
adb reverse was introduced in Android 5.0
Since adb reverse is not supported in Android versions lower than 5.0, you need to use an alternative method, for example connecting via Wi-Fi instead. If you are using React Native, Facebook has added official documentation to connect to the development server via Wi-Fi. Quoting the instructions for MacOS, but they also have them for Linux and Windows:
Method 2: Connect via Wi-Fi
You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.
You can find the IP address in System Preferences → Network.
Make sure your laptop and your phone are on the same Wi-Fi network.
Open your React Native app on your device.
You'll see a red screen with an error. This is OK. The following steps will fix that.
Open the in-app Developer menu.
Go to Dev Settings → Debug server host for device.
Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
Go back to the Developer menu and select Reload JS.
Follow these steps carefully.
Note: All commands need to run inside a project only.
Run this command first:
npm react-native start
Open another window in the same project and run:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
This will create index.android.bundle in the assets folder
Run:
npm react-native run-android
Now you can get apk in the build folder which will work fine.
adb reverse requires Android 5.0+. For devices previous to that, you'll need to use a workaround like so.
If you have busybox installed on your Android device (most Genymotion images do), you can emulate adb reverse using this incantation:
adb shell busybox nc -ll -p {guest port} -e busybox nc {host IP} {host port}
In this case, "guest" is the Android OS running in the emulator and "host" is the computer running the emulator.
cause of adb reverse isnt working on android prior 5 you could propably use adb forward with a service listening on android and tunneling other connections through this inbound connection. I am doing this mostly with ssh, but you would need an ssh server on android. you than can connect using ssh -R incommingreverseportonandroid:hostyouwanttoforwardto:portyouwanttoforwardto sshuseronandroid#localhost -p portyouhaveusedforadbforwaqrdtoaccessandroidssshserver
but i dont know how to enable an ssh server on android and maybe there is a better way cause ssh uses encryption which isnt needed over usb and using up cpu.
i am using this way with my server to share a service when i am forced behind a nat...
hope someone will find a way to bring this teoretical way into practical possibility
Just use 10.0.2.2 instead of localhost/127.0.0.1 for your hostname. It will directly try to connect to the port on the host machine (same affect as reverse).

Android 127.0.0.1 (loopback) connection: Works on WiFi, fails with 3G/4G

My application embeds a local http server that can be accessed through the loopback device at URL: http://127.0.0.1:8080/
It works fine with WiFi enabled, it also works fine with no external network (no WiFi, no 3G) but it fails when WiFi is disabled and 3G enabled.
Connecting through adb shell and executing "netcfg" I can see that the loopback device is always enabled:
shell#android:/ $ netcfg
...
lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00
...
Alos "ping 127.0.0.1" continues to work while switching on/off the WiFi or 3G.
Any idea?
UPDATE:
Adding to the puzzle. From my dev computer I forward the tcp port:
$ adb forward tcp:8080 tcp:8080
Then I try to connect from my PC using http://127.0.0.1:8080/. It works, but when it continues to fail when using a browser running on the android device.
UPDATE 2015-06-01:
When working on 3G I see on adb logcat lot of related errors similar to:
W/ContextImpl( 504): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendStickyBroadcast:1239 com.android.server.TelephonyRegistry$3.onReceive:818 android.app.LoadedApk$ReceiverDispatcher$Args.run:788 android.os.Handler.handleCallback:725 android.os.Handler.dispatchMessage:92
and
E/CellLocation( 8336): create GsmCellLocation
It doesn't make any sense to me to trigger Gsm activity to connect to the loopback device.
UPDATE 2015-06-01 (2):
I managed to install wget in
/data/data/com.XXXX.yyy/files/appFiles/bin
Then I connect through "adb shell" -> "run-as com.XXXX.yyy" and finally execute:
wget -O - "http://127.0.0.1:8080/"
I works properly so I can discard any weird security setup that disables loopback access on localhost, so I guess it has something to do with WebView/WebViewClient trying to wrongly use a 3G external proxy to access the loopback. Now I'm wondering whether it's possible to disable the proxy on WebView.
Finally it looks it was a problem with the WebView trying to access an external proxy even for the lookback interface. I fixed the issue following the solution proposed at: WebView android proxy

Android Webdriver - How can I use a different port on localhost for WebDriver Hub?

I am just getting started with Android Webdriver.
I have successfully setup my first tests and I am using an HTC One V to run them, after following all the steps mentioned here: https://code.google.com/p/selenium/wiki/AndroidDriver
However, on my local host, I am also running a Jenkins instance which is normally started on 8080, and I would like to keep Jenkins running on this port and change the port of the Android Webdriver server.
Is it possible to have the webdriver hub running on the local host on a port other than 8080?
Yes it is possible to use another port on the PC.
Try changing the value in the adb forward command to something like: adb forward tcp:8090 tcp:8080 which would mean the port on your PC to use would be 8090 in your scripts, etc. [Remember to start WebDriver running on the Android device first.]
You can easily test this connects OK by using a web browser to connect to http://localhost:8090/wd/hub/status/ the response will appear as a web page with something like {status:0}
Here are the details from adb:
adb forward <local> <remote> - forward socket connections
forward specs are one of:
tcp:<port>
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)

Debugging using a virtual machine like VMWare/VirtualBox?

I am developing an Android application but fed-up of performance of My emulator
I do have a Android PC version installed in both VM-ware and Virtual Box
Can I use it as emulator? If so, how? How can I connect ADB to a virtual machine running PC Android?
I saw in some forum to use this but my VMs android having no specific IP.
How to i connect it??
Solution:
I would highly recommend to use Android x86 coz it many many times faster than Android emulator with Android x86 4.2 you can install and use any application with this and use "Google play" synch with your account as you do it with tablet
Working with latest Android X86 4.2 Jelly Bean and Virtual Box
I have found Different ways to connect with Internet and adb
Step: 1 Selection of Adapters
CASE 1: Only Internet {NAT Adapter}
The easiest solution is just use NAT adapter that will directly connect you to internet if host is connected to internet but you won't get the adb connection with this setup
Here you will get Public ip so you can't connect to Host computer
Case 2: Only adb {Host Only Adapter}
The easiest solution is just use Host Only Adapter
Note: The default Host Only adapter may not work due to DHCP server settings either create new HostOnlyAdapter or run DHCP server for existing Adapter()
Case 3: For both adb and Internet {Bridge Adapter}
You will have to take care in this case.
If you are using LAN for internet connection you shall use Bridge Adapter with your Ethernet card it will give you local ip and Virtual Machine will connect to Internet using host machine
Alternatively if you are with Wifi just do the same by selecting the Wifi adapter
For other type of connection you shall go with the same way
Step: 2 Connection with adb
to check the ip Address just press Alt+F1 {for console Window} [To switch back to Graphics view press Alt+F7 ]
you will see the console window type netcfg
it will show the ip address
Now move on to you host run command prompt move to adb directory
type
adb connect {your ip address}
Example
adb connect 192.168.1.51
Note: if adb is not running or responding you can do following
adb kill-server
adb start-server
you can check devices connected to adb
adb devices
As per your edited question, if you want to connect it to ADB you need to check what the IP of the VM is: Assuming you use VMWare's player;
Hit ALT-F1 in the VM and use the ifconfig command to know the IP address given to your network device (usually eth0). You can then hit ALT-F7 to go back to the Android UI.
Then, in your host PC, execute the adb connect [ANDROID_X86_IP] to connect the SDK debugger to your Android x86 VM; for example: adb connect 192.168.1.100:5555.
You should then see the list of devices connected and then it will be enabled to use for debugging.
ADB is typically located on your computer in a subfolder to your user folder in: ~/Android/Sdk/platform-tools. It is recommended to add it to your path so you can access it using the terminal wherever. I personally use this in ~/.bash_profile:
#add Android platform-tools directory
PATH=~/android-sdks/platform-tools:$PATH
export PATH
In case ADB fails the first time, you can try adb kill-server ; adb start-server to reset ADB.
If you want to read further, check out the Android-x86 website. It also has a lot of disc images available for download.
This is not a direct answer to your question, but did you see tricks to increase performance of emulator (read Why is the Android emulator so slow? How can we speed up the Android emulator?)
a) Use Intel Atom x86 instead of ARM
b) Use hw.gpu.enabled
I would say this makes emulator quite comparable in performance to a real device.
Update 1
Generally speaking, the idea is to configure Android PC to use tcp/ip for adb connection. And you may need to play around with network settings on VMWare or VirtualBox.
Useful links (which try to accomplish what you want
No network connection - Android-x86 on VMWare Fusion
http://lkubaski.wordpress.com/2012/08/15/running-android-on-vmware-player-with-networking-enabled/
http://www.transdroid.org/2011/01/26/techpost-debugging-against-a-virtual-machine-android/
install android x86 on vmware
run android terminal write command "ifconfig eth0"
windows user make Environment C:\Users\user- name\AppData\Local\Android\sdk\platform-tools
"adb connect IP address of the VM":5555
now run app on vmware
To save some time:
http://aztcs.org/meeting_notes/winhardsig/Android-vm/Android-VMwarePlayer-Win.pdf
Good link to get started in VMWARE
Where in the case you installed in the following directory /opt/android-sdk-linux
Set path variables
export ANDROID_HOME=/opt/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
After performing path if you see the application from typing "android" in the console your path setting is good.
create a hello world application (get the sdk installed correctly here if you have questions)
Run the hello world app
Hit ALT-F1 in the VM and use the netcfg command to know the IP address given to your eth0 device. You can then hit ALT-F7 to go back to the Android UI. Then, in your host PC, execute the adb connect [ANDROID_X86_IP] to connect the SDK debugger to your Android x86 VM; for example: adb connect 192.168.1.100:5555. If problems bounce the service adb kill-server ; adb start-server
at console change directory to /android-sdks/platform-tools
then type
./adb connect 192.168.1.100
(note the 192.168.1.100 is what is required it defaults to port 5555)
I had to use the ./adb prefix and then I was configuring the VMWARE instance.
I feel allot less greasy avoiding XAML :-)

Categories

Resources