Android - Junit - 测试项目使用外部 Jar

发布于 2024-09-27 06:33:49 字数 727 浏览 1 评论 0原文

我在一个库项目 (LIB) 中有一些 java 代码(对于 Android 编译得很好),我想在另一个 Android 项目 (A) 中使用它。

由于 LIB 的代码不太可能发生太大变化,因此我选择将其作为 jar 添加到 A 中。它工作得很好。

我还有另一个项目,是一个 Android 仪器项目,测试第一个 Android 项目 (B)。

所以我们现在拥有的是 A,包括 LIB 作为外部 jar,B 测试 A。

当我想从用 LIB 编写的 B 代码访问时,问题就开始了。 据我所知,除非我将 LIB 作为外部 jar 添加到 B,否则它会拒绝编译(也就是说,它无法访问 A 中包含的 LIB jar 中的代码)。

我不愿意将 LIB 作为外部 jar 添加到 B 中,因为: 1. 感觉不对,而且 2. 运行测试时失败,并显示:

java.lang.IllegalAccessError:预验证类中的类引用解析为意外实现

我发现 Mike的问题,但他的解决方案仅涵盖使用ant脚本进行编译,而我目前更喜欢使用Eclipse IDE来完成此项目。

知道如何解决这个问题吗?

I have some java code (compiles nicely for Android) in a library project (LIB) that I want to use in an another Android project (A).

As LIB's code is unlikely to change much, I opted for adding it as a jar to A. It works fine.

I have another project that is an Android instrumentation project, testing the first Android project (B).

So what we have now is A including LIB as an external jar, and B testing A.

The problem starts when I want to access from B code written in LIB.
From what I see, unless I add LIB as an external jar to B, it refuses to compile (that is, it cannot access the code in the LIB jar that is included in A).

I am reluctant to add LIB as an external jar to B because:
1. It doesn't feel right, and
2. When running the tests it fails with:

java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation

I found Mike's question, but his solution only covers compiling using an ant script, and I currently prefer to use the Eclipse IDE for this project.

Any idea how can I solve this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

豆芽 2024-10-04 06:33:49

(为了从“未回答”过滤器中删除此问题...)

解决方案概述如下:

Android 测试:外部库

应从 A 导出 LIB,以便从 B 访问它。

(In order to remove this question from the "Unanswered" filter...)

The solution is outlined here:

Android Testing: External libraries

The LIB should be exported from A to make it accessible from B.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文