RestAdapter (retrofit) not resolving in android

前端 未结 4 1566
伪装坚强ぢ
伪装坚强ぢ 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: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

提交回复
热议问题