Running Emulators on Different Device for React Native Applications - android

Since Xcode and Android studio consume a lot, I am having storage and processing capacity issues on my Mac, while developing React Native Applications.
My Question is that is there any way to run emulators (in my case android emulator) on another PC, while I am coding on Mac?
Thank you

I tried once the solution below, it might also work for you. And the source is in this repo.
If you want to write and compile an Android application on one machine and debug it remotely on the emulator launched on another follow the instructions below:
Preparation
First of all you need to install SSH server on your remote machine.
Ubuntu
You can use OpenSSH.
sudo apt install openssh-server
Windows
You can install OpenSSH on Windows following this link.
Connection
Now you must connect local machine to remote server using SSH tunnel.
The emulator listens on two TCP ports per instance: 5554 for the telnet interface and 5555 for control communication with tools like DDMS. So you could probably get away with only forwarding port 5555. Each subsequent emulator takes the next available even+odd port number tuple.
Note that you need to enter the ip address of emulator running on remote server instead of emulator-ip and also remote machine username and hostname instead of myuser and remote-server.
Ubuntu
On the local machine try:
ssh -NL 5554:emulator-ip:5554 -L 5555:emulator-ip:5555 myuser#remote-server
Windows
Follow this link instructions and add two source ports and destinations below:
Source port: 5554
Destination: emulator-ip:5554
Source port: 5555
Destination: emulator-ip:5555
then connect to remote server.
ADB
The emulator tries to notify a local adb server at startup; hence you need to restart adb in order for it to probe the local 5554+ ports.
adb kill-server; adb devices
adb devices shows a new emulator — emulator-5554 — and you can use it as if it is running on your local machine.
Running
Finally run:
react-native run-android
the app should be installed on emulator, but you may face an error:
error: more than one device/emulator
Could not run adb reverse: Command failed: path/to/sdk/adb -s emulator-5554 reverse tcp:8081 tcp:8081
you need to specify your debug host IP and port in app's Developer menu -> Dev settings -> Debug server host & port, that is your local machine ip address and 8081 for port.
Note that after APK installation you don't need to do any of these steps. You can just start the npm server: npm start in the project directory of your local machine, run the app on the emulator in remote machine and then reload.
if there was another error:
Exception in thread "Device List Monitor" java.lang.NullPointerException
try:
react-native run-android --deviceId

Related

Android Studio show the dialog "unable to create debug bridge : unable to start adb server: unable to obtain result of 'adb version'"

When I open Android Studio, it shows the dialog below, and my application can't run as debug mode.
Find the folder of sdk->platform-tool then run the command adb tcpip 5555.
This should result in the following:
Now restart Android Studio and reconnect the Android Monitor:
Stop adb from terminal by calling adb kill-server repeatedly to kill all running unstances of adb.
Disable adb integration at android Studio by unmarking “Enable ADB Integration” (from toolbar -> Tools -> Android -> Enable ADB Integration).
Enable ADB Integration again by marking “Enable ADB Integration”.
Finally run project, so adb will be started automatically and properly.
It looks like Android Studio 3.2 uses DNS to resolve "localhost" on OSX (that seems like a bad idea, Google), and in my case a bad DNS entry on the local DNS server broke things.
nmr2:notes nathan$ hostname
nmr2
nmr2:notes nathan$ host nmr2
nmr2.mycompany.co has address 192.168.0.31
nmr2:notes nathan$ host localhost
localhost.mycompany.co has address 192.168.0.85
nmr2:notes nathan$ sudo grep -rni 192.168.0.85 /etc
So, verify that localhost resolves to 127.0.0.1

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).

Connect obdsim to Torque(android app) Ubuntu

Am trying to connect odbsim through bluetooth with my Samsung S4. After successfully pairing my devices with ubuntu, my results connecting obdsim with phone is never happened.
Whenever I tried running the command obdsim -b it always throwing error:
SimPort name: Not yet connected
I tried connecting it with windows too, with the help of com0com serial port, but couldn't succeded. And in windows, obdsim -b results in invalid options.
Please help me to connect the simulator with android device.
Thanks,
Boopathy.
I had the same problem on Linux and I resolved it installing some libraries and recompiling OBDSim.
I will put here the whole process to make a guide for new users like me.
Download OBDSim:
wget http://icculus.org/obdgpslogger/downloads/obdgpslogger-0.16.tar.gz
Or get the most recent version from: http://icculus.org/obdgpslogger/
Install OBDSim:
tar -zxvf obdgpslogger-0.16.tar.gz
cd obdgpslogger-0.16
mkdir build
cd build
I have to install only these libraries, but in your case keep attention to warning messages of cmake and install all that it ask you to install:
sudo apt-get install libbluetooth-dev libfltk1.1-dev libfltk1.1 fltk1.1-doc fluid fftw3-dev libgps-dev libftdi-dev
cmake ..
make obdsim
cd ../bin/
Run OBDSim:
./obdsim -b -g gui_fltk
Now you have OBDSim running, but you need a channel to communicate it with your app. You need a serial port working as a bluetooth interface.
Creating the serial->bluetooth interface:
sudo rfcomm bind 0 00:00:00:00:00:00 1 # Change this MAC address, putting the MAC of your device
sudo sdptool add SP
You can discover the MAC address of your device by using hcitool:
hcitool scan
It only works when the bluetooth configuration "Visible to all nearby Bluetooth devices" is on in your device.
I have used almost the same method described here and here and it worked. It worked without using com0com.
Pair the android device with the computer.
In Torque app, go to Settings -> OBD2 Adaptor Settings -> Choose Bluetooth Device. Select
your Computer Name.
Set the incoming COM Port of bluetooth as COM#Number . Assume it
is COM10 (Use https://www.verizon.com/support/knowledge-base-20605/)
Use obdsimwindows-2011-06-11 build. Can be downloaded from
http://icculus.org/obdgpslogger/downloads/obdsimwindows-latest.zip
Run obdsim.exe -w COM10
Run the Torque app and see whether it connects automatically.
-g option is used to give a generator type. By default it is gui_fltk which is the GUI interface.

Can't access the Android Device from Remote machine within same lan

I am using selenium webdriver , android server for mobile browser automation.
Android device(where the android server is running ) is connected to the remote machine 10.0.0.158 and i want to access this machine from development machine 10.0.0.138 [ where i will run the webdriver code for device automation using eclipse),i want to mention one thing that in both of these machine android sdk is present.
In the Android driver reference site[ https://code.google.com/p/selenium/wiki/AndroidDriver ] they mention about the remote connection procedure by using socat but those commands are for linux os which is not working in windows , commands are given below
# Instal socat, one time setup
$sudo apt-get install socat
$socat TCP-LISTEN:8081,fork TCP:localhost:8080
Can any one tell me for windows what commands will be used .
At last i have solved this problem.
I am sharing the procedure hopefully it will helpfull for all
To access android device remotely in windows environment we need to do the following steps
1 In the remote machine (i.e the machine which is connected with the android device) first download socat-x.x.x.x.zip from http://blog.gentilkiwi.com/programmes/socat#englishversion
2 Now through command prompt go to that folder where you have downloaded the socat zip [ for me i have download it in E: drive socat folder ]
3 Now in the same command prompt give the command adb.devices [ i am assuming that platform-tools folder path is already set in the environment variable ]
to check weather Remote machine is detecting your desired device or not, if the machine detect the device correctly then it will show device id then the text device otherwise it will show device id then the text offline
4 If the device is detected properly in the remote machine then either star the android server in the device manually or give the command
adb -shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity
if more than one device is there the give the serial id of your device
adb -s <serialId> shell am start -a android.intent.action.MAIN -n org.openqa.selenium.android.app/.MainActivity
5 Once Android driver started in the device then give the command
adb forward tcp:8080 tcp:8080
6 then give the command
socat TCP-LISTEN:8081,fork TCP:localhost:8080
[ i have given 8081 but we can give 8082 or 8083 or any port which is not in use ]
so now everything is ready in the remote machine
to verify weather Android WebDriver server can be accessed from from any machine or network interface open the url http://remote machine ip:8081/wd/hub
in the firefox browser in any machine
if every thing is fine then then it will show a blank page in firefox browser
7 Now at the development machine [ i.e where code will be execute through eclipse ] just modify the below code
WebDriver driver = new AndroidDriver();
and change it to
WebDriver driver = new AndroidDriver("http://remote machine ip:8081/wd/hub/");
8 Now click on the run button in the eclipse , you will see the output in the android device which is connected in the remote machine.

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