Play商店发布的应用上“网络无法访问”,但调试版本有效

时间:2019-05-26 23:25:58

标签: java android google-play proguard

我无法使用我的应用商店的Play商店发布的版本连接到Chromecast Audio,但可以在同一部手机上使用USB调试版本。两种版本都可以访问网络,即它们都可以成功找到Chromecast设备的IP地址。

相同的手机,Chromecast,网络和代码。只是Play商店发布的APK /捆绑软件无法连接。

在Logcat中,我看到:

2019-05-27 11:05:12.753 9203-9370/? W/System.err: java.net.ConnectException: failed to connect to /192.168.100.109 (port 8009) from /:: (port 0): connect failed: ENETUNREACH (Network is unreachable)
2019-05-27 11:05:12.753 9203-9370/? W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:138)
2019-05-27 11:05:12.753 9203-9370/? W/System.err:     at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:129)
2019-05-27 11:05:12.753 9203-9370/? W/System.err:     at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:357)
2019-05-27 11:05:12.753 9203-9370/? W/System.err:     at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:201)
2019-05-27 11:05:12.753 9203-9370/? W/System.err:     at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:183)
2019-05-27 11:05:12.753 9203-9370/? W/System.err:     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
2019-05-27 11:05:12.753 9203-9370/? W/System.err:     at java.net.Socket.connect(Socket.java:616)
2019-05-27 11:05:12.753 9203-9370/? W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.connect(OpenSSLSocketImpl.java:263)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.connect(OpenSSLSocketImpl.java:250)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at f.a.a.a.a.y.connect(Unknown Source:55)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at f.a.a.a.a.y.d(Unknown Source:4)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at f.a.a.a.a.z.a(Unknown Source:28)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at f.a.a.a.a.z.j(Unknown Source:5)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at f.a.a.a.a.z.e(Unknown Source:0)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at [my app's name].j.e(Unknown Source:29)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at [my app's name].j.b(Unknown Source:0)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at [my app's name].f.run(Unknown Source:3)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at java.lang.Thread.run(Thread.java:784)
2019-05-27 11:05:12.754 9203-9370/? W/System.err: Caused by: android.system.ErrnoException: connect failed: ENETUNREACH (Network is unreachable)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at libcore.io.Linux.connect(Native Method)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:126)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at libcore.io.IoBridge.connectErrno(IoBridge.java:152)
2019-05-27 11:05:12.754 9203-9370/? W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:130)

很明显,我的应用程序可以找到AVR / Chromecast Audio的IP地址(192.168.100.109)来访问网络。我还在清单中为其授予了INTERNET许可。我还在build.gradle文件中使用了minifyEnabled trueshrinkResources true

为方便起见,我使用ChromeCast Java API v2而不是官方的Cast SDK,如果有什么不同的话。

编辑:已解决。 minifyEnabled true文件(即ProGuard)中的选项build.gradle (Module: app)不喜欢ChromeCast Java API v2库。

1 个答案:

答案 0 :(得分:0)

minifyEnabled true文件中启用选项build.gradle (Module: app)是问题所在。 ProGuard和ChromeCast Java API v2库不能很好地协同工作,因此如果要使用minifyEnabled选项,则需要在proguard-rules.pro文件中添加排除项:

-keep class su.litvak.chromecast.**
-keepclassmembers class su.litvak.chromecast.** {*;}

非常感谢用户this questionrandom的回答。