2015-10-02 10 views
38

उपयोग नहीं कर सकते मैं अपने प्रोजेक्ट के लिए इन निर्भरता को शामिल किया है:पुराना वापस कनवर्टर कारखाना GsonConverterFactory

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

मैं एक वर्ग है, जहां मैं पुराना वापस के माध्यम से मेरी एपीआई का उपयोग करने के लिए जा रहा हूँ है:

public static <S> S createService(Class<S> serviceClass, String baseUrl) { 


     Retrofit builder = new Retrofit.Builder() 
       .baseUrl(baseUrl) 
       .addConverterFactory(GsonConverterFactory.create()) 
       .build();  

      RestAdapter adapter = builder.build();*/ 

     return builder.create(serviceClass); 
    } 

और अब , यह मुझे यह संकलन समय त्रुटि देता है:

Error:(24, 17) error: method addConverterFactory in class Builder cannot be applied to given types; required: Factory found: GsonConverterFactory reason: actual argument GsonConverterFactory cannot be converted to Factory by method invocation conversion

मैं इसे कैसे हल कर सकता हूं? मैंने प्रलेखन का पालन किया। गलत क्या है?

उत्तर

111

रेट्रोफिट और कनवर्टर-जीसन - 2.0.0-beta2 के लिए समान संस्करण का उपयोग करने का प्रयास करें। आप कनवर्टर के लिए रेट्रोफिट और beta1 के लिए beta2 का उपयोग कर रहे हैं।

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

महत्वपूर्ण नोट!

रेट्रोफिट 2.0.0-beta3 संस्करण के बाद से अपने पैकेज का नाम बदलता है। अब आपको com.squareup.retrofit2 का उपयोग करना चाहिए।

compile 'com.squareup.retrofit2:retrofit:2.2.0' 
compile 'com.squareup.retrofit2:converter-gson:2.2.0' 
+1

आप एक बड़े आदमी हैं)। लेकिन कोई संसाधन नहीं है जो इंगित करता है कि मुझे उसी बीटा 2 संस्करण का उपयोग करना होगा। – AEMLoviji

+0

@AEMLoviji संसाधन को सामान्य ज्ञान कहा जाता है, क्या आप सहमत नहीं होंगे? सबसे विशेष रूप से क्योंकि बीटा चरण इंटरफेस के दौरान परिवर्तन के अधीन हैं जो रेट्रोफिट दस्तावेज़ों में लिखा गया है। –

+0

मैं बस इस समस्या में भाग गया। और उसने 2 घंटे पहले हल किया। धन्यवाद!) – ip696

1
error: method addConverterFactory in class Builder cannot be applied to given types; 
    required: Factory 
    found: GsonConverterFactory 
    reason: actual argument GsonConverterFactory cannot be converted to Factory by method invocation conversion 

आपको यह त्रुटि मिलती रहे हैं, तो कारण गलत dependancy शामिल है: यहाँ उदाहरण है। के रूप में

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

आवेदन build.gradle फ़ाइल में

जोड़ें/परिवर्तन निर्भरता सुनिश्चित करें कि कनवर्टर संस्करण 2.0.0-beta2 नहीं 2.0.0-beta1 है या नहीं।

2

नवीनतम बीटा 2.0.3 रिलीज के साथ आप जोड़ने की जरूरत:

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

gson कनवर्टर संस्करण के साथ पुराना वापस पुस्तकालय संस्करण से मेल करना सुनिश्चित करें।

+0

अंतर स्पॉट करना मुश्किल है।तो हर किसी के लिए जो मेरे जैसा अंधा है - आपको पैकेज नाम में '2' जोड़ना होगा। – reVerse

2

यह नवीनतम है:

compile 'com.squareup.retrofit2:retrofit:2.0.0' 
compile 'com.squareup.retrofit2:converter-gson:2.0.0' 
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0' 

आप बीटा संस्करण का उपयोग करते हैं:

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

build.gradle (एप्लिकेशन) में के बजाय:

implementation 'com.google.code.gson:gson:2.8.2' 

लिखने:

implementation 'com.squareup.retrofit2:converter-gson:2.3.0' 
संबंधित मुद्दे