Android 发现多个文件具有独立于操作系统的路径';META-INF/proguard/okhttp3.pro';
我正在尝试okhttp,出现下一个错误:\ 找到多个具有操作系统独立路径的文件 'META-INF/proguard/okhttp3.pro' 这就是我的身材,格雷德尔Android 发现多个文件具有独立于操作系统的路径';META-INF/proguard/okhttp3.pro';,android,okhttp,okhttp3,Android,Okhttp,Okhttp3,我正在尝试okhttp,出现下一个错误:\ 找到多个具有操作系统独立路径的文件 'META-INF/proguard/okhttp3.pro' 这就是我的身材,格雷德尔 apply plugin: 'com.android.application' android { compileSdkVersion 28 defaultConfig { applicationId "com.woooba.login2" minSdkVersion 23
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新手
谢谢
更新
proguard-rules.pro代码按照@vivek请求显示
# 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,下一步:
按下“立即同步”并播放,错误消失,但当您转到4:run时,我看到另一个错误
找到多个具有操作系统独立路径的文件
'okhttp3/internal/publicsuffix/publicsuffixes.gz'
所以我在packagingOptions中添加了{}
排除“okhttp3/internal/publicsuffixes/publicsuffixes.gz”
我得到了下一个错误
编译未能完成
Android问题:
程序类型已存在:okhttp3.Call$Factory消息{kind=ERROR,
text=程序类型已存在:okhttp3.调用$Factory,
sources=[未知源文件],工具名=可选.of(D8)}
有什么想法吗?我已经看到有人建议删除okhttp3的实现,但是在MainActivity中调用这个类时出现了错误
OkHttpClient=新的OkHttpClient()
看起来您的构建试图在二进制文件中包含OkHttp的多个副本。您的依赖项是否包含自己的OkHttp副本?是否包含多个版本?显示您的proguardfile@VivekMishra完成。我在那里什么也没有。谢谢VivekMishra。尝试了该操作和其他说明,但仍然存在问题。如果没有尝试使用okhttp libraryHi@Jesse的旧版本。谢谢你的回复。这是安卓的一个新项目。只是玩玩而已。您可以看到以上所有依赖项。问题可能来自此默认创建的实现?>实现文件树(dir:'libs',include:['*.jar'])我不这么认为,因为当我删除实现'com.squareup.okhttp3:okhttp:3.11.0'时,我调用okhttp3类时出错
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'
}