How To Include Transitive Dependencies

拥有回忆 提交于 2019-12-10 10:29:18

问题


I have 2 gradle projects: an Android app and a RoboSpock test.

My build.gradle for the Android app has

. . .

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile ('com.actionbarsherlock:actionbarsherlock:4.4.0@aar') {
        exclude module: 'support-v4'
    }
}

. . .

and builds correctly by itself, e.g assembleRelease works.

I'm stuck getting the test to work. I gets lots of errors such as:

package com.google.zxing does not exist

Those seem to indicate that the .jar files aren't being picked up.

Here's my build.gradle for the test project:

buildscript {
  repositories {
    mavenLocal()
    mavenCentral()

  }
  dependencies {
      classpath 'com.android.tools.build:gradle:0.9.+'
      classpath 'org.robospock:robospock-plugin:0.4.0'

  }
}

repositories {
  mavenLocal()
  mavenCentral()
}

apply plugin: 'groovy'

dependencies {
    compile "org.codehaus.groovy:groovy-all:1.8.6"
    compile 'org.robospock:robospock:0.4.4'
}


dependencies {
    compile fileTree(dir: ':android:libs', include: '*.jar')
    compile (project(':estanteApp')) {
        transitive = true
    }
}

sourceSets.test.java.srcDirs = ['../android/src/', '../android/build/source/r/debug']

test {
    testLogging {
        lifecycle {
            exceptionFormat "full"
        }
    }

}

project.ext {
    robospock = ":estanteApp" // project to test
}


apply plugin: 'robospock'

As that shows, I've tried adding transitive = true and including the .jar files explicitly. But no matter what I try, I end up with the package does not exist error.


回答1:


In Android Studio you no longer need a different project for testing. Put your testing code in the same module under "src/androidTest/java"

Then add the following to "build.gradle" in the "defaultConfig"

testPackageName "com.yourpackage.test"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
testFunctionalTest true


来源:https://stackoverflow.com/questions/24090707/how-to-include-transitive-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!