admin 管理员组文章数量: 1086019
straight to the point. I created a new react native app in windows using:
npx @react-native-community/cli init exampleApp
I then run:
npx react-native run-android
Everything loads up OK. Metro runs fine, Gradlew builds the app OK and the emulator loads fine allowing me to edit the app in real time. Everything works fine.
THE PROBLEM:
The react native app connects OK to a LAN server using HTTP or WebSockets (ws). I need the app to connect using those protocols over TLS, i.e. https or wss.
I've read that Android by default blocks self-signed SSL certificates and non-secure connections like http:// and ws://.
So, I read a bit more online and found something on Android docs. Also, this Stack Overflow question looks relevant.
The thing is, when I do what those two resources mention I need to do so that my app connects to the server, I'm getting the following error:
Unable to load script. Make sure youre either running Metro (run "npx react-native start")
or that your bundle "index.android.bundle" is packaged correctly for release.
MY CONFIGURATION:
I created a new folder at the following location and copied/pasted the root CA certificate that I created using openssl. This certificate signed the certificate that the LAN server is using: exampleApp/android/app/src/main/res/raw/test_rootca_certificate.crt
I created a file called "network_security_config.xml" at the following location: exampleApp/android/app/src/main/res/xml/network_security_config.xml
and this is the content:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="@raw/test_rootca_certificate"/>
<certificates src="system"/>
</trust-anchors>
</base-config>
</network-security-config>
Finally I added the following line inside the application element tag in the "AndroidManifest.xml" file: android:networkSecurityConfig="@xml/network_security_config"
CONCLUSIONS:
I already tried running Metro bundler first in a separate terminal and then when Metro loads, I proceed to build the app using npx react-native run-android
, but I get the same error.
If I remove the following line from AndroidManifest.xml
, the error is gone:
android:networkSecurityConfig="@xml/network_security_config"
I already tried doing the following but the same error appears:
adb reverse tcp:8081 tcp:80181
I tried clearing the gradlew cache, and restarting adb server but the same error appears.
What could be the issue here? Is there some Android-specific configuration I'm missing? The app works fine in HTTP, but since I need HTTPS I'm following these network configurations.
Any help will do, thank you!
本文标签: androidReact Native ERROR after editing quotAndroidManifestxmlquotStack Overflow
版权声明:本文标题:android - React Native ERROR after editing "AndroidManifest.xml" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744018651a2519392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论