I am developing an Android app that uses Google Cloud Endpoints on Google App Engine (in Python) for its backend. The Android app authorizes the user using Google Play Services on the Android device, and it all works fantastically.
我正在开发一款Android应用程序,该应用程序使用Google App Engine上的Google Cloud Endpoints(在Python中)作为后端。 Android应用授权用户在Android设备上使用Google Play服务,这一切都非常有效。
However, now that I have actual users, I'd like to be able to test this all locally before deploying any app engine API changes to production, and I haven't figured out how to have the Android app talk to my local development server anywhere. The testing recommendations suggest that I just do some manual tinkering with API Explorer, but as I'm using the Endpoints Proto Datastore for my API, which makes the Android development easy, it also makes the API Explorer basically useless, since the calls I need to make are far more complicated than what I can generate by hand.
但是,既然我有实际用户,我希望能够在将任何应用引擎API更改部署到生产环境之前在本地进行全部测试,而且我还没想出如何让Android应用与我的本地开发服务器通信任何地方。测试建议表明我只是对API Explorer进行了一些手动修改,但由于我正在使用端点Proto数据存储区来实现我的API,这使得Android开发变得简单,它也使得API Explorer基本无用,因为我需要调用制作比我手工生成的要复杂得多。
One answer to this question suggests that there is a way to point the Android client at the local server, but while I can use the --host argument to have the dev_appserver's default server listen on something other than localhost, I can't seem to find a way to do the same for the API server. And even if I could do that, it might only be the first step to a full end-to-end local testing setup for my Android app.
这个问题的一个答案表明,有一种方法可以将Android客户端指向本地服务器,但是虽然我可以使用--host参数让dev_appserver的默认服务器侦听除localhost以外的其他东西,但我似乎无法找到一种方法为API服务器做同样的事情。即使我能做到这一点,它可能只是我的Android应用程序完整的端到端本地测试设置的第一步。
Can someone post more details on how I might do this, or short of that, please enlighten me on the best practices for testing Android apps that use Google Cloud Endpoints on App Engine? Thanks in advance for any answers.
有人可以发布更多有关我如何做到这一点的详细信息,或者说没有,请告诉我有关在App Engine上测试使用Google Cloud Endpoints的Android应用的最佳做法吗?提前感谢您的任何答案。
2 个解决方案
#1
2
In the local environment, the dev_appserver is the API server. If you've configured it so that it's accessible from machines other than localhost (i.e. another machine/device on the network) API requests should be accessible as well.
在本地环境中,dev_appserver是API服务器。如果您已将其配置为可从localhost以外的计算机(即网络上的其他计算机/设备)访问,则也应该可以访问API请求。
However, there's currently an issue with the local server and gzipped requests. Until that's fixed you'll need to disable gzipping within the client library in your Android app (see this post).
但是,当前服务器和gzip压缩请求存在问题。在修复之前,您需要在Android应用中的客户端库中禁用gzipping(请参阅此文章)。
#2
8
Alright, finally got it working, thanks for the tips, Dan! Here are the remaining details that would have saved me a few hours - hopefully this is helpful to someone else.
好吧,终于搞定了,感谢提示,丹!这些剩余的细节可以让我节省几个小时 - 希望这对其他人有帮助。
1) As I expected and mentioned earlier, dev_appserver.py needs to be run with --host=0.0.0.0 so that it can listen on the local network.
1)正如我之前所预期和前面提到的,dev_appserver.py需要使用--host = 0.0.0.0运行,以便它可以在本地网络上侦听。
2) In order to properly parse the ID token to make the user authentication work, you need to have the PyCrypto library installed - it is not installed by default, so just having it in your app.yaml isn't enough. I found the binaries for Windows here.
2)为了正确解析ID令牌以使用户身份验证工作,您需要安装PyCrypto库 - 默认情况下不安装它,所以只在app.yaml中使用它是不够的。我在这里找到了Windows的二进制文件。
3) Then, in my generated Tictactoe.java-equivalent class, I had to change the DEFAULT_ROOT_URL to be http://<my-local-machine>:8080/_ah/api/
(which is where my local machine is running), so that requests went to the local network. Alternatively (and perhaps less invasively), you can use builder.setRootUrl to the same address from wherever you initialize your builder. This way you don't muck with your generated classes.
3)然后,在我生成的Tictactoe.java等效类中,我必须将DEFAULT_ROOT_URL更改为http://
4) I also had to make the change Dan mentioned described here.
4)我还必须做出丹在这里描述的改变。
After doing those four things, everything seems to be working now and I can test my app locally - hooray!
完成这四件事之后,现在一切似乎都在运行,我可以在本地测试我的应用程序 - 万岁!
#1
2
In the local environment, the dev_appserver is the API server. If you've configured it so that it's accessible from machines other than localhost (i.e. another machine/device on the network) API requests should be accessible as well.
在本地环境中,dev_appserver是API服务器。如果您已将其配置为可从localhost以外的计算机(即网络上的其他计算机/设备)访问,则也应该可以访问API请求。
However, there's currently an issue with the local server and gzipped requests. Until that's fixed you'll need to disable gzipping within the client library in your Android app (see this post).
但是,当前服务器和gzip压缩请求存在问题。在修复之前,您需要在Android应用中的客户端库中禁用gzipping(请参阅此文章)。
#2
8
Alright, finally got it working, thanks for the tips, Dan! Here are the remaining details that would have saved me a few hours - hopefully this is helpful to someone else.
好吧,终于搞定了,感谢提示,丹!这些剩余的细节可以让我节省几个小时 - 希望这对其他人有帮助。
1) As I expected and mentioned earlier, dev_appserver.py needs to be run with --host=0.0.0.0 so that it can listen on the local network.
1)正如我之前所预期和前面提到的,dev_appserver.py需要使用--host = 0.0.0.0运行,以便它可以在本地网络上侦听。
2) In order to properly parse the ID token to make the user authentication work, you need to have the PyCrypto library installed - it is not installed by default, so just having it in your app.yaml isn't enough. I found the binaries for Windows here.
2)为了正确解析ID令牌以使用户身份验证工作,您需要安装PyCrypto库 - 默认情况下不安装它,所以只在app.yaml中使用它是不够的。我在这里找到了Windows的二进制文件。
3) Then, in my generated Tictactoe.java-equivalent class, I had to change the DEFAULT_ROOT_URL to be http://<my-local-machine>:8080/_ah/api/
(which is where my local machine is running), so that requests went to the local network. Alternatively (and perhaps less invasively), you can use builder.setRootUrl to the same address from wherever you initialize your builder. This way you don't muck with your generated classes.
3)然后,在我生成的Tictactoe.java等效类中,我必须将DEFAULT_ROOT_URL更改为http://
4) I also had to make the change Dan mentioned described here.
4)我还必须做出丹在这里描述的改变。
After doing those four things, everything seems to be working now and I can test my app locally - hooray!
完成这四件事之后,现在一切似乎都在运行,我可以在本地测试我的应用程序 - 万岁!