我有一个全新安装的Android Studio和一个新的Android项目。我创建了一个JUnit测试类但我无法运行它:
"C:\Program Files\Java\jdk1.7.0_55\bin\java" -ea -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files\android-studio\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\android-studio\lib\idea_rt.jar;C:\Program Files\android-studio\plugins\junit\lib\junit-rt.jar;D:\Dev\android-sdks\platforms\android-21\android.jar;D:\Dev\android-sdks\platforms\android-21\data\res;D:\Dev\android-sdks\tools\support\annotations.jar;d:\myapp\mobile\build\intermediates\classes\debug;D:\jon\.gradle\caches\modules-2\files-2.1\com.j256.ormlite\ormlite-android\4.48\afa06f539a4026c10b247386312aa67404b80a16\ormlite-android-4.48.jar;D:\jon\.gradle\caches\modules-2\files-2.1\commons-io\commons-io\2.0.1\7ffdb02f95af1c1a208544e076cea5b8e66e731a\commons-io-2.0.1.jar;D:\Dev\android-sdks\extras\android\m2repository\com\android\support\support-annotations\21.0.2\support-annotations-21.0.2.jar;D:\jon\.gradle\caches\modules-2\files-2.1\com.j256.ormlite\ormlite-core\4.48\e579bd2905d0399af5029aaaf9817d5fa0ca88a5\ormlite-core-4.48.jar;d:\myapp\mobile\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.2\res;d:\myapp\mobile\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.2\libs\internal_impl-21.0.2.jar;d:\myapp\mobile\build\intermediates\exploded-aar\com.android.support\support-v4\21.0.2\classes.jar;D:\jon\.gradle\caches\modules-2\files-2.1\com.squareup.dagger\dagger\1.2.2\e8f912ee19ad84958510883ea191135276b091f8\dagger-1.2.2.jar;D:\jon\.gradle\caches\modules-2\files-2.1\javax.inject\javax.inject\1\6975da39a7040257bd51d21a231b76c915872d38\javax.inject-1.jar;D:\jon\.gradle\caches\modules-2\files-2.1\org.androidannotations\androidannotations-api\3.2\89b33bb1e996eb2c4089f79d1b8651c71fe8e2d1\androidannotations-api-3.2.jar;D:\jon\.gradle\caches\modules-2\files-2.1\com.squareup\otto\1.3.5\7941cd2c2c8ec006800d75c35f8a9dacf892ab93\otto-1.3.5.jar;d:\myapp\mobile\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.1.71\classes.jar;d:\myapp\mobile\build\intermediates\exploded-aar\com.google.android.gms\play-services\6.1.71\res;d:\myapp\mobile\build\intermediates\exploded-aar\net.danlew\android.joda\2.5.1\classes.jar;d:\myapp\mobile\build\intermediates\exploded-aar\net.danlew\android.joda\2.5.1\res;D:\jon\.gradle\caches\modules-2\files-2.1\org.robobinding\robobinding\0.8.9\c6b50ddd9e741a7c8e54b56ac7057a66312a3e11\robobinding-0.8.9-with-dependencies.jar;d:\myapp\javamail\build\intermediates\classes\debug" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.example.MyUnitTest
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
这是我第一次尝试使用Android Studio并进行JUnit测试。很抱歉,如果解决方案很明显。
答案 0 :(得分:2)
以下解决方案在Windows中为我工作:
1)在环境变量中添加一个新的“系统变量” ANDROID_SDK_HOME = D:\ Program Files \ android-sdk-windows(选择你的android sdk主目录)
2)修改系统变量Path,添加“%Android_SDK_HOME%\ tools;”