当我们将android项目升级到java8时,connectedAndroidTest停止在Kitkat设备上运行Robotium测试。但是相同的代码在Lollipop和更高的Android版本上运行良好,甚至在kitkat上运行时从Android Studio执行时运行正常。但是一旦我们切换到./gradlew cAT
,它就会停止在具有以下日志的kitkat设备上执行:
如果使用AndroidJUnitRunner执行执行,则会显示以下错误:
18:29:56.902 [LIFECYCLE] [org.gradle.api.Task] Starting 0 tests on Titanium Octane Plus - 4.4.2
18:29:56.903 [WARN] [org.gradle.api.Task] Tests on Titanium Octane Plus - 4.4.2 failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'
18:29:56.939 [INFO] [org.gradle.api.Task] [XmlResultReporter]: XML test result file generated at /Users/sil/Workspace/Android/LrAndroid/dev-eng/Thio/android/build/outputs/androidTest-results/connected/TEST-Titanium Octane Plus - 4.4.2-android-.xml. Total tests 0,
18:29:56.939 [INFO] [com.android.build.gradle.internal.ApplicationTaskManager] [XmlResultReporter]: XML test result file generated at /Users/sil/Workspace/Android/LrAndroid/dev-eng/Thio/android/build/outputs/androidTest-results/connected/TEST-Titanium Octane Plus - 4.4.2-android-.xml. Total tests 0,
18:29:57.108 [WARN] [org.gradle.api.Task]
com.android.builder.testing.ConnectedDevice > No tests found.[Titanium Octane Plus - 4.4.2] FAILED
18:29:57.109 [WARN] [org.gradle.api.Task] No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
但如果使用了orchestrator,则会显示以下日志:
12:13:48.953 [LIFECYCLE] [org.gradle.api.Task] Starting 0 tests on Titanium Octane Plus - 4.4.2
12:13:48.963 [INFO] [org.gradle.api.Task] [XmlResultReporter]: XML test result file generated at /Users/sil/Workspace/Android/LrAndroid/dev-eng/Thio/android/build/outputs/androidTest-results/connected/TEST-Titanium Octane Plus - 4.4.2-android-.xml. Total tests 0,
12:13:48.963 [INFO] [org.gradle.api.Task] [XmlResultReporter]: XML test result file generated at /Users/sil/Workspace/Android/LrAndroid/dev-eng/Thio/android/build/outputs/androidTest-results/connected/TEST-Titanium Octane Plus - 4.4.2-android-.xml. Total tests 0,
12:13:48.963 [INFO] [org.gradle.api.Task] [XmlResultReporter]: XML test result file generated at /Users/sil/Workspace/Android/LrAndroid/dev-eng/Thio/android/build/outputs/androidTest-results/connected/TEST-Titanium Octane Plus - 4.4.2-android-.xml. Total tests 0,
12:13:48.963 [INFO] [org.gradle.api.Task] [XmlResultReporter]: XML test result file generated at /Users/sil/Workspace/Android/LrAndroid/dev-eng/Thio/android/build/outputs/androidTest-results/connected/TEST-Titanium Octane Plus - 4.4.2-android-.xml. Total tests 0,
12:13:48.963 [INFO] [com.android.build.gradle.internal.ApplicationTaskManager] [XmlResultReporter]: XML test result file generated at /Users/sil/Workspace/Android/LrAndroid/dev-eng/Thio/android/build/outputs/androidTest-results/connected/TEST-Titanium Octane Plus - 4.4.2-android-.xml. Total tests 0,
12:13:48.995 [WARN] [org.gradle.api.Task]
com.android.builder.testing.ConnectedDevice > No tests found.[Titanium Octane Plus - 4.4.2] FAILED
12:13:48.995 [WARN] [org.gradle.api.Task] No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
build.gradle中使用java8所做的更改是:
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
期待解决为什么问题仅在Kitkat和较低设备上发生的解决方法/解释(尽管我对Android版本低于kitkat的设备并不感到烦恼)。
答案 0 :(得分:0)
问题是由于未在build.gradle中定义用于测试代码的Java源目录。所以以前的代码就像
instrumentTest.setRoot('tests')
或
androidTest.setRoot('tests')
将其更新为以下内容即可解决问题。
androidTest {
setRoot('tests')
java.srcDirs = ['src/androidTest/java']
manifest.srcFile file('src/androidTest/AndroidManifest.xml')
}