Reputation: 12022
I am using Android Studio
and trying to access local host
from android device using google app engine
.I followed this link.Now what they have shown it is nicely working with genymotion
.Now when i tried with android device it didn't work.I read this post and give this in my run configuration, in VM Args as
--address=0.0.0.0
But when i tried to run the backend server it gives me some error.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --address=0.0.0.0
Now i have my SignUp
class where i am communicating with server.
public class SignUp_Endpoint_Communicator extends AsyncTask <Pair<Context, UserinfoModel>, Void, ResponseMessages> {
private Context maincontext;
private UserinfoModelApi userinfo_api;
private UserinfoModel userdata;
private manipulate_Signup ms;
@Override
protected ResponseMessages doInBackground(Pair<Context, UserinfoModel>... params) {
if(userinfo_api == null) { // Only do this once
UserinfoModelApi.Builder builder = new UserinfoModelApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
// options for running against local devappserver
// - 10.0.2.2 is localhost's IP address in Android emulator
// - turn off compression when running against local devappserver
//.setRootUrl("http://10.0.2.2:8080/_ah/api/")
.setRootUrl("http://0.0.0.0:8080/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
// end options for devappserver
userinfo_api = builder.build();
}
maincontext = params[0].first;
userdata = params[0].second;
try {
ResponseMessages response = new ResponseMessages();
response = userinfo_api.setUserInfo(userdata).execute();
return response;
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
}
protected void onPostExecute(ResponseMessages response){
ms = (manipulate_Signup) ((Activity) maincontext);
ms.setResponseMessage(response);
}
public interface manipulate_Signup{
public void setResponseMessage(ResponseMessages response);
}
}
Is there any other thing i have to change to work it for android device??
Upvotes: 1
Views: 3368
Reputation: 278
I got this working in Android Studio by doing the following:
Builder
, replace the default '10.0.2.2' IP address for the 'rootUrl' with your local IP address (mine is 192.168.1.222 below).E.g:
MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory(), null)
// options for running against local devappserver
// - 10.0.2.2 is localhost's IP address in Android emulator
// - 192.168.1.222 is my machine's IP address on my local network.
// - turn off compression when running against local devappserver
.setRootUrl("http://192.168.1.222:8080/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
Edit the Run Configuration for your Appengine backend module:
Re-run your Appengine module.
I went round the houses a bit trying to get this to work, so I hope it saves someone else some time. Google's docs on this don't seem to make this obvious.
Upvotes: 2
Reputation: 12022
I worked on it .In android studio
at first go to Run->Edit Configuration->backend->VM Args and then paste the code of where my local datatstore bin presents
-Ddatastore.backing_store=E:\datastore\local_db.bin
and the IP address
for android device is the ipaddress
of your wifi
.
Upvotes: 0
Reputation: 1620
You should be using 10.0.2.2 for localhost.. Maybe this link can help.. https://developer.android.com/tools/devices/emulator.html#networkaddresses
Upvotes: -1