gpt4 book ai didi

android - 在 gradle 中没有库依赖的情况下,改造如何工作?

转载 作者:太空狗 更新时间:2023-10-29 16:29:59 26 4
gpt4 key购买 nike

所以我检查了我的代码,我注意到在任何 gradle 文件中都找不到改造依赖项。我的第一个想法是它 bundle 在另一个库中,所以我开始一个一个地排除它们,但我仍然无法弄清楚它在哪里。

问题 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;
}
}

顶级渐变:

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
}

应用程序等级:

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:2.3.1@aar') {
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'

最佳答案

使用 dependencies 任务可以很简单地列出所有项目依赖项以跟踪它们的来源:

gradlew app:dependencies

这将生成您可以进一步调查的报告 (docs: 4.7.4. Listing project dependencies)。

此外,如果喜欢的话,似乎还有一个名为“Gradle View”的 IDEA 插件:https://plugins.jetbrains.com/idea/plugin/7150-gradle-view

关于android - 在 gradle 中没有库依赖的情况下,改造如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41954216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com