В Gradle, как мне указать, что моя реализация androidTest должна зависеть от версии выпуска модуля проекта? - PullRequest
0 голосов
/ 05 сентября 2018

Я пытаюсь написать тест производительности в Android Studio, используя InstrumentedTest. Я сделал отдельный модуль только для моего теста производительности. Это зависит от других модулей в проекте. Чтобы сделать мой тест производительности точным, я бы хотел, чтобы мой модуль performancetest зависел от конфигураций release других модулей.

Например, если у меня есть три модуля в моем проекте: - :foo - :bar - :performancetest

Я хочу, чтобы ExampleInstrumentedTest в модуле :performancetest осуществлял упражнения и измерял версии версий :foo и :bar.

Как мне это настроить? Я пытаюсь использовать:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    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 project(path: ':foo', configuration: 'release')
    implementation project(path: ':bar', configuration: 'release')
}

но когда я синхронизирую его, я получаю эту ошибку:

Execution failed for task ':performancetest:androidDependencies'.
> Could not resolve all artifacts for configuration ':performancetest:debugCompileClasspath'.
   > Could not resolve project :foo.
     Required by:
         project :performancetest
      > Project :performancetest declares a dependency from configuration 'implementation' to configuration 'release' which is not declared in the descriptor for project :foo.

но я определенно могу собрать релизную версию :foo.

Как я могу объявить, что мой :performancetest полагается на релиз версий :foo и :bar?

1 Ответ

0 голосов
/ 11 сентября 2018

Кажется, я понял это.

performancetest.build.gradle

android {
    // We want our performance test to run with the _release_ version of our libraries
    // so we make the test type "release" which will choose the release version of all the
    // modules
    // However, I get a signing error when Android has run a test apk built with the release
    // build type. So, by inheriting the debug buildType into the release configuration, we
    // end up with:
    //
    // 1. release versions of all our library code
    // 2. debug version of the testing code with debug apk packaging.
    //
    // This runs successfully on the devices.
    testBuildType "release"
    buildTypes {
        release {
            initWith debug
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...