17

I am using Selenium in Java to make an app. I keep getting this error and I have been searching the internet to figure out what is wrong and I cannot find anything. Please help.

Here is my build.gradle:

    android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "luke.luke.seleniumtest"
        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:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation files('libs/byte-buddy-1.7.9.jar')
    implementation files('libs/client-combined-3.9.1.jar')
    implementation files('libs/commons-codec-1.10.jar')
    implementation files('libs/commons-exec-1.3.jar')
    implementation files('libs/commons-logging-1.2.jar')
    implementation files('libs/gson-2.8.2.jar')
    implementation files('libs/guava-23.6-jre.jar')
    implementation files('libs/httpclient-4.5.3.jar')
    implementation files('libs/httpcore-4.4.6.jar')
    implementation files('libs/okhttp-3.9.1.jar')
    implementation files('libs/okio-1.13.0.jar')
}
LUKER
  • 540
  • 1
  • 5
  • 23

3 Answers3

36

The simple solution instead of excluding it is to just do

android {
    packagingOptions {
        pickFirst  'META-INF/*'
    }
}
Brent
  • 740
  • 1
  • 5
  • 11
21

First, try to add this line: exclude 'META-INF/DEPENDENCIES', then Run 'app'

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }
}

If error continue occur: 'META-INF/INDEX.LIST', keep adding exclude 'META-INF/INDEX.LIST':

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/INDEX.LIST'
    }
}

Success for me!

TedVN
  • 536
  • 5
  • 10
  • This forced me to change my minsdk to 26. It also lead to: java.lang.RuntimeException: Unable to instantiate activity – LUKER Nov 03 '18 at 03:00
  • I added youtube library then i was facing this issue. in my case second answer worked for me. – Deepak Maurya Oct 25 '20 at 05:18
2

try add packagingOptions

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
    }
}
sanemars
  • 767
  • 5
  • 18
  • Then I get the error: Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/luke/AndroidStudioProjects/SeleniumTest/app/libs/client-combined-3.9.1.jar Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing org/openqa/selenium/logging/LogCombiner.class. Error:com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26) – LUKER Feb 24 '18 at 03:16
  • what is your gradle version? and check [this](https://stackoverflow.com/questions/47137483/android-studio-3-0-dexarchivebuilderexception) – sanemars Feb 24 '18 at 03:23
  • change minSdkVersion to 26 – sanemars Feb 24 '18 at 03:42
  • That will not work for my app. It will allow very few people to use it. – LUKER Feb 24 '18 at 03:44
  • @LUKER did you find any solution, I am facing the same problem. – Sajid Zeb Jul 31 '18 at 10:50
  • @SajidZeb I did not, have you yet? – LUKER Nov 03 '18 at 03:04