引用 Android 自定义库导致应用程序中找不到运行时类错误

发布于 2024-10-10 03:15:00 字数 604 浏览 0 评论 0原文

我正在开发一个自定义 Android 库。我从一个 java 项目(在 Eclipse 中)和另一个 UI 测试 Android 项目开始。

在我的 UI 测试项目中,我在构建路径中引用了库项目,一切都很好,我可以在 UI 中测试库代码。

后来,我决定需要“Gen”代码(用于自定义样式属性),因此我尝试将我的库更改为 Android 项目(通过 Android-tools -> Convert.. ),但灾难发生了!解决了所有编译时问题后,它终于“让”我启动了 UI 测试应用程序,然后一声巨响!当我尝试从库类创建任何对象时,它(在日志中)说找不到类

两个问题:

  1. 知道如何解决这个问题吗?我尝试过,但似乎它是为了引用另一个需要单独安装的 .apk。

  2. 如果我只是将其保留为我的库的 java 项目(而不是 android),我可以使用资源生成器吗?如何?

PS:根据Eclipse的控制台所说,依赖项(我的库)是在UI测试应用程序之前安装的。

更新:我尝试将库项目编译为 jar 并从 UI 测试中引用它,这样,它就可以工作了。但我不想使用这种方法,因为它在测试方面非常慢。

I am working on a custom Android library. I start off with a java project (in Eclipse) with another UI testing Android project.

In my UI testing project, I reference the library project in build path, and everything is good and I can test the library codes in the UI.

Later on, I decided I need to have the 'Gen' code (for custom styles attributes), so I try to change my library to an Android project (via Android-tools -> convert.. ), and disasters happens! After fixing up all the compile time problems, it finally 'let' me start the UI testing application, and bangs! When I try to create any objects from the library class, it said (in the Log) that Class not found.

Two questions:

  1. Any idea how to fix this? I tried but seems it is for referencing another .apk that need to install separately.

  2. If I just keep it to be java project (not android) for my library, can I use the resource generator? and how?

PS: the dependency (my library) is installed before the UI test application, according to the Console of Eclipse said.

Update: I tried to compile the library project to jar and reference it from the UI testing, and in this way, it works. But I don't want to use this approach since it is very slow in terms of testing.

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

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

发布评论

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

评论(2

好菇凉咱不稀罕他 2024-10-17 03:15:00

对于那些像我一样犯同样错误的人

当库项目是一个 android 项目时,
必须

属性>安卓>单击弹出窗口底部的添加按钮
图书馆部分

并添加项目,而不是

属性> java构建路径>项目>>添加

稍后的方法仅适用于纯java项目。

for those who are doing same mistake like me

when library project is an android project
got to

properties > android > click add button at bottom of the popup inside
library section

and add project, instead of

properties > java build path > project > add

later approach is for pure java projects only .

£烟消云散 2024-10-17 03:15:00

最后我找到了我自己问题的答案。这实际上在官方文档中提到过。

Finally I found the answer to my own question. This is actually mentioned in official documentation.

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