Montag, 3. Oktober 2016

Enable Debug and LiveReload functionality in OracleJet Android application

Introduction

OracleJet YeoMan Generator: version 1.1
OracleJet: version 2.1.0

Debug and LiveReload (aka HotDeployment) are two very powerful functions. You should always try to make this possible in your development environment, no matter what framework you are using. Debug saves you a lot of time in finding bugs and LiveReload allows you to see your changes to the sourcecode after seconds instead of waiting for another redeployment, which can take minutes.

What is going on behind the scenes


To make this happen, there is a lot going on. But don't worry, all of this is already setup. The only thing you have to do is setup an Google Android Virtual Device, start the Virtual Device and run the following scripts.

To find out the name of your Virtual Device
$ adb devices

To start the process, that is pointed out in the picture above
$ grunt serve:dev --platform=android --destination=<NAME_OF_YOUR_AVD_DEVICE>

Here comes an explanation of the steps, shown in the picture
  1. Your source code is being build and moved to the hybrid folder, which contains the informatione needed to make cordova work
  2. A server is being started on your local machine with port 8000. It is important, that this server is running on port 8000. You can also check that this step has been working fine, by entering localhost:8000 in your browser. You should see something similar to the following picture.
  3. This server is probably pointing to the hybrid folder. But I didn't make research on that. The important thing is, that server is always synchrone with your source code.
  4. Next your app is being deployed to the Virtual Device. Again, you don't have to trigger any separate command to make this happen. All this is being done by using the "grunt serve" command.
  5. Here comes the interesting part.Your Virtual Android Device is always listening to http://10.0.2.2/8000 for changes. 





Known Issues

Failed to establish connection to ADB server

When starting the Google Android Virtual Device you get this error in the log.

Solution
  1. Go to AVD Manager
  2. Edit your AVD
  3. Uncheck 'Use Host GPU'option.
  4. Click Finish (Save).
  5. Then Start AVD again


ERR_EMPTY_RESPONSE

In my case, my local Google Cloud Endpoint server's Debug Port has been listening on port 8000. Check on your computer, if there are any other actions going on on this port.

Conclusion

It took me quite some hair to find out why this is working the way it is. Why is 10.0.2.2 pointing directly to the localhost of my development environmen although I never setup my development environment or anything else to make 10.0.2.2 my localhost.

The reason why this is working is because Google did setup their Android Virtual Device in a way, that 10.0.2.2 is always forwarding the request to the localhost of your development environment.

Here comes the big problem with this. If you want to use your own Android device or some other Virtual Machine, than this is not working, because they don't forward 10.0.2.2 to your localhost development environment. Genymotion, which is another famous Android Virtual Device software is using 10.0.3.2 as IP to forward to your localhost development environment. And if you would want to make this work from your real device, than you would have to take the IP of your development environment and point to that from device, instead of pointing to 10.0.2.2.

I did make some research and found out, that currently the 10.0.2.2 can't be changed and is a hardcoded value. This means, that currently you can only use the debug and liveReload functionality with the original Google Android Virtual Devices

Keine Kommentare:

Kommentar veröffentlichen