Android 测试模块(Gradle 插件 1.3)不起作用:“找不到调试类"

2023-02-01移动开发问题
7

本文介绍了Android 测试模块(Gradle 插件 1.3)不起作用:“找不到调试类"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试按照 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)不起作用:“找不到调试类"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何在 COCOS2d Android 中使用 CClistview?
How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)...
2024-08-12 移动开发问题
5

cocos2d-android:如何显示分数
cocos2d-android: how to display score(cocos2d-android:如何显示分数)...
2024-08-11 移动开发问题
7

Sqlite 数据库未从资产文件夹 Android 复制
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)...
2024-04-15 移动开发问题
8

SQLite 数据库副本在由设备而不是模拟器生成时出现损坏
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)...
2024-04-15 移动开发问题
4

安卓文件拷贝
Android file copy(安卓文件拷贝)...
2024-04-15 移动开发问题
6

Android如何在android中检测Edittext的Copy事件
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)...
2024-04-15 移动开发问题
5