无法与开发Google Cloud模块通话(Can't talk to dev Google Cloud module)

编程入门 行业动态 更新时间:2024-10-26 00:25:03
无法与开发Google Cloud模块通话(Can't talk to dev Google Cloud module)

我有一个Android Studio项目,其中包含Android应用程序和后端Google云端模块。 我遇到了开发后端的IP地址问题。 在Android文档的例子中,它说使用10.0.2.2 ,我试过了,我总是得到20秒的超时时间。 我也尝试使用我的开发机器的ip,这也会导致20秒的超时,即使它立即失败。 在之前的两种情况下,通过在浏览器中手动加载localhost:8080来验证服务器是否正在运行。

// Async task snippet protected Joke doInBackground(Void... voids) { if(mApiService == null) { // Only do this once 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 // - turn off compression when running against local devappserver .setRootUrl("http://10.0.2.2:8080/_ah/api/") .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() { @Override public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException { abstractGoogleClientRequest.setDisableGZipContent(true); } }); mApiService = builder.build(); } try { String text = mApiService.sayHi("Chris").execute().getData(); return new Joke(text); } catch (IOException e) { Log.d(TAG, "fetch: " + e.getLocalizedMessage()); return null; } }

有任何想法吗?

I have an Android Studio project that contains the android app and a backend Google Cloud Module. I am having problems with the IP address of the development backend. In the examples in the Android docs it says to use 10.0.2.2, which I have tried and I always get a 20sec timeout. I have also tried to use my development machine's ip, which also results in a reported 20sec timeout, even though it fails immediately. In both of the previous cases the server is verified to be running by manually loading localhost:8080 in the browser.

// Async task snippet protected Joke doInBackground(Void... voids) { if(mApiService == null) { // Only do this once 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 // - turn off compression when running against local devappserver .setRootUrl("http://10.0.2.2:8080/_ah/api/") .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() { @Override public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException { abstractGoogleClientRequest.setDisableGZipContent(true); } }); mApiService = builder.build(); } try { String text = mApiService.sayHi("Chris").execute().getData(); return new Joke(text); } catch (IOException e) { Log.d(TAG, "fetch: " + e.getLocalizedMessage()); return null; } }

Any ideas?

最满意答案

事实证明,我错过了关于在模拟器中运行的ip地址的文本片断,因为我正在usb连接的设备上测试它。 通过模拟器运行它工作得很好:)

It turns out that I missed the text snippet in regards to the ip address being for running within an emulator, where as I was testing it on a usb connected device. Running it via the emulator worked just fine :)

更多推荐

本文发布于:2023-08-06 01:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1442061.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   Cloud   Google   module   dev

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!