2016-04-26 2 views
4

Я использую Rtofit для обработки данных Serverside с мобильных устройств после внедрения Retrofit. Я получаю следующее исключение. Любой знает об этой проблеме. Скажите мне, где я ошибаюсь.Runtime Execption java.lang.NoClassDefFoundError: retrofit2.Platform в Android

Init дооснащения:

mRetrofit = new Retrofit.Builder() 
        .baseUrl(AppConstance.APP_URL) 
        .addConverterFactory(GsonConverterFactory.create()) 
        .build(); 
      Iservice = mRetrofit.create(IdeaService.class); 

Gradle Файл

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.2.1' 
    compile 'com.squareup.retrofit2:retrofit:2.0.2' 
    compile 'com.squareup.retrofit2:converter-gson:2.0.0' 
    compile 'com.squareup.okhttp:okhttp:2.2.0' 
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0' 
    compile 'com.squareup.okio:okio:1.7.0' 
} 

StackTrace

04-26 11:54:36.441 18355-18355/com.omt.example W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41da0c98) 
04-26 11:54:36.441 18355-18355/com.omt.example W/dalvikvm: threadid=1: uncaught exception occurred 
04-26 11:54:36.442 18355-18355/com.omt.example W/System.err: java.lang.NoClassDefFoundError: retrofit2.Platform 
04-26 11:54:36.444 18355-18355/com.omt.example W/System.err:  at retrofit2.Retrofit$Builder.<init>(Retrofit.java:402) 
04-26 11:54:36.445 18355-18355/com.omt.example W/System.err:  at com.omt.example.utils.Idea.onCreate(Idea.java:79) 
04-26 11:54:36.447 18355-18355/com.omt.example W/System.err:  at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007) 
04-26 11:54:36.448 18355-18355/com.omt.example W/System.err:  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4541) 
04-26 11:54:36.449 18355-18355/com.omt.example W/System.err:  at android.app.ActivityThread.access$1500(ActivityThread.java:151) 
04-26 11:54:36.450 18355-18355/com.omt.example W/System.err:  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1381) 
04-26 11:54:36.451 18355-18355/com.omt.example W/System.err:  at android.os.Handler.dispatchMessage(Handler.java:110) 
04-26 11:54:36.451 18355-18355/com.omt.example W/System.err:  at android.os.Looper.loop(Looper.java:193) 
04-26 11:54:36.452 18355-18355/com.omt.example W/System.err:  at android.app.ActivityThread.main(ActivityThread.java:5292) 
04-26 11:54:36.453 18355-18355/com.omt.example W/System.err:  at java.lang.reflect.Method.invokeNative(Native Method) 
04-26 11:54:36.454 18355-18355/com.omt.example W/System.err:  at java.lang.reflect.Method.invoke(Method.java:515) 
04-26 11:54:36.455 18355-18355/com.omt.example W/System.err:  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) 
04-26 11:54:36.456 18355-18355/com.omt.example W/System.err:  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
04-26 11:54:36.457 18355-18355/com.omt.example W/System.err:  at dalvik.system.NativeStart.main(Native Method) 
04-26 11:54:36.457 18355-18355/com.omt.example W/dalvikvm: threadid=1: calling UncaughtExceptionHandler 
+0

, кажется, что он не может найти Platformclass.Try очистить и построить – Asthme

+0

я пробовал все еще же ISSU –

+0

Вы используете ProGuard? если да, то добавили ли вы proguard enteries? –

ответ

3

Попробуйте изменить okhttp к okhttp3

compile 'com.squareup.okhttp3:okhttp:3.2.0' 
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0' 

retrofit2 Как внутренне используя okhttp3.

Попробуйте построить и установить градиент.

+0

, и нет необходимости использовать библиотеку okio в gradlle.since, так как retrofit внутренне использует то, что – Asthme

+1

работает отлично Спасибо dude –

+0

@MuthuPandiyan Рад помочь вам. –

6

У меня была та же проблема. Возможное решение (фиксированная моя проблема):

1) Добавить Gradle зависимость: compile 'com.android.support:multidex:1.0.0' (файл build.gradle)

2) Установите multiDexEnabled true (файл build.gradle)

3) Добавить android:name="android.support.multidex.MultiDexApplication" (файл AndroidManifest.xml)

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme" 
    android:name="android.support.multidex.MultiDexApplication"> 
</application> 
+0

Это была проблема для меня. Мое приложение не работало для 4.4, только для 5.0 и более поздних версий, и это решило это. Спасибо. –

0

Добавьте их к классу обслуживания

// создать OkHttpClient клиент

Strategy strategy = new AnnotationStrategy(); 

    // Define the interceptor, add authentication headers 
    Interceptor interceptor = new Interceptor() { 
     @Override 
     public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException { 
      Request newRequest = chain.request().newBuilder().addHeader("User-Agent", "Retrofit-Sample-App").build(); 
      return chain.proceed(newRequest); 
     } 
    }; 


    Serializer serializer = new Persister(strategy); 

    OkHttpClient.Builder builder = new OkHttpClient.Builder(); 
    builder.interceptors().add(interceptor); 
    OkHttpClient client = builder.build(); 

    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); 

    httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); 
    builder.networkInterceptors().add(httpLoggingInterceptor); 
    builder.build(); 

    RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory.create(); 

    Retrofit retrofit = new Retrofit.Builder() 
      .addConverterFactory(SimpleXmlConverterFactory.create(serializer)) 
      .addCallAdapterFactory(rxAdapter) 
      .baseUrl(YellowTalkConstant.BASE_URL) 
      .client(client) 
      .build(); 

    try{ 
     this.mYellowTalkApi = retrofit.create(YellowTalkApi.class); 
    }catch (Exception ex) { 
     Log.e("Exception", ex.toString()); 
    } 
Смежные вопросы