本文介绍了仪表运行失败,原因是“java.lang.IllegalAccessError”。摇篮+居preSSO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用ES preSSO试验的摇篮。要做到这一点我试图用双ES preSSO 通过杰克·沃顿的,但它不工作
我读过,它可以被复制的依赖关系,但我已经排除匕首和支持-V4库,就像杰克在他的自述中写道。
谁能给我建议什么可能是错在这里?
测试类:
包info.korzeniowski.myapp.test;
进口android.test.ActivityInstrumentationTestCase2;
进口android.test.suitebuilder.annotation.LargeTest;
进口info.korzeniowski.myapp.R;
进口info.korzeniowski.myapp.activity.MainActivity_;
进口静电com.google.android.apps.common.testing.ui.es presso.Es presso.onView;
引入静态com.google.android.apps.common.testing.ui.es presso.assertion.ViewAssertions.matches;
进口静电com.google.android.apps.common.testing.ui.es presso.contrib.DrawerActions.closeDrawer;
进口静电com.google.android.apps.common.testing.ui.es presso.contrib.DrawerActions.openDrawer;
进口静电com.google.android.apps.common.testing.ui.es presso.contrib.DrawerMatchers.isClosed;
进口静电com.google.android.apps.common.testing.ui.es presso.contrib.DrawerMatchers.isOpen;
进口静电com.google.android.apps.common.testing.ui.es presso.matcher.ViewMatchers.withId;
公共类基本试验扩展ActivityInstrumentationTestCase2< MainActivity_> {
公共基本试验(){
超(MainActivity_.class);
}
@覆盖
保护无效设置()抛出异常{
super.setUp();
getActivity();
}
@LargeTest
公共无效testOpenAndCloseDrawer(){
。OnView为(withId(R.id.drawer_layout))检查(匹配(在isClosed()));
openDrawer(R.id.drawer_layout);
。OnView为(withId(R.id.drawer_layout))检查(场(isOpen()函数));
closeDrawer(R.id.drawer_layout);
。OnView为(withId(R.id.drawer_layout))检查(匹配(在isClosed()));
}
}
build.gradle:
buildscript {
高清androidGradlePluginVersion =0.9 +
高清androidAptVersion =1.2+
库{
mavenCentral()
}
依赖{
类路径com.android.tools.build:gradle:${androidGradlePluginVersion}
类路径com.neenbedankt.gradle.plugins:Android的贴切:$ {androidAptVersion}
}
}
库{
mavenCentral()
mavenLocal()
}
应用插件:'机器人'
应用插件:Android的容易
易于 {
参数{
androidManifestFile variant.processResources.manifestFile
resourcePackageNameinfo.korzeniowski.myapp
}
}
安卓{
compileSdkVersion 19
buildToolsVersion19.0.3
defaultConfig {
的minSdkVersion 10
targetSdkVersion 19
}
buildTypes {
推出 {
runProguard假
proguardFiles getDefaultProguardFile('ProGuard的-android.txt'),'ProGuard的-rules.txt
}
}
lintOptions {
abortOnError假
}
packagingOptions {
排除的LICENSE.txt
}
}
高清androidSupportVersion = '19 .0 +
高清greenDaoVersion =1.3 +
高清androidAnnotationsVersion =2.7.1
高清daggerVersion =1.2.1
依赖{
//支持Android
编译com.android.support:support-v4:${androidSupportVersion}
编译com.android.support:appcompat-v7:${androidSupportVersion}
// Android的注解
容易com.google code.androidannotations:androidannotations:$ {androidAnnotationsVersion}
编译com.google code.androidannotations:androidannotations-API:$ {androidAnnotationsVersion}
// 匕首
容易com.squareup.dagger:匕首编译:$ {daggerVersion}
编译com.squareup.dagger:短剑:$ {daggerVersion}
//居preSSO
androidTestCompile('com.jakewharton.es preSSO:ES preSSO:1.1-R2'){
排除组:com.squareup.dagger',模块:匕首
}
androidTestCompile('com.jakewharton.es preSSO:ES preSSO支持-V4:1.1-R2'){
排除组:com.android.support',模块:支持-V4
}
}
测试结果:
运行测试
试运行开始
测试未能完成运行。原因是:规范运行失败,原因是java.lang.IllegalAccessError'。检查设备logcat的详细信息
试运行失败:仪器仪表运行失败,原因是java.lang.IllegalAccessError
logcat的:
12月3号至18日:52:12.168 274-443 / system_process I / ActivityManager:启动PROC info.korzeniowski.myapp的增值应用info.korzeniowski.myapp:PID = 2998 UID = 10049导报= {50049,1028}
十二月3日至18号:52:27.417 2998年至2998年/? I / dalvikvm:未能解决Lorg / hamcrest /集成/ EasyMock2Adapter;接口2417Lorg / EasyMock的/ IArgumentMatcher;
十二月3日至18号:52:27.417 2998年至2998年/? W / dalvikvm:Link类的Lorg / hamcrest /集成/ EasyMock2Adapter;失败
十二月3日至18号:52:27.537 2998年至2998年/? W / ClassPathPackageInfoSource:无法加载类。请确保它在你的apk。分类名称:org.hamcrest.integration.EasyMock2Adapter。消息:org.hamcrest.integration.EasyMock2Adapter
抛出java.lang.ClassNotFoundException:org.hamcrest.integration.EasyMock2Adapter
在java.lang.Class.classForName(本机方法)
在java.lang.Class.forName(Class.java:204)
在android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
在android.test.ClassPathPackageInfoSource.access $ 000(ClassPathPackageInfoSource.java:39)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:50)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:47)
在android.test.SimpleCache.get(SimpleCache.java:31)
在android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
在android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
在android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
在android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
在android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
在android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
在android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
在android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
在android.app.ActivityThread.access $ 1300(ActivityThread.java:141)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5103)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
在dalvik.system.NativeStart.main(本机方法)
java.lang.NoClassDefFoundError的:通过引起组织/ hamcrest /集成/ EasyMock2Adapter
在java.lang.Class.classForName(本机方法)
在java.lang.Class.forName(Class.java:204)
在android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
在android.test.ClassPathPackageInfoSource.access $ 000(ClassPathPackageInfoSource.java:39)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:50)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:47)
在android.test.SimpleCache.get(SimpleCache.java:31)
在android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
在android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
在android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
在android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
在android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
在android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
在android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
在android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
在android.app.ActivityThread.access $ 1300(ActivityThread.java:141)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5103)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
在dalvik.system.NativeStart.main(本机方法)
抛出java.lang.ClassNotFoundException:产生的原因没有找到类org.hamcrest.integration.EasyMock2Adapter的路径:DexPathList [zip文件/system/framework/android.test.runner.jar,zip文件/数据/应用/ info.korzeniowski.myapp.test-1.apk,zip文件"/data/app/info.korzeniowski.myapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/info.korzeniowski.myapp.test-1, /data/app-lib/info.korzeniowski.myapp-1,/系统/ lib目录]
在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
在java.lang.ClassLoader.loadClass(ClassLoader.java:501)
在java.lang.ClassLoader.loadClass(ClassLoader.java:461)
在java.lang.Class.classForName(本机方法)
在java.lang.Class.forName(Class.java:204)
在android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
在android.test.ClassPathPackageInfoSource.access $ 000(ClassPathPackageInfoSource.java:39)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:50)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:47)
在android.test.SimpleCache.get(SimpleCache.java:31)
在android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
在android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
在android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
在android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
在android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
在android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
在android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
在android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
在android.app.ActivityThread.access $ 1300(ActivityThread.java:141)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5103)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
在dalvik.system.NativeStart.main(本机方法)
十二月3日至18号:52:27.537 2998年至2998年/? I / dalvikvm:未能解决Lorg / hamcrest /集成/ JMock1Adapter;接口2468Lorg / JMock的/核心/约束;
十二月3日至18号:52:27.537 2998年至2998年/? W / dalvikvm:Link类的Lorg / hamcrest /集成/ JMock1Adapter;失败
十二月3日至18号:52:27.587 2998年至2998年/? W / ClassPathPackageInfoSource:无法加载类。请确保它在你的apk。分类名称:org.hamcrest.integration.JMock1Adapter。消息:org.hamcrest.integration.JMock1Adapter
抛出java.lang.ClassNotFoundException:org.hamcrest.integration.JMock1Adapter
在java.lang.Class.classForName(本机方法)
在java.lang.Class.forName(Class.java:204)
在android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
在android.test.ClassPathPackageInfoSource.access $ 000(ClassPathPackageInfoSource.java:39)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:50)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:47)
在android.test.SimpleCache.get(SimpleCache.java:31)
在android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
在android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
在android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
在android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
在android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
在android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
在android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
在android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
在android.app.ActivityThread.access $ 1300(ActivityThread.java:141)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5103)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
在dalvik.system.NativeStart.main(本机方法)
java.lang.NoClassDefFoundError的:通过引起组织/ hamcrest /集成/ JMock1Adapter
在java.lang.Class.classForName(本机方法)
在java.lang.Class.forName(Class.java:204)
在android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
在android.test.ClassPathPackageInfoSource.access $ 000(ClassPathPackageInfoSource.java:39)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:50)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:47)
在android.test.SimpleCache.get(SimpleCache.java:31)
在android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
在android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
在android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
在android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
在android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
在android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
在android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
在android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
在android.app.ActivityThread.access $ 1300(ActivityThread.java:141)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5103)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
在dalvik.system.NativeStart.main(本机方法)
抛出java.lang.ClassNotFoundException:产生的原因没有找到类org.hamcrest.integration.JMock1Adapter的路径:DexPathList [zip文件/system/framework/android.test.runner.jar,zip文件/数据/应用/ info.korzeniowski.myapp.test-1.apk,zip文件"/data/app/info.korzeniowski.myapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/info.korzeniowski.myapp.test-1, /data/app-lib/info.korzeniowski.myapp-1,/系统/ lib目录]
在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
在java.lang.ClassLoader.loadClass(ClassLoader.java:501)
在java.lang.ClassLoader.loadClass(ClassLoader.java:461)
在java.lang.Class.classForName(本机方法)
在java.lang.Class.forName(Class.java:204)
在android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
在android.test.ClassPathPackageInfoSource.access $ 000(ClassPathPackageInfoSource.java:39)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:50)
在android.test.ClassPathPackageInfoSource $ 1.load(ClassPathPackageInfoSource.java:47)
在android.test.SimpleCache.get(SimpleCache.java:31)
在android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
在android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
在android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
在android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
在android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
在android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
在android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
在android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
在android.app.ActivityThread.access $ 1300(ActivityThread.java:141)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5103)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
在dalvik.system.NativeStart.main(本机方法)
十二月3日至18号:52:28.477 2998-3011 /? I / TestRunner的:开始:testOpenAndCloseDrawer(info.korzeniowski.myapp.test.BasicTest)
十二月3日至18号:52:28.497 274-439 / system_process I / ActivityManager:从PID 2998启动U0 {行动= android.intent.action.MAIN FLG = 0x10000000处CMP = info.korzeniowski.myapp / .activity.MainActivity_}
十二月3日至18号:52:28.617 2998年至2998年/? I / greenDAO:为架构版本1创建表
十二月3日至18号:52:28.687 2998年至2998年/? W / dalvikvm:一类以意想不到的DEX解决:LINFO /科尔泽尼奥夫斯基/ MyApp的/ MyApp的;(0x416fc6a8):0x73054000文献[Ldagger / ObjectGraph] Ldagger / ObjectGraph;(0x416fc6a8):0x72ec8000
十二月3日至18号:52:28.687 2998年至2998年/? W / dalvikvm:(LINFO /科尔泽尼奥夫斯基/ MyApp的/ MyApp的,已经使用了不同的Ldagger / ObjectGraph;在pre-验证)
十二月3日至18号:52:28.697 2998年至2998年/? W / dalvikvm:主题ID = 1:螺纹退出与未捕获的异常(组= 0x41465700)
十二月3日至18号:52:28.738 2998年至2998年/? E / AndroidRuntime:致命异常:主要
java.lang.IllegalAccessError:类文献在pre-核实级解决意外的执行
在info.korzeniowski.myapp.MyApp.onCreate(MyApp.java:32)
在android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
在android.app.ActivityThread.access $ 1300(ActivityThread.java:141)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5103)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:525)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
在dalvik.system.NativeStart.main(本机方法)
十二月3日至18号:52:28.738 274-286 / system_process W / ActivityManager:在应用info.korzeniowski.myapp运行仪器误差ComponentInfo {info.korzeniowski.myapp.test / android.test.InstrumentationTestRunner}:
十二月3日至18号:52:28.738 274-286 / system_process W / ActivityManager:java.lang.IllegalAccessError
十二月3日至18号:52:28.738 274-286 / system_process W / ActivityManager:java.lang.IllegalAccessError:类文献在pre-核实级解决意外implementationF
解决方案
由于类没有在 org.hamcrest.integration
包中,尽量排除。然后,你对你的依赖性看起来像
//居preSSO
androidTestCompile('com.jakewharton.es preSSO:ES preSSO:1.1-R2'){
排除组:com.squareup.dagger',模块:匕首
排除组:org.hamcrest',模块:hamcrest整合
}
androidTestCompile('com.jakewharton.es preSSO:ES preSSO支持-V4:1.1-R2'){
排除组:com.android.support',模块:支持-V4
以下行//不知道是否有必要
排除组:org.hamcrest',模块:hamcrest整合
}
I want to use espresso tests with gradle. To do that I tried to use double-espresso by Jake Wharton, but it doesn't work.
I've read that it could be duplicated dependencies, but I have excluded Dagger and Support-v4 libs, like Jake wrote in his README.
Can anyone give me advice on what could be wrong here?
test class:
package info.korzeniowski.myapp.test;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import info.korzeniowski.myapp.R;
import info.korzeniowski.myapp.activity.MainActivity_;
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerActions.closeDrawer;
import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerActions.openDrawer;
import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerMatchers.isClosed;
import static com.google.android.apps.common.testing.ui.espresso.contrib.DrawerMatchers.isOpen;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
public class BasicTest extends ActivityInstrumentationTestCase2<MainActivity_> {
public BasicTest() {
super(MainActivity_.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
getActivity();
}
@LargeTest
public void testOpenAndCloseDrawer() {
onView(withId(R.id.drawer_layout)).check(matches(isClosed()));
openDrawer(R.id.drawer_layout);
onView(withId(R.id.drawer_layout)).check(matches(isOpen()));
closeDrawer(R.id.drawer_layout);
onView(withId(R.id.drawer_layout)).check(matches(isClosed()));
}
}
build.gradle:
buildscript {
def androidGradlePluginVersion= '0.9.+'
def androidAptVersion = '1.2+'
repositories {
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:${androidGradlePluginVersion}"
classpath "com.neenbedankt.gradle.plugins:android-apt:${androidAptVersion}"
}
}
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'android'
apply plugin: 'android-apt'
apt {
arguments {
androidManifestFile variant.processResources.manifestFile
resourcePackageName 'info.korzeniowski.myapp'
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
packagingOptions {
exclude 'LICENSE.txt'
}
}
def androidSupportVersion = '19.0.+'
def greenDaoVersion = '1.3.+'
def androidAnnotationsVersion = '2.7.1'
def daggerVersion = '1.2.1'
dependencies {
// Android Support
compile "com.android.support:support-v4:${androidSupportVersion}"
compile "com.android.support:appcompat-v7:${androidSupportVersion}"
// Android Annotations
apt "com.googlecode.androidannotations:androidannotations:${androidAnnotationsVersion}"
compile "com.googlecode.androidannotations:androidannotations-api:${androidAnnotationsVersion}"
// Dagger
apt "com.squareup.dagger:dagger-compiler:${daggerVersion}"
compile "com.squareup.dagger:dagger:${daggerVersion}"
// Espresso
androidTestCompile ('com.jakewharton.espresso:espresso:1.1-r2') {
exclude group: 'com.squareup.dagger', module: 'dagger'
}
androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r2') {
exclude group: 'com.android.support', module: 'support-v4'
}
}
Test results:
Running tests
Test running started
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'java.lang.IllegalAccessError''. Check device logcat for details
Test running failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'
Logcat:
3-18 12:52:12.168 274-443/system_process I/ActivityManager﹕ Start proc info.korzeniowski.myapp for added application info.korzeniowski.myapp: pid=2998 uid=10049 gids={50049, 1028}
03-18 12:52:27.417 2998-2998/? I/dalvikvm﹕ Failed resolving Lorg/hamcrest/integration/EasyMock2Adapter; interface 2417 'Lorg/easymock/IArgumentMatcher;'
03-18 12:52:27.417 2998-2998/? W/dalvikvm﹕ Link of class 'Lorg/hamcrest/integration/EasyMock2Adapter;' failed
03-18 12:52:27.537 2998-2998/? W/ClassPathPackageInfoSource﹕ Cannot load class. Make sure it is in your apk. Class name: 'org.hamcrest.integration.EasyMock2Adapter'. Message: org.hamcrest.integration.EasyMock2Adapter
java.lang.ClassNotFoundException: org.hamcrest.integration.EasyMock2Adapter
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org/hamcrest/integration/EasyMock2Adapter
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.hamcrest.integration.EasyMock2Adapter" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/info.korzeniowski.myapp.test-1.apk", zip file "/data/app/info.korzeniowski.myapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/info.korzeniowski.myapp.test-1, /data/app-lib/info.korzeniowski.myapp-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
03-18 12:52:27.537 2998-2998/? I/dalvikvm﹕ Failed resolving Lorg/hamcrest/integration/JMock1Adapter; interface 2468 'Lorg/jmock/core/Constraint;'
03-18 12:52:27.537 2998-2998/? W/dalvikvm﹕ Link of class 'Lorg/hamcrest/integration/JMock1Adapter;' failed
03-18 12:52:27.587 2998-2998/? W/ClassPathPackageInfoSource﹕ Cannot load class. Make sure it is in your apk. Class name: 'org.hamcrest.integration.JMock1Adapter'. Message: org.hamcrest.integration.JMock1Adapter
java.lang.ClassNotFoundException: org.hamcrest.integration.JMock1Adapter
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org/hamcrest/integration/JMock1Adapter
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.hamcrest.integration.JMock1Adapter" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/info.korzeniowski.myapp.test-1.apk", zip file "/data/app/info.korzeniowski.myapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/info.korzeniowski.myapp.test-1, /data/app-lib/info.korzeniowski.myapp-1, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:366)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4435)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
03-18 12:52:28.477 2998-3011/? I/TestRunner﹕ started: testOpenAndCloseDrawer(info.korzeniowski.myapp.test.BasicTest)
03-18 12:52:28.497 274-439/system_process I/ActivityManager﹕ START u0 {act=android.intent.action.MAIN flg=0x10000000 cmp=info.korzeniowski.myapp/.activity.MainActivity_} from pid 2998
03-18 12:52:28.617 2998-2998/? I/greenDAO﹕ Creating tables for schema version 1
03-18 12:52:28.687 2998-2998/? W/dalvikvm﹕ Class resolved by unexpected DEX: Linfo/korzeniowski/myapp/MyApp;(0x416fc6a8):0x73054000 ref [Ldagger/ObjectGraph;] Ldagger/ObjectGraph;(0x416fc6a8):0x72ec8000
03-18 12:52:28.687 2998-2998/? W/dalvikvm﹕ (Linfo/korzeniowski/myapp/MyApp; had used a different Ldagger/ObjectGraph; during pre-verification)
03-18 12:52:28.697 2998-2998/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41465700)
03-18 12:52:28.738 2998-2998/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at info.korzeniowski.myapp.MyApp.onCreate(MyApp.java:32)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
03-18 12:52:28.738 274-286/system_process W/ActivityManager﹕ Error in app info.korzeniowski.myapp running instrumentation ComponentInfo{info.korzeniowski.myapp.test/android.test.InstrumentationTestRunner}:
03-18 12:52:28.738 274-286/system_process W/ActivityManager﹕ java.lang.IllegalAccessError
03-18 12:52:28.738 274-286/system_process W/ActivityManager﹕ java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementationF
解决方案
Since class is not found in org.hamcrest.integration
package, try excluding it. Then your your dependencies would look like
// Espresso
androidTestCompile ('com.jakewharton.espresso:espresso:1.1-r2') {
exclude group: 'com.squareup.dagger', module: 'dagger'
exclude group: 'org.hamcrest', module: 'hamcrest-integration'
}
androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r2') {
exclude group: 'com.android.support', module: 'support-v4'
// Not sure whether line below is needed
exclude group: 'org.hamcrest', module: 'hamcrest-integration'
}
这篇关于仪表运行失败,原因是“java.lang.IllegalAccessError”。摇篮+居preSSO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!