2017-01-31 4 views
2

だから私は自分のコードをたどって、レトロフィットの依存関係がどこのgradleファイルでも見つからないことに気付きました。私の最初の考えは、それが別の図書館の中に束ねられていたので、私はそれらを一つずつ除外し始めましたが、それがどこであるか把握できませんでした。ライブラリの依存関係なしでretrofitはどのように動作しますか?

問題1: 私はトラブルシューティングの目的のために使用しています改造のバージョンを見つけることができません。
問題2: 私はHttpLoggingInterceptorのコメントを解除した場合、それはjava.lang.NoSuchMethodErrorの

エラーログでクラッシュ:

import com.google.gson.Gson; 
import com.google.gson.GsonBuilder; 

import okhttp3.OkHttpClient; 
import okhttp3.logging.HttpLoggingInterceptor; 
import retrofit2.Retrofit; 
import retrofit2.converter.gson.GsonConverterFactory; 


public class RestApi { 
    private static String BASE_URL = "https://someurl.com"; 
    private static RestInterface apiService; 

    public static RestInterface getApi() { 

     if(apiService == null){ 
      Gson gson = new GsonBuilder() 
        .setDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'") 
        .registerTypeAdapterFactory(new ItemTypeAdapterFactory()) 
        .create(); 

      // This crashes with NoSuchMethodError 

//   HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); 
//   logging.setLevel(HttpLoggingInterceptor.Level.HEADERS); 
// 
//   OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); 
//   httpClient.addInterceptor(logging); 

      Retrofit adapter = new Retrofit.Builder() 
        .baseUrl(BASE_URL) 
        .addConverterFactory(GsonConverterFactory.create(gson)) 
        //.client(httpClient.build()) 
        .build(); 

      apiService = adapter.create(RestInterface.class); 
     } 
     return apiService; 
    } 
} 

トップレベルのGradle:ここ

E/UncaughtException: java.lang.NoSuchMethodError: No virtual method startsWith(Lokio/ByteString;)Z in class Lokio/ByteString; or its super classes (declaration of 'okio.ByteString' appears in /data/data/com.company.app/files/instant-run/dex/slice-okio-1.6.0_7e5c9782b87cba0343c811c73cffd2135b1ad139-classes.dex) 
     at okhttp3.internal.http2.Hpack$Writer.writeHeaders(Hpack.java:511) 
     at okhttp3.internal.http2.Http2Writer.headers(Http2Writer.java:299) 
     at okhttp3.internal.http2.Http2Writer.synStream(Http2Writer.java:127) 
     at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:230) 
     at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:205) 
     at okhttp3.internal.http2.Http2Codec.writeRequestHeaders(Http2Codec.java:105) 
     at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:43) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
     at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:212) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179) 
     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:129) 
     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:818) 

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher 
     java.lang.NoSuchMethodError: No virtual method startsWith(Lokio/ByteString;)Z in class Lokio/ByteString; or its super classes (declaration of 'okio.ByteString' appears in /data/data/com.company.app/files/instant-run/dex/slice-okio-1.6.0_7e5c9782b87cba0343c811c73cffd2135b1ad139-classes.dex) 
     at okhttp3.internal.http2.Hpack$Writer.writeHeaders(Hpack.java:511) 
     at okhttp3.internal.http2.Http2Writer.headers(Http2Writer.java:299) 
     at okhttp3.internal.http2.Http2Writer.synStream(Http2Writer.java:127) 
     at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:230) 
     at okhttp3.internal.http2.Http2Connection.newStream(Http2Connection.java:205) 
     at okhttp3.internal.http2.Http2Codec.writeRequestHeaders(Http2Codec.java:105) 
     at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:43) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
     at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:212) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) 
     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) 
     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:179) 
     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:129) 
     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
     at java.lang.Thread.run(Thread.java:818) 

は私のコードです:

buildscript { 
    repositories { 
     jcenter() 
     maven { url 'https://maven.fabric.io/public' } 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.3' 
     classpath 'com.google.gms:google-services:3.0.0' 
     classpath 'io.fabric.tools:gradle:1.21.5' 
     classpath "io.realm:realm-gradle-plugin:2.3.0" 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

アプリケーションのGradle:

dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.3' 
     classpath 'com.google.gms:google-services:3.0.0' 
     classpath 'io.fabric.tools:gradle:1.21.5' 
     classpath "io.realm:realm-gradle-plugin:2.3.0" 
    } 

私はそれが彼らのgithubのレポのbuild.gradle応じ改造を使用して、ファブリックSDKだと思う:私はあなたのbuild.gradleは以下の依存関係を持っていることに気づいた

apply plugin: 'com.android.application' 
apply plugin: 'io.fabric' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.1" 
    defaultConfig { 
     applicationId "com.someid.app" 
     minSdkVersion 16 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    testOptions { 
     unitTests.returnDefaultValues = true 
    } 
} 
repositories { 
    mavenCentral() 
    maven { url 'https://maven.fabric.io/public' } 
} 
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.twitter.sdk.android:twitter:[email protected]') { 
     transitive = true; 
    } 


    compile 'com.android.support:appcompat-v7:25.1.0' 
    compile 'com.android.support:design:25.1.0' 
    compile 'com.android.support:support-v4:25.1.0' 
    compile 'com.android.support:recyclerview-v7:25.1.0' 

    compile 'com.google.firebase:firebase-core:10.0.1' 
    compile 'com.google.firebase:firebase-messaging:10.0.1' 
    compile 'com.google.firebase:firebase-auth:10.0.1' 
    compile 'com.google.firebase:firebase-crash:10.0.1' 
    compile 'com.google.firebase:firebase-config:10.0.1' 
    compile 'com.google.firebase:firebase-storage:10.0.1' 
    compile 'com.google.firebase:firebase-ads:10.0.1' 
    compile 'com.google.firebase:firebase-database:10.0.1' 

    compile 'com.firebaseui:firebase-ui-database:1.1.1' 
    compile 'com.google.android.gms:play-services-auth:10.0.1' 
    compile 'com.facebook.android:facebook-android-sdk:[4,5)' 

    compile 'com.squareup.picasso:picasso:2.5.2' 

    testCompile 'junit:junit:4.12' 
    testCompile 'org.mockito:mockito-core:1.10.19' 
    testCompile 'org.robolectric:robolectric:3.2.1' 
} 

apply plugin: 'realm-android' 
apply plugin: 'com.google.gms.google-services' 
+0

、これはあなたの問題を解決できますか? http://stackoverflow.com/questions/32514410/logging-with-retrofit-2 – Egor

+0

「NoSuchMethodError」のスタックトレースを投稿してください。 retrofit2がどこから来ているかを知るには、 './gradlew dependencies'を使います。 – Egor

+0

何が問題でしたか?私は同じ問題に直面している – Rawan

答えて

3

dependenciesタスクを使用することによって、彼らがどこから来ているトレースするすべてのプロジェクトの依存関係を一覧表示する簡単な方法があります:あなたは、さらに調査することができます報告生み出す

gradlew app:dependencies 

docs: 4.7.4. Listing project dependencies)。

また、「Gradleの表示」の場合と呼ばれるIDEAプラグインがあるように思えるそのように好む:あなたの問題があるまさに明確ではありませんhttps://plugins.jetbrains.com/idea/plugin/7150-gradle-view

+0

ありがとう、これはすべてのバージョンと可能な更新を見つけるのに役立ちました。 –

+0

依存関係の更新をチェックするには、[Android Studioの組み込み機能のこの回答](http://stackoverflow.com/a/28683488/1235698)または[この1つは純粋なgradleベースのもの]( http://stackoverflow.com/a/41958982/1235698)。 –

2

クラスパス 'io.fabric.tools:gradle:1.21.5' https://github.com/twitter/twitter-kit-android/blob/3530b71de233606248b2c80a4d67b78a69642523/dependencies.gradle

dependencies { 
    . 
    . 
    retrofit:'com.squareup.retrofit2:retrofit:2.0.2', 
    . 
    . 
} 
+0

ヒントのおかげで、ここで彼らは1.9を使用すると言うが、私のコードはretrofit2をインポートする? –

+0

これは、古いインターセプタを使用して動作させる必要があることを意味しますか?私は本当に最新のライブラリを使うのが好きです。 –

+0

申し訳ありません、正しいリンクで回答を更新しました。実際にはRetrofit 2を使用していますが、インターセプタについては古いバージョンを使用する必要はありません。 –

関連する問題