使用jar依赖项测试Android项目

时间:2011-06-06 14:01:08

标签: android testing

我的Android项目有几个jar库作为依赖项。单独,它编译并运行良好。 我写了一个小测试项目,但运行它我没有得到任何结果(没有测试通过或失败)也没有任何错误,但在logcat的输出中有这样的警告:

06-06 14:55:43.533: INFO/dalvikvm(7049): Failed resolving Lcom/adwhirl/adapters/InMobiAdapter; interface 315 'Lcom/inmobi/androidsdk/InMobiAdDelegate;'
06-06 14:55:43.533: WARN/dalvikvm(7049): Link of class 'Lcom/adwhirl/adapters/InMobiAdapter;' failed
06-06 14:55:43.533: INFO/dalvikvm(7049): Failed resolving Lcom/adwhirl/adapters/InMobiAdapter; interface 407 'Lcom/inmobi/androidsdk/InMobiAdDelegate;'
06-06 14:55:43.533: WARN/dalvikvm(7049): Link of class 'Lcom/adwhirl/adapters/InMobiAdapter;' failed
06-06 14:55:43.553: DEBUG/dalvikvm(7049): GC_CONCURRENT freed 471K, 51% free 2880K/5831K, external 0K/0K, paused 2ms+4ms
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049): Cannot load class. Make sure it is in your apk. Class name: 'com.adwhirl.adapters.InMobiAdapter'. Message: com.adwhirl.adapters.InMobiAdapter
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049): java.lang.ClassNotFoundException: com.adwhirl.adapters.InMobiAdapter
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at java.lang.Class.classForName(Native Method)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at java.lang.Class.forName(Class.java:234)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:89)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:40)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:51)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:48)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.SimpleCache.get(SimpleCache.java:31)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:73)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:154)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:115)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:103)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:360)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3398)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.app.ActivityThread.access$2200(ActivityThread.java:123)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:977)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.os.Looper.loop(Looper.java:130)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at android.app.ActivityThread.main(ActivityThread.java:3835)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at java.lang.reflect.Method.invokeNative(Native Method)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at java.lang.reflect.Method.invoke(Method.java:507)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at dalvik.system.NativeStart.main(Native Method)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049): Caused by: java.lang.NoClassDefFoundError: com.adwhirl.adapters.InMobiAdapter
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     ... 26 more
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049): Caused by: java.lang.ClassNotFoundException: com.adwhirl.adapters.InMobiAdapter in loader dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/com.mypackage.test-1.apk:/data/app/com.mypackage-2.apk]
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-06 14:55:43.553: WARN/ClassPathPackageInfoSource(7049):     ... 26 more

正如您所看到的,似乎导出库存在问题,实际上我得到的错误就像每个库一样。 我读了in this blog post为了让它工作,它应该足以导出主项目中的所有库,但对我来说不起作用。还有其他想法吗?

3 个答案:

答案 0 :(得分:16)

转到使用.jar文件的项目(即测试中的项目)。点击右键 - >属性 - > Java构建路径 - >订单和出口 - >检查那里的图书馆

enter image description here

答案 1 :(得分:2)

对我有用的是 - 在'订购和导入'部分,我的jar文件上架

答案 2 :(得分:1)

您是否尝试将jar放入libs intead而不是lib?

http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17