2017-01-31 13 views
2

Итак, я прошел через свой код, и я заметил, что зависимость от модификации нигде не встречается ни в одном файле градиента. Моя первая мысль заключалась в том, что она встроена в другую библиотеку, поэтому я начал исключать их один за другим, и все же я не мог понять, где это.Как модифицировать работу без зависимости от библиотеки в градиенте?

Проблема 1: Невозможно узнать версию модификации, которую я использую для устранения неполадок.
Задача 2: Если я раскомментировать HttpLoggingInterceptor он падает с java.lang.NoSuchMethodError

Журнал ошибок:

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) 

Вот мой код:

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 :

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 
} 

App 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'. Чтобы выяснить, откуда происходит ретрофит2, используйте './gradlew dependencies' – Egor

+0

, в чем проблема? Я столкнулся с той же проблемой – Rawan

ответ

3

Там в простой способ перечислить все зависимости проекта, чтобы проследить, где они приходят с помощью dependencies задачи:

gradlew app:dependencies 

, который будет производить отчет можно дополнительно исследовать (docs: 4.7.4. Listing project dependencies).

Кроме того, кажется, есть плагин IDEA под названием «Gradle View», если предпочитают его таким образом: https://plugins.jetbrains.com/idea/plugin/7150-gradle-view

+0

. Спасибо, это было полезно, чтобы найти все версии и возможные обновления. –

+0

Для проверки обновлений зависимостей -> вы можете проверить [этот ответ для встроенной функции Android Studio] (http://stackoverflow.com/a/28683488/1235698) или [этот, для чистого градиента на основе] (http://stackoverflow.com/a/41958982/1235698). –

2

Я заметил, что ваш build.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" 
    } 

Я предполагаю, что это ткань SDK, который использует переоснащения в соответствии с build.gradle на их GitHub репо : путь к классам '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, как и для перехватчика. Думаю, вам не нужно использовать более старую версию –