Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

HCP for android emulator #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RealHandy
Copy link
Contributor

I made this change to get HCP to work in the android emulator. I think it's safe, given that it doesn't do anything unless this is android and "localhost" is present in the ROOT_URL string, which means it has to be the emulator -- right? The idea was taken straight from code that runs elsewhere that deals with the 10.0.2.2 android issue.

Copy link
Collaborator

@filipenevola filipenevola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you for this PR.

Let me check if I understand the problem, you are saying that running in the Android emulator HCP is not working and then the app code is not getting new versions after changes? I always test on devices then I would be glad to understand the issue better.

@@ -191,7 +191,7 @@ public String getRootUrlString() {
JSONObject runtimeConfig = getRuntimeConfig();
if (runtimeConfig != null) {
try {
rootUrlString = runtimeConfig.getString("ROOT_URL");
rootUrlString = runtimeConfig.getString("ROOT_URL").replace("localhost","10.0.2.2");
Copy link
Collaborator

@filipenevola filipenevola Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions:
1 - Could you split this operation into two lines (not replacing directly after getString) to improve readability;
2 - Extract these string localhost and 10.0.2.2 for constants then we can have a readable name for both;
3 - I don't remember if we have the environment available in the Java part but it would be good to only apply this replace in development mode.

Copy link
Contributor Author

@RealHandy RealHandy Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, HCP doesn't work in Android emulator without this. That's the only purpose of it, is to make HCP work in Android emulator.

The proposed change is a straight steal from this existing meteor code, which is solving the same problem:

https://github.com/meteor/meteor/blob/3051150f2f5ae953f391802e73682fba613b3d46/packages/boilerplate-generator/template-web.cordova.js#L42-L50

I can split the lines for readability and extract the strings as constants, but I don't know what the test would be for whether it's dev or not. Is there a standard test for that? I'm pretty sure it already can only impact dev, because the server won't be localhost in production.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm ok, if Meteor is already doing the same I believe this is safe. Please just update your code to have constants and let's move this forward.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool -- I extracted the constants and split the line into two.

@RealHandy
Copy link
Contributor Author

This travis build is failing for a reason unrelated to the change. The change is in Android-only java code, but the build is failing because it can't find the iPhone 11 Pro Max.

@delki8
Copy link

delki8 commented May 6, 2020

Hello @RealHandy, we both took the same path to solve this problem. And as I haven't seen your PR before I end up opening the #93 issue to address this. In the end, I came to the conclusion that we don't have a real bug in Meteor but a lack of clearer documentation that points to --mobile-server as a mandatory parameter for HCP to work on android.

Additionally our .replace() solution has a problem, it doesn't work if real devices are being used to debug the app because 10.0.2.2 is a standard that points to the emulator's host machine (details). So to make it work on both emulator and real devices you should run your meteor app with meteor run android --mobile-server 10.0.2.2:3000 or meteor run android --mobile-server 192.168.1.4:3000 as I pointed in my last #93 comment.

That's why I believe this PR shouldn't be merged, but I encourage anyone to submit a PR to meteor docs and add this caveat. I might do this in the future but feel free to do it first.

@RealHandy
Copy link
Contributor Author

Hello @RealHandy, we both took the same path to solve this problem. And as I haven't seen your PR before I end up opening the #93 issue to address this. In the end, I came to the conclusion that we don't have a real bug in Meteor but a lack of clearer documentation that points to --mobile-server as a mandatory parameter for HCP to work on android.

Additionally our .replace() solution has a problem, it doesn't work if real devices are being used to debug the app because 10.0.2.2 is a standard that points to the emulator's host machine (details). So to make it work on both emulator and real devices you should run your meteor app with meteor run android --mobile-server 10.0.2.2:3000 or meteor run android --mobile-server 192.168.1.4:3000 as I pointed in my last #93 comment.

That's why I believe this PR shouldn't be merged, but I encourage anyone to submit a PR to meteor docs and add this caveat. I might do this in the future but feel free to do it first.

I'm not sure we're addressing the same issue. This PR is only to deal with debugging in emulator, because when debugging in emulator "localhost" means the machine running the emulator, not the emulator itself, so to debug the emulator, you have to declare 10.0.2.2 instead. You probably know all that. But this doesn't come into play at all when using a real device. It's strictly to debug on an emulator. It sounds like your issue has also to do with real devices in some way, which on the surface, sounds outside the bounds of this change. Maybe?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants