最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Flutter app won't connect to my local API - Stack Overflow

programmeradmin2浏览0评论

The application from the mobile phone does not connect to my local ASP Web API, although the debug version of the application running on the emulator works with it correctly, while running "flutter build apk" and installing it on the mobile phone does not work. The phone and the server are on the same network, which is why I can't figure out what the problem is.

The application from the mobile phone does not connect to my local ASP Web API, although the debug version of the application running on the emulator works with it correctly, while running "flutter build apk" and installing it on the mobile phone does not work. The phone and the server are on the same network, which is why I can't figure out what the problem is.

Share edited Mar 4 at 11:37 VLAZ 29.2k9 gold badges63 silver badges84 bronze badges asked Mar 4 at 11:31 Денис ВолчекДенис Волчек 31 bronze badge
Add a comment  | 

3 Answers 3

Reset to default 0

Since the app requires an internet connection to communicate with your local ASP Web API.

  • the debug version of the application running correctly.

  • the command flutter build apk builds a release APK by default.

  • The internet permission is not added by default in the AndroidManifest file in the release version.

Try to:

1. Open AndroidManifest.xml:

Navigate to android/app/src/main/AndroidManifest.xml in your project.

2. Add the INTERNET Permission:

<uses-permission android:name="android.permission.INTERNET"/>

3. Additional Permissions to Consider

  • Access Network State:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

  • Access Wi-Fi State:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

what IP address is in your code when you run flutter build apk? It should not be 10.0.2.2. 10.0.2.2 is for emulators to host machines only. you need to use the LAN ip address of your machine, connect your phone to the same network as your machine. Look at the logcat for more info, it may give you more insight as well. here is a screenshot of logcat

With your android device connected, you can use adb reverse to grant your device access to local host running on your computer.

See this article for more info.

发布评论

评论列表(0)

  1. 暂无评论