我遇到了Android / IOs应用程序的问题:库代码(libgdx?)会抛出NPE,但不支持在RoboVM中进行调试。在Android中运行时,它按预期工作并重新使用handleHttpResponse()
方法。在IO中运行时,它会到达失败的(Throwable t)方法,其中t为NullPointerException
。我已经创建了一个示例应用来展示问题,也许这是我的错,所以这里是代码:
public class Npe extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
loadHttps("https://www.google.it");
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
private static void loadHttps(String url) {
HttpRequest httpGet = new HttpRequest(HttpMethods.GET);
httpGet.setUrl(url);
Gdx.net.sendHttpRequest(httpGet, new HttpResponseListener() {
@Override
public void handleHttpResponse(HttpResponse httpResponse) {
String res = httpResponse.getResultAsString();
System.err.println("res = \"" + res + "\"");
}
@Override
public void failed(Throwable t) {
System.err.println("On IOs we reach this point");
t.printStackTrace(); // and t is a NPE
}
@Override
public void cancelled()
{
}
});
}
}
和我的robovm.xml:
<config>
<executableName>${app.executable}</executableName>
<mainClass>${app.mainclass}</mainClass>
<os>ios</os>
<arch>thumbv7</arch>
<target>ios</target>
<iosInfoPList>Info.plist.xml</iosInfoPList>
<resources>
<resource>
<directory>../android/assets</directory>
<includes>
<include>**</include>
</includes>
<skipPngCrush>true</skipPngCrush>
</resource>
<resource>
<directory>data</directory>
</resource>
</resources>
<forceLinkClasses>
<pattern>org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl</pattern>
<pattern>com.android.org.conscrypt.JSSEProvider</pattern>
<pattern>com.android.org.conscrypt.OpenSSLProvider</pattern>
<pattern>com.android.org.conscrypt.OpenSSLSocketFactoryImpl</pattern>
<pattern>com.android.okhttp.HttpsHandler</pattern>
<pattern>com.badlogic.gdx.scenes.scene2d.ui.*</pattern>
<pattern>org.apache.harmony.xnet.provider.jsse.OpenSSLProvider</pattern>
<pattern>org.apache.harmony.security.provider.cert.DRLCertFactory</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.BouncyCastleProvider</pattern>
<pattern>org.apache.harmony.security.provider.crypto.CryptoProvider</pattern>
<pattern>org.apache.harmony.xnet.provider.jsse.JSSEProvider</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.JDKKeyStore</pattern>
<pattern>org.apache.harmony.security.provider.cert.X509CertFactoryImpl</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi</pattern>
<pattern>org.apache.harmony.xnet.provider.jsse.OpenSSLMessageDigestJDK$MD5</pattern>
</forceLinkClasses>
<libs>
<lib>build/libs/ios/libgdx-box2d.a</lib>
<lib>build/libs/ios/libgdx-bullet.a</lib>
<lib>build/libs/ios/libgdx-freetype.a</lib>
<lib>build/libs/ios/libgdx.a</lib>
<lib>build/libs/ios/libObjectAL.a</lib>
</libs>
<frameworks>
<framework>UIKit</framework>
<framework>OpenGLES</framework>
<framework>QuartzCore</framework>
<framework>CoreGraphics</framework>
<framework>OpenAL</framework>
<framework>AudioToolbox</framework>
<framework>AVFoundation</framework>
</frameworks>
</config>
答案 0 :(得分:5)
假设您正在使用最新的0.0.14版本的RoboVM,我相信您的问题是您没有强制链接适当的HTTPS支持类。请尝试将您的<forceLinkClasses>
部分更改为:
<forceLinkClasses>
<pattern>com.badlogic.gdx.scenes.scene2d.ui.*</pattern>
<!-- For http: support in URLConnection -->
<pattern>com.android.okhttp.HttpHandler</pattern>
<!-- For https: support in URLConnection -->
<pattern>com.android.okhttp.HttpsHandler</pattern>
<!-- OpenSSL is preferred over BouncyCastle. This pulls in full OpenSSL support. -->
<pattern>com.android.org.conscrypt.**</pattern>
<!-- We still need KeyStore.BKS and CertPathValidator.PKIX from BouncyCastle -->
<pattern>com.android.org.bouncycastle.jce.provider.BouncyCastleProvider</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.BC$Mappings</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi</pattern>
<pattern>com.android.org.bouncycastle.jcajce.provider.keystore.bc.BcKeyStoreSpi$Std</pattern>
<pattern>com.android.org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi</pattern>
<!-- Use AndroidDigestFactoryOpenSSL as AndroidDigestFactory implementation -->
<pattern>com.android.org.bouncycastle.crypto.digests.AndroidDigestFactoryOpenSSL</pattern>
</forceLinkClasses>
如果这不起作用,请尝试将<pattern>**</pattern>
添加到<forceLinkClasses>
。该模式将引入类路径中的所有内容。如果这使得您的应用程序至少工作,那么您就知道它正在导致问题的一个或多个缺失的类。