問題描述
我正在嘗試按照 android studio 博客文章中的說明設置單元測試模塊.但是,進行 gradle 構建失敗并告訴我找不到名稱為 'debug-classes' 的配置".Debug 是它試圖構建的 targetVariant 的名稱,但我不明白這里出了什么問題.
I'm attempting to set up a unit test module as described in the android studio blog post. However, doing a gradle build fails telling me "Configuration with name 'debug-classes' not found". Debug is the name of the targetVariant it's trying to build, but I don't understand what is going wrong here.
這是我的測試模塊的 gradle 文件.
Here's my test module's gradle file.
apply plugin: 'com.android.test'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
targetProjectPath ':app'
targetVariant 'debug'
}
這是描述新測試模塊功能的博文.http://android-developers.blogspot.com/2015/07/get-your-hands-on-android-studio-13.html
This is the blogpost describing the new test module functionality. http://android-developers.blogspot.com/2015/07/get-your-hands-on-android-studio-13.html
我正在使用 Gradle 插件 v1.3.0
I'm using the Gradle plugin v1.3.0
推薦答案
我也對分離應用程序代碼和測試代碼感到好奇,我很難弄清楚.我查看堆棧跟蹤并找到 DependencyManager(第 238 行)有一個 TODO 可以在 gradle 中解決這個問題.
I was also curious about separating app code and test code and i had hard time to figure it out. I look at the stack trace and found the DependencyManager (line 238) having a TODO to fix that in gradle.
1) 你對構建風格的看法是正確的.你必須輸入正確的變體
1) You are right about the build flavors.You have to enter the correct variant
targetVariant '<flavor>Debug'
例如
targetVariant 'flavor1Debug'
2) 您還需要更改 targetProjectPath 的模塊 build.gradle.添加以下代碼段:
2) You also need to change you targetProjectPath's module build.gradle. Add the following snippet:
android {
// ...
publishNonDefault true
// ...
}
發布所有構建變體!由于 gradle 的一些限制,它默認禁用.
which publishes all build variants! It its disabled by default due to some limitations of gradle.
這篇關于Android 測試模塊(Gradle 插件 1.3)不起作用:“找不到調試類"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!