2017-07-25 82 views
0

我收到此錯誤信息,如果我嘗試使用GsonConvertFactory:無法解析符號GsonConverterFactory

無法解析符號GsonConverterFactory

我使用它是這樣的:

return new Retrofit.Builder() 
      .baseUrl(BASE_URL) 
      .client(client) 
      //.addConverterFactory(MoshiConverterFactory.create()) 
      .addConverterFactory(GsonConverterFactory.create(gson)) 
      .build(); 

這是我的gradle這個文件(模塊:APP):

dependencies { 
    ... 
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1' 
    compile 'com.google.code.gson:gson:2.7' 
} 

回答

3

GsonConverterFactory駐留在下面的依賴關係中,因此,請在作爲依賴關係的build.gradle中添加此項。

compile 'com.squareup.retrofit2:converter-gson:2.3.0' 
0

更改此

compile 'com.google.code.gson:gson:2.7' 

對此

compile 'com.google.code.gson:gson:2.8.1' 
0

你建議立即進行刪除添加這些庫的build.gradle文件

編譯「com.squareup.retrofit2:轉換器 - GSON:2.3.0' 編譯 'com.squareup.retrofit2:改造:2.3.0'

dependencies { 
 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
 
     exclude group: 'com.android.support', module: 'support-annotations' 
 
    }) 
 
    compile 'com.android.support:appcompat-v7:25.3.1' 
 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
 
    compile 'com.squareup.retrofit2:converter-gson:2.3.0' 
 
    compile 'com.squareup.retrofit2:retrofit:2.3.0' 
 
    testCompile 'junit:junit:4.12' 
 
}