我正在尝试okhttp,并且遇到下一个错误:\
发现多个文件具有与操作系统无关的路径 'META-INF / proguard / okhttp3.pro'
这是我在build.gradle中拥有的
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.woooba.login2"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
这是MainActivity.java
OkHttpClient client = new OkHttpClient();
String u = "https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22k";
task.execute(u);
Request request = new Request.Builder().url(u).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()){
Log.i("Response", response.body().string());
}
}
});
有人知道会发生什么吗?它说“发现一个文件不止一个”,但不确定它在说什么。我是android新手
谢谢
更新 根据@vivek请求显示的proguard-rules.pro代码
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
更新2 在android {}中添加到build.grade下一个: link
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/proguard/okhttp3.pro'
}
按下“立即同步”并播放,错误消失了,但是当您转到4:run时,我看到了另一个错误。
发现多个文件具有与操作系统无关的路径 'okhttp3 / internal / publicsuffix / publicsuffixes.gz'
所以我添加到PackagingOptions {}
排除“ okhttp3 / internal / publicsuffix / publicsuffixes.gz”
我收到下一个错误
编译失败
Android问题:
程序类型已经存在:okhttp3.Call $ Factory Message {kind = ERROR, text =程序类型已经存在:okhttp3.Call $ Factory, sources = [未知源文件],工具名称= Optional.of(D8)}
有什么主意吗?我见过here,建议删除okhttp3的实现,但是当我在MainActivity中调用此类时出现错误
OkHttpClient客户=新的OkHttpClient();
答案 0 :(得分:0)
看起来您的构建正在尝试在二进制文件中包含OkHttp的多个副本。您的任何依赖项都包括自己的OkHttp副本吗?您包括多个版本吗?