安装 Android Studio 0.5.1 时,我收到以下消息:
The project is using an unsupported version of the Android Gradle plug-in (0.7.3). Version 0.9.0 introduced incompatible changes in the build language. Please read the migration guide to learn how to update your project.
我一直在尝试迁移我的项目,应用程序工作得很好,但我无法运行我的 Robotium 测试用例。
这是我尝试过的:
- Changed build.gradle from 0.7 to 0.9: classpath 'com.android.tools.build:gradle:0.9.+'
- Updated the gradle-wrapper.properties from distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip to distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
- Following the guide at http://tools.android.com/tech-docs/new-build-system/migrating_to_09 that tells me to rename the testfolder to androidTest and to update test dependencies from instrumentTestCompile to androidTestCompile, i am now using androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.0.1'
我的 build.gradle 文件如下所示
apply plugin: 'android'
sourceSets {
main {
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/res']
}
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.2'
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 116
versionName "1.5.5"
}
defaultConfig {
testPackageName "com.foo.androidTest"
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'org.apache.commons:commons-lang3:3.0'
compile 'com.jayway.android.robotium:robotium-solo:5.0.1'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.0.1'
}
我不知道我错过了什么,运行时我得到的只是:
java.lang.NoClassDefFoundError: com.foo.androidTest.TestSimple$1
at com.foo.androidTest.TestSimple.setUp(TestSimple.java:47)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1740)
如果您想知道 setUp 方法,它看起来像这样。
45: public void setUp() throws Exception {
46: solo = new Solo(getInstrumentation(), getActivity());
47: falseCondition = new Condition() {
48: @Override
49: public boolean isSatisfied() {
50: return false;
51: }
52: };
53: }
我没有更改任何 java 代码,我所做的只是安装 Android Studio 0.5.1,然后尝试迁移到 Gradle 0.9。
最佳答案
0.9 gradle 工具版本有一些问题
src\instrumentTest\java - 适用于 0.8.+ gradle 工具版本 src\androidTest\java - 不适用于 0.9.+ gradle 工具版本
关于android - 使用 Gradle 0.9 和 Android Studio 的 Robotium 测试用例,迁移到 Gradle 0.9 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22303950/