RestAdapter (retrofit) not resolving in android

前端 未结 4 1553
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 04:39

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

相关标签:
4条回答
  • 2020-12-03 05:08

    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

    0 讨论(0)
  • 2020-12-03 05:15

    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

    0 讨论(0)
  • 2020-12-03 05:25

    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

    0 讨论(0)
  • 2020-12-03 05:29

    You have two options:

    1) Use stable Retrofit 1

    This has the RestAdapter class you need.

    compile 'com.squareup.retrofit:retrofit:1.9.0'
    

    2) Migrate to Retrofit 2

    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.

    0 讨论(0)
提交回复
热议问题