I'm trying to create a simple widget that just shows data acquired by a json exposed via Github. I'm using Retrofit (don't know if this is right but i found this one) from the emulator on studio all good but when i generate the apk and install it on my device it wont work and i got this error: java.net.UnkownHostException: Unable to resolve host "host": No Address associated.
I added these to manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
But this is still not working. I even tried with google.com but still wasnt able to resolve the host. What can i try? Is this a Retrofit problem?
Here the retrofit part:
@Keep
object RetrofitService {
private val numbersRetrofit: Retrofit = Retrofit.Builder()
.baseUrl("https://host.github.io/")
.client(OkHttpClient())
.addConverterFactory(GsonConverterFactory.create())
.build()
fun getGamesApiService(): GamesApiService {
return numbersRetrofit.create(GamesApiService::class.java)
}
}
Any idea? Thanks
UPDATE: I checked also with this method:
private fun isOnline(mgr: ConnectivityManager): Boolean {
val netInfo = mgr.activeNetworkInfo
return if (netInfo != null && netInfo.isConnected) {
true
} else false
}
And netInfo.isConnected is actually false
The solution was adding a file in xml folder named
network_security_config.xmlwith the following content:Then adding this line in the manifest inside the application tag: