java - ParseServer i/o 失败的应用程序部署问题
问题描述
我在我的应用程序开发中达到了一个点,我想在实际设备(而不是模拟器)上对其进行测试。尽管该应用程序尚未完成,但它在模拟器上运行时可以正常运行。
所以我构建了一个 APK 来传输到我的设备并安装它。这一切都很顺利,但是,当我按下一个运行 ParseQuery 的按钮来构建一个数组,将它附加到一个 ListView 并显示在一个 AlertDialog 中时,我收到的所有内容(30-45 秒后)都是一个编程为声明“i/o 失败”的错误处理程序 - 这是从 ParseException 检索到的消息。
不确定有关 ParseServers 的 Internet 权限要求(它在没有 Internet 权限的情况下在模拟器中运行良好),我尝试将 Internet 权限添加到清单中并再次尝试......这产生了相同的结果。
我尝试过调试和发布版本,以及签名和未签名的 APK,结果都一样。除了我的手机不会安装的未签名版本之外。
我对此感到茫然,因为这是我第一次使用 ParseServer 测试应用程序,所以我问你们这些好人是否可以提供任何帮助。
让我知道您是否需要查看任何特定的代码段,我会发布它们,但正如我所说,它在模拟器中运行良好,所以我只能假设这可能是我构建 apk 的方式或在在 AWS 上部署 ParseServer 实例。
哦..我已经选择不使用这个应用程序的任何类型的用户身份验证,所以我不以任何方式访问用户类并且启用了自动用户。
请求的代码@Davi Macêdo-我不确定您请求的初始化的哪一部分,所以我将添加我认为涉及为此应用程序设置 Parse 的所有区域-
.StarterApplication -
package com.app.letsplaydarts;
import android.app.Application;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseUser;
public class StarterApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Enable Local Datastore.
Parse.enableLocalDatastore(this);
// Add your initialization code here
Parse.initialize(new Parse.Configuration.Builder(getApplicationContext())
.applicationId("9da08bc83....62b73e6ea")
.clientKey("a04b8e7866a9....67fc3dbebfbd")
.server("http://ipaddress/parse/")
.build()
);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
defaultACL.setPublicWriteAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
服务器地址不是 AWS 提供的公共 DNS,它是在创建实例后通过 PuTTY 访问的 server.js 文件提供的引用唯一提供的公共 DNS 是用于访问 ParseServer 仪表板的公共 DNS
我正在使用 AWS 提供的 t2.micro 免费服务来托管 Bitnami ParseServer
相关项目 Gradle 部分 -
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
mavenCentral()
}
}
相关模块 Gradle 部分 -
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.parse.bolts:bolts-tasks:1.4.0'
implementation 'com.parse:parse-android:1.17.3'
}
PuTTY 控制台结果运行curl http://ip/parse/ -v
bitnami@ip-:~$ curl http://ip/parse/ -v
* Trying ip...
* TCP_NODELAY set
* Connected to ip (ip) port 80 (#0)
> GET /parse/ HTTP/1.1
> Host: ip
> User-Agent: curl/7.53.1
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Date: Tue, 12 Nov 2019 13:24:03 GMT
< Server: Apache
< X-Frame-Options: SAMEORIGIN
< X-Powered-By: Express
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
< Access-Control-Allow-Headers: X-Parse-Master-Key, X-Parse-REST-API-Key, X-Parse-Javascript-Key, X-Parse-Application-Id, X-Parse-Client-Version, X-Parse-Session-Token, X-Requested-With, X-Parse-Revocable-Session, Content-Type, Pragma, Cache-Control
< Access-Control-Expose-Headers: X-Parse-Job-Status-Id, X-Parse-Push-Status-Id
< Content-Length: 24
< Cache-Control: s-maxage=10
<
* Connection #0 to host ip left intact
{"error":"unauthorized"}bitnami@ip:~$
我已经设法从 ParseException 中检索到一些额外的信息,如下所示 -
.getMessage() returns "I/o failure"
.getCode() returns "100" - Listed as a 'client-only' error
// ConnectionFailed 100 The connection to the Parse servers failed.
.getCause() returns "java.net.UnknownServiceException: CLEARTEXT communication to [ipaddress] not permitted by network security policy"
在我看来,这可能是我的手机网络提供商的问题!?谁能证实这一点?
解决方案
在这种情况下,该.getCause()
功能已被证明是无价的。快速搜索给出的响应将我带到此页面- 解决方案 #2 对我有用,下面是一个快速概述 -
将文件“network_security_config.xml”添加到 res\xml\ 文件夹,其中包含 -
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">your domain or ip address</domain>
</domain-config>
</network-security-config>
然后将以下行添加到 AndroidManifest.xml -
android:networkSecurityConfig="@xml/network_security_config"
重建APK,瞧!
谢谢@Davi Macêdo 的意见,这一直是困扰我一段时间的问题。
值得注意的是,对于最终构建,解决方案 #1 可能更合适,因为它涉及创建安全证书和使用安全 https 协议,但由于仍在开发中,上述解决方案非常适合我的需求现在。
推荐阅读
- assembly - 用汇编语言删除文件的程序?
- java - 计算多行文本的字符数
- vue.js - Vuex 在开始时从 API 调用填充数据
- xamarin.forms - 使用回车键从条形码阅读器读取 Xamarin.Forms 条目给出空结果
- php - Laravel syncWithoutDetaching 额外字段
- c - CS50 pset4 滤镜“模糊
- angular - 未知错误:错误:没有为 src\main\ui\node_modules\uuid 找到有效的导出 main?
- php - FreeTDS + Doctrine 去除零小数
- express - 即使我调用 server.close(),Mocha 也不会退出
- html - 缺少有效的 YouTube API 密钥