這個問題 EXPO 官方其實有在 SDK 49 release blog 中提到:
https://blog.expo.dev/expo-sdk-49-c6d398cdf740
android:usesCleartextTraffic
is now based on system defaults. It’s explicitly set to enabled in debug builds, and in other variants it is unspecified, which means that on API 27 and below it will default to true, and on API 28 and above it will default tofalse
. If you depend on network requests to unsecured endpoints in production on Android, you will need to enable this manually throughexpo-build-properties
.
這是在說 android:usesCleartextTraffic
現在是基於 system defaults。意味著在 Android API 27 及更低版本上它預設為 true,而 API 28 或更高版本預設為 false。如果你的應用需要在 Production 請求不安全的Endpoints(比如 HTTP 協議的地址)就需要透過 expo-build-properties 手動啟用此功能。
解決方法
https://github.com/expo/expo/issues/22887#issuecomment-1721948800
npx expo install expo-build-properties
2. 打開 app.json
在 plugins 處加上 usesCleartextTraffic
為 true
{
"expo": {
// ...
"plugins": [
// ...
[
"expo-build-properties",
{
"android": {
"usesCleartextTraffic": true
}
}
]
]
}
}