Using android gradle + dagger to run instrumentTests

前端 未结 2 416
长发绾君心
长发绾君心 2021-02-06 11:24

I have began using Android Studio and gradle recently for android development and find it much better overall than eclipse/ant or maven. However I\'ve recently began trying to i

相关标签:
2条回答
  • 2021-02-06 11:56

    Ok, so I have been dealing with this problem for hours, and here is my fix: Put this in the dependencies of your build.gradle

    compile(project(':commons:statemachine')) {
        exclude module: 'junit'
        exclude module: 'json'
        exclude module: 'guava'
    }
    
    compile 'com.google.guava:guava:15.0'
    instrumentTestCompile files('libs/espresso-1.0-SNAPSHOT-bundled.jar')
    instrumentTestCompile 'com.squareup:fest-android:1.0.+'
    

    Add the espresso bundled jar in the libs folder of your test. Now comes the important part.

    Open that espresso bundled jar with WinRar or equivalent and go to com/ folder, then select de android folder and Delete it. Now close WinRar and compile and run your test :-)

    0 讨论(0)
  • 2021-02-06 11:58

    Took quite awhile but I finally got it working. I had to do the following:

    1. Declare my dependencies like so:

      dependencies {
        compile 'com.android.support:appcompat-v7:+'
        compile 'com.squareup.dagger:dagger-compiler:1.1.0'
        compile 'com.squareup.dagger:dagger:1.1.0'
      
        instrumentTestCompile files('libs/espresso-1.0-SNAPSHOT.jar','libs/testrunner-1.0-SNAPSHOT.jar','libs/testrunner-runtime-1.0-SNAPSHOT.jar')
        instrumentTestCompile files('libs/hamcrest-core-1.1.jar', 'libs/hamcrest-library-1.1.jar', 'libs/hamcrest-integration-1.1.jar')
        instrumentTestCompile 'com.google.guava:guava:14.0.1'
      }
      
    2. Copy the hamcrest jars from here

    3. Remove the license files from the jars like this (or else you'll get an error about duplicate LICENSE.txt files)

      zip -d hamcrest-core-1.1.jar LICENSE.txt
      zip -d hamcrest-library-1.1.jar LICENSE.txt
      
    4. Run gradle connectedCheck

    A few things to note:
    - Hamcrest 1.3 didn't work for me, got an error about a matcher was missing - Crazy how many hoops I had to jump through to get here.
    - Good luck getting this to play well with android studio.

    0 讨论(0)
提交回复
热议问题