我的应用程序开发已经达到了一个阶段,我想在实际设备(而不是模拟器)上测试它。尽管该应用程序尚未完成,但它在模拟器上运行时可以完美运行。
所以我构建了一个 APK 来传输到我的设备并安装它。然而,这一切都很顺利,当我按下一个运行 ParseQuery 的按钮来构建一个数组,将其附加到 ListView 并显示在 AlertDialog 中时,我收到的只是(30-45 秒后)一个被编程为错误处理程序指出“i/o failure” - 这是从 ParseException 检索到的消息。
不确定有关 ParseServers 的互联网权限要求(它在没有互联网许可的情况下在模拟器中运行良好),我尝试将互联网权限添加到 list 中并再次尝试......这产生了相同的结果。
我尝试过调试和发布版本,以及签名和未签名的 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提供的公共(public)DNS,它是引用 由创建实例后通过 PuTTY 访问的 server.js 文件提供 提供的唯一公共(public) 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()
函数已被证明是无价的。快速搜索了该回复,我找到了 this page - 解决方案 #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 协议(protocol),但由于该解决方案仍在开发中,因此上面的解决方案适合我目前需要完美。
关于java - ParseServer I/O 失败导致应用程序部署问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58713456/