首页 > 解决方案 > 将 jars 作为库添加到 Android Studio,错误:发现多个文件与操作系统无关路径 'META-INF/DEPENDENCIES'

问题描述

我正在尝试将 Selenium 添加到 Android Studio,以便在设备处于待机模式时自动化 Web 表单。我不断遇到越来越多的错误。我将所有 .jars 添加到 Lib 文件中并将它们添加为库,然后我遇到了这个问题。请帮我。这是我的毕业典礼:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "mul.luke.selenium"
        minSdkVersion 15
        targetSdkVersion 26
        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(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    implementation files('libs/byte-buddy-1.7.9.jar')
    implementation files('libs/okio-1.13.0.jar')
    implementation files('libs/okhttp-3.9.1.jar')
    implementation files('libs/httpcore-4.4.6.jar')
    implementation files('libs/httpclient-4.5.3.jar')
    implementation files('libs/guava-23.6-jre.jar')
    implementation files('libs/gson-2.8.2.jar')
    implementation files('libs/commons-logging-1.2.jar')
    implementation files('libs/commons-exec-1.3.jar')
    implementation files('libs/commons-codec-1.10.jar')
    implementation files('libs/client-combined-3.11.0-sources.jar')
    implementation files('libs/client-combined-3.11.0.jar')
}

标签: androidandroid-studiogradleweb-scrapingbots

解决方案


implementation fileTree(include: ['*.jar'], dir: 'libs')

以上将包括库中的所有罐子。正确的?

您正在尝试使用特定路径再次添加相同的库。

implementation files('libs/byte-buddy-1.7.9.jar')

排除 PackagingOptions 中的依赖项,

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "mul.luke.selenium"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
     packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
      }

}

推荐阅读