Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrofit cannot access HttpUrl

I have included below libraries to my app's lib folder:

  1. compile files('libs/retrofit-2.0.0-beta2.jar')
  2. compile files('libs/converter-gson-2.0.0-beta1.jar')

When going to run app it gives me such an error:

Error:(17, 17) error: cannot access HttpUrl class file for com.squareup.okhttp.HttpUrl not found

I have created app including retrofit as said here: The biggest update yet on the best HTTP Client Library for Android

  1. As there said: But in Retrofit 2.0, OkHttp is now required and is automatically set as a dependency.

    -- So, did not add OkHttp to my project

  2. As there said: But in Retrofit 2.0, Converter is not included in the package anymore. You need to plug a Converter in yourself or Retrofit will be able to accept only the String result. As a result, Retrofit 2.0 doesn't depend on Gson anymore.

    -- So, i decided include Gson: com.squareup.retrofit:converter-gson to my app, not 'com.google.code.gson:gson:2.3.1'

Any advises how to use retrofit will be helpful. And please advice me how to correct this main Error?

Solved: I searched and find this solution. If you are using proxy to connect internet then simply add it to gradle.properties file:

systemProp.http.proxyHost=xxx systemProp.http.proxyPort=xxx systemProp.http.proxyUser=xxx systemProp.http.proxyPassword=xxx systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

systemProp.https.proxyHost=xxx systemProp.https.proxyPort=xxx systemProp.https.proxyUser=xxx systemProp.https.proxyPassword=xxx systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

Thanks to @ilya. It was just network issue

like image 438
AEMLoviji Avatar asked Mar 14 '23 14:03

AEMLoviji


1 Answers

Jars doesn't contain any information about its dependencies So when you are adding jars you also have to download and add OkHttp/Gson jars.

compile files('libs/okhttp.jar')
compile files('libs/gson.jar')

But if you add your dependency in this way

compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'

All other required libraries will be downloaded and added by gradle automatically.

The final gradle.build should contain these 2 lines:

compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
like image 140
Ilya Tretyakov Avatar answered Mar 29 '23 21:03

Ilya Tretyakov