java.lang.NoClassDefFoundError的在android.test.ServiceTestCase [英] java.lang.NoClassDefFoundError in android.test.ServiceTestCase

查看:198
本文介绍了java.lang.NoClassDefFoundError的在android.test.ServiceTestCase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我开始我的Andr​​oid仪器测试失败,

Every time I start my Android instrumentation test it fails with

android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests:
Error in testSuiteConstructionFailed:
java.lang.RuntimeException: Exception during suite construction
    at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:239)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Caused by: java.lang.reflect.InvocationTargetException
    at com.samy4me.test.Test_Service2.<init>(Test_Service2.java:26)
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
    at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
    at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
    at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:263)
    at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:185)
    at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:373)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4218)
    at android.app.ActivityThread.access$3000(ActivityThread.java:125)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4627)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: com.XXX.ws.Service
    ... 19 more

类是存在的。我查了ProGuard的,我暂时停用ProGuard的。我测试减少到最低限度:

The class is there. I checked ProGuard, I temporarily deactivated ProGuard. I reduced the test to the absolute minimum:

public class Test_Service2
   extends android.test.ServiceTestCase<Service>
{

   public Test_Service2 ()
   {
      super (Service.class);
   } // Test_Service2
} // Test_Service2

有没有人有一个想法如何可能的呢?

Has anybody got an idea how this might have come about?

更仔细地观察我现在发现了以下内容:

Looking closer I now found the following:

04-23 15:56:21.186 W/ClassPathPackageInfoSource(  580): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
04-23 15:56:21.186 W/ClassPathPackageInfoSource(  580):     at dalvik.system.DexFile.defineClass(Native Method)
04-23 15:56:21.186 W/ClassPathPackageInfoSource(  580):     at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:209)
04-23 15:56:21.186 W/ClassPathPackageInfoSource(  580):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:203)
04-23 15:56:21.186 W/ClassPathPackageInfoSource(  580):     at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-23 15:56:21.186 W/ClassPathPackageInfoSource(  580):     at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-23 15:56:21.186 W/ClassPathPackageInfoSource(  580):     ... 26 more

这是原来的错误异常链的一部分,但被截断。在pre-验证的例外是不是新的,但在Android开发另一种痛苦。

This is part of the original error exception chain but was truncated. The pre-verified exception is not new and yet another pain in Android development.

推荐答案

OK,我发现这个问题 - 主要是PEBKAC。所以在这里,它是:

OK, I found the problem - mostly PEBKAC. So here it is:

  1. 在我看过只是在控制台上。但是,该错误信息被截断。经验教训:经常检查logcat的还有
  2. 在真正的错误是众所周知的 pre-验证的错误,发生在库意味着主要的应用得到拖入测试应用程序。教训:始终确保库不是拖入仪器测试
  1. I have looked only at the console. But there the error message was truncated. Lesson learned: always check logcat as well.
  2. The real error was the well know pre-verified error which happens when libraries meant for the main application get dragged into test application. Lesson learned: always make sure that libraries are not dragged into the instrumentation test

如果你使用Maven - 像我这样做 - 那么你可以在这里阅读详情起来的 Android的自动化测试项目,其中 - 为增加的尴尬 - 我两个星期前写我自己

If you use Maven — like I do — then you can read the details up here Automate Android Test Project, which — for added embarrassment — I wrote myself two weeks ago.

这篇关于java.lang.NoClassDefFoundError的在android.test.ServiceTestCase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆