LoginSignup
11
2

More than 3 years have passed since last update.

FlutterのreleaseビルドでHTTP通信が使えないとき

Posted at

FlutterのreleaseビルドでHTTP通信が使えないとき

つい先日、debugモードでのビルドが正常に動いていたためreleaseモードでビルドして実行しようとした際に

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)]
Unhandled Exception: SocketException: Failed host lookup: 'example.com/api/hogehoge'
(OS Error: No address associated with hostname, errno = 7)

といったエラーが出ました。

Failed host lookup(ホスト検索に失敗)と出ていたのでURLが間違えていたのかと思い確認してみるが間違えていなかった。

後ろのほうを見てみると、OS Error: No address associated with hostname(ホスト名に関連付けられたアドレスがありません)となっているため、もしかしたら権限回り?と思い調べてみました

StackOverflowに同じようなError内容がありました。

error when using https with flutter http.dart package

ネットワークに接続するための権限がないので、権限をandroid\app\src\main\AndroidManifest.xmlに書いてくださいとのことでした。

<manifest xmlns:android="http://".....>
    <uses-permission android:name="android.permission.INTERNET" /> <!--この行を追加してください!-->
    <application android:name=......>
        <activity .....>
            .....
        </activity>
    </application>
</manifest>

これでreleaseビルドでもhttp通信ができるようになりました!

参考ドキュメント

Android developersドキュメント:ネットワークに接続する

11
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
2