けーじーのブログ

旅行の記録と撮った写真と時々技術的な話を書く

Android7.0でhttp接続

はじめに

アルバイト先でGCPのモックサーバにAPI投げまくっていたはずが、bodyがすっからかんで:thinking_face:になったので備忘録として書き残しておく。

tl;dr

xmlファイルを作ってManifestに追記する

環境

現象

Fuelを使ってGCP上のモックサーバに向けてhttp postを投げるもGCP側のログを見るとbodyが空。 Android studio側のコンソールに D/NetworkSecurityConfig: No Network Security Config specified, using platform defaultの表記。 f:id:zyundamochi_080:20190621175806p:plain

解決策

  • AndroidManifest.xmlに以下を追加
 <application
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
(以下省略)
  • (省略)/res/xml/network_security_config.xmlを作成
  • network_security_config.xmlを記入
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

表記がf:id:zyundamochi_080:20190621175146p:plainになれば繋がると思います

公式そのまんまと言えばそれはそうなんですけど忘れそうなんでメモ書きでした
以前までパーミッションの一文だけで良かったのにいつの間に変わってたんだ...って作業中に思ってました()