当前位置: 首页 > 知识库问答 >
问题:

找到多个具有操作系统独立路径“meta-inf/proguard/okhttp3.pro”的文件

胡璞瑜
2023-03-14

我正在尝试okhttp,但出现下一个错误:\

找到多个具有操作系统独立路径“meta-inf/proguard/okhttp3.pro”的文件

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'
}
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
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'
}

找到多个具有操作系统独立路径“okhttp3/internal/publicsuffix/publicsuffix.gz”的文件

所以我添加到packagingOptions{}

排除“OKHTTP3/internal/publicsuffix/publicsuffixes.gz”

编译未能完成

Android问题:

程序类型已存在:OKHTTP3.Call$Factory消息{Kind=错误,Text=程序类型已存在:OKHTTP3.Call$Factory,Sources=[未知源文件],tool Name=可选.of(D8)}

共有1个答案

段干博涉
2023-03-14

看起来您的构建试图在二进制文件中包含OkHttp的多个副本。您的任何依赖项是否包括它们自己的OKHTTP副本?你包括多个版本吗?

 类似资料: