苏州做网站知识的分享,黄骅港引航站,河池环江网站建设,安卓android官网下载flutter开发实战-解决release下Error: SocketException: Failed host lookup问题
当在开发App过程中#xff0c;在Debug下接口访问正常#xff0c;但是通过flutter build apk lib/main.dart --release打包后安装#xff0c;发现Android手机上无法请求数据#xff0c;报Err…flutter开发实战-解决release下Error: SocketException: Failed host lookup问题
当在开发App过程中在Debug下接口访问正常但是通过flutter build apk lib/main.dart --release打包后安装发现Android手机上无法请求数据报Error: SocketException: Failed host lookup的错误
一、解决Android的release下Error: SocketException: Failed host lookup问题
在工程的android/app/main/AndroidManifest.xml需要添加网络请求权限 uses-permission android:nameandroid.permission.INTERNET /uses-permission android:nameandroid.permission.ACCESS_NETWORK_STATE /uses-permission android:nameandroid.permission.ACCESS_WIFI_STATE /
AndroidManifest.xml完整结构如下
manifest xmlns:androidhttp://schemas.android.com/apk/res/androidpackagecn.example.flutter_appuses-permission android:nameandroid.permission.INTERNET /uses-permission android:nameandroid.permission.ACCESS_NETWORK_STATE /uses-permission android:nameandroid.permission.ACCESS_WIFI_STATE /applicationandroid:labelflutter_appandroid:name${applicationName}android:usesCleartextTraffictrueandroid:iconmipmap/ic_launcheractivityandroid:name.MainActivityandroid:exportedtrueandroid:launchModesingleTopandroid:themestyle/LaunchThemeandroid:configChangesorientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiModeandroid:hardwareAcceleratedtrueandroid:usesCleartextTraffictrueandroid:windowSoftInputModeadjustResizeandroid:networkSecurityConfigxml/network_security_config!-- Specifies an Android theme to apply to this Activity as soon asthe Android process has started. This theme is visible to the userwhile the Flutter UI initializes. After that, this theme continuesto determine the Window background behind the Flutter UI. --meta-dataandroid:nameio.flutter.embedding.android.NormalThemeandroid:resourcestyle/NormalTheme/intent-filteraction android:nameandroid.intent.action.MAIN/category android:nameandroid.intent.category.LAUNCHER//intent-filter/activity!-- Dont delete the meta-data below.This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --meta-dataandroid:nameflutterEmbeddingandroid:value2 //application
/manifest
二、iOS工程info.plist文件配置
在ios/Runner/info.plist添加NSAppTransportSecurity
keyNSAppTransportSecurity/keydictkeyNSAllowsArbitraryLoads/keytrue//dict
完整的info.plist如下
?xml version1.0 encodingUTF-8?
!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd
plist version1.0
dictkeyCFBundleDevelopmentRegion/keystring$(DEVELOPMENT_LANGUAGE)/stringkeyCFBundleDisplayName/keystringFlutter App/stringkeyCFBundleExecutable/keystring$(EXECUTABLE_NAME)/stringkeyCFBundleIdentifier/keystring$(PRODUCT_BUNDLE_IDENTIFIER)/stringkeyCFBundleInfoDictionaryVersion/keystring6.0/stringkeyCFBundleName/keystringflutter_app_merchant_platform/stringkeyCFBundlePackageType/keystringAPPL/stringkeyCFBundleShortVersionString/keystring$(FLUTTER_BUILD_NAME)/stringkeyCFBundleSignature/keystring????/stringkeyCFBundleVersion/keystring$(FLUTTER_BUILD_NUMBER)/stringkeyLSRequiresIPhoneOS/keytrue/keyUILaunchStoryboardName/keystringLaunchScreen/stringkeyUIMainStoryboardFile/keystringMain/stringkeyUISupportedInterfaceOrientations/keyarraystringUIInterfaceOrientationPortrait/stringstringUIInterfaceOrientationLandscapeLeft/stringstringUIInterfaceOrientationLandscapeRight/string/arraykeyUISupportedInterfaceOrientations~ipad/keyarraystringUIInterfaceOrientationPortrait/stringstringUIInterfaceOrientationPortraitUpsideDown/stringstringUIInterfaceOrientationLandscapeLeft/stringstringUIInterfaceOrientationLandscapeRight/string/arraykeyUIViewControllerBasedStatusBarAppearance/keyfalse/keyCADisableMinimumFrameDurationOnPhone/keytrue/keyUIApplicationSupportsIndirectInputEvents/keytrue/keyNSAppTransportSecurity/keydictkeyNSAllowsArbitraryLoads/keytrue//dict
/dict
/plist
三、小结
flutter开发实战-解决release下Error: SocketException: Failed host lookup问题
学习记录每天不停进步。