I’m working on a React Native 0.74 app with a third-party SDK that requires Metro to run over HTTPS instead of HTTP. I prefer to use USB method over WI-FI.
Setup
React Native 0.74.1
Android physical device (Samsung Galaxy A22 5G)
Developing on macOS (Metro running on my machine)
Using mkcert to generate certs with SAN =
localhost,127.0.0.1,::1,and my LAN IPInstalled mkcert root CA on the Android device as a CA certificate
Added a debug
network_security_config.xmlthat allows<certificates src="user"/>I can verify from my Mac:
curl -vk https://localhost:8081/status # workscurl -v http://localhost:8081/status # fail
What I’ve tried
1. Metro HTTPS config
metro.config.js:
server: { secureServerOptions: { key: fs.readFileSync('./certs/key.pem'), cert: fs.readFileSync('./certs/cert.pem'), },},and starting Metro with:
npx react-native start --https --port 8081 \ --key ./certs/key.pem --cert ./certs/cert.pem --reset-cache2. USB + adb reverse
adb reverse tcp:8081 tcp:8081and setting Debug server host & port for device on the device in Dev Menu →localhost:8081. Have also tried the setup with another port ex. localhost:9091. And if I write https://localhost:8081 it just gets prepend to http://https://localhost:8081.
3. Wi-Fi
Set Debug server host & port for device→my_ip:8081.
4. SharedPreferences override
Tried pushing this file intoshared_prefs/ReactNativeDevPrefs.xml and com.facebook.react.packager_preferences.xml:
<map><string name="debug_http_host">localhost:8081</string><boolean name="dev_server_https" value="true" /></map>I also added equivalent code in MainApplication.kt (onCreate) to write these values on startup.
5. mkcert CA on device
- Confirmed it’s installed as a CA certificate and
- My cert includes the LAN IP + localhost + 127.0.0.1.
The problem
Despite all this, the app still tries to connect withhttp://…instead ofhttps://.
On red error screens "Could not connect to development server.." I see:
URL: http://localhost:8081/index.bundle?platform=android...instead of
URL: https://localhost:8081/index.bundle?platform=android...Even with prefs set to dev_server_https=true, it seems React Native 0.74 keeps falling back to HTTP.
Question
How can I force React Native 0.74 to use HTTPS for the dev server?
Is there a reliable way to ensure Metro only listens on HTTPS (no HTTP fallback)?
Is there a known limitation in RN 0.74 around HTTPS dev servers?
Any working examples (preferable USB or else Wi-Fi) would be hugely appreciated 🙏