So I am trying to use Retrofit for my project. As the site says I have included
compile \'com.squareup.retrofit:retrofit:2.0.0-beta1\'
in build.gradle
If you want to run your code you need to use older version of Retrofit.
compile 'com.squareup.retrofit:retrofit:1.9.0'
But you are using
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
So you need to change your code like this.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com")
.build();`
for complete documentation please check RetroFit square
There is a change in the API in version 2. This is how you do it in this version:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com")
.build();
GitHubService service = retrofit.create(GitHubService.class);
Please refer here for more information: Retrofit 2 home page
and these slides: Retrofit 2 presentation
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.
If you want to accept json result and make it parse into DAO, you have to summon Gson Converter as a separate dependency.
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
And plug it in through addConverterFactory. Please note that RestAdapter is now also renamed to Retrofit.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.nuuneoi.com/base/")
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(APIService.class);
more info: https://inthecheesefactory.com/blog/retrofit-2.0/en
You have two options:
This has the RestAdapter
class you need.
compile 'com.squareup.retrofit:retrofit:1.9.0'
The RestAdapter
class was renamed to Retrofit
and the API was completely remade. Read more in Jake Wharton's presentation.
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
As of June 30 2016 the latest version is 2.1.0 obtained by
compile 'com.squareup.retrofit2:retrofit:2.1.0'
Please check http://square.github.io/retrofit/ for updates.