2016-03-18 37 views
0

我試圖使用Retrofit 2.0的發佈版本和他們的Retrofit configuration上建議的GsonConverterFactory。Retrofit 2.0 non-beta,使用GsonConverterFactory

的問題是,GsonConverterFactory似乎只適用於改造1,和我現在我改造2,即使GsonConverterFactory上的2

這裏的β是我的搖籃依賴關係:

compile 'com.squareup.retrofit2:retrofit:2.0.0' 
compile 'com.google.code.gson:gson:2.6.2' 
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' 

我找不到一個非beta版本的converter-gson,只是刪除-beta2並沒有辦法。

運行此代碼:

import retrofit.GsonConverterFactory; 
import retrofit2.Retrofit; 

public class Service { 

    public void getListings() 
    { 
     Retrofit retrofit = new Retrofit.Builder() 
       .baseUrl("http://www.google.com") 
       .addConverterFactory(GsonConverterFactory.create()) 
       .build(); 

     Services services = retrofit.create(Services.class); 
    } 
} 

我得到這個錯誤:

addConverterFactory (retrofit2.Converter.Factory) in Builder cannot be applied to (gson.GsonConverterFactory) 

任何建議,除了運行改造2測試版?

謝謝!

回答

3

據對改造的網站上的文檔,他們說,你應該使用com.squareup.retrofit2:converter-gson

build.gradle

compile 'com.squareup.retrofit2:converter-gson:2.0.0' 
+0

對不起。我嘗試過,但沒有奏效。 – TooManyEduardos

+0

最後需要2.0.0,它的工作原理!謝謝。可能編輯答案,以便我可以將其標記爲正確的答案。 – TooManyEduardos

1

普拉莫德是接近它取代

compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' 

。此作品:

compile 'com.squareup.retrofit2:converter-gson:2.0.0' 

它需要在末尾2.0.0

+0

在這種情況下,你應該通知廣場的傢伙,因爲他們的網站上他們有com.squareup.retrofit2:converter-gson不能編譯'com.squareup.retrofit2:converter-gson:2.0.0'它會混淆其他人 –

+0

究竟!我會給他們發郵件 – TooManyEduardos