简体   繁体   English

将non_Android项目的源代码用作库

[英]Using a non_Android project's source code as a library

I've carefully followed the very clear advice given on this subject by Gunar at: Add a non-Android library project to an Android app in Eclipse but I still get class-not-defined errors. 我认真遵循了Gunar在此主题上给出的非常明确的建议: 在Eclipse中将非Android库项目添加到Android应用程序中,但仍然收到类未定义的错误。 I'm using an ordinary Java desktop project (not an Android project) as the library and it is resident in Eclipse's workspace. 我使用一个普通的Java桌面项目(不是Android项目)作为库,它驻留在Eclipse的工作区中。 My Android project can "see" classes and interfaces in the library project and it compiles and loads to the emulator but crashes as soon as a class or interface in the library project is referenced. 我的Android项目可以“查看”库项目中的类和接口,并且可以编译并加载到模拟器中,但是一旦引用库项目中的类或接口,则崩溃。 I do not have a jar for the library project but thought that Eclipse/ADT would find it's source in the workspace. 我没有一个用于库项目的jar,但认为Eclipse / ADT会在工作区中找到它的源。 I'm obviously wrong. 我显然是错的。

Must I have the library project in jar form? 我必须有jar形式的图书馆项目吗?

I have loaded the latest SDK tools etc in ADT. 我已经在ADT中加载了最新的SDK工具。

As I know you need create Android project from source code (aka desktop project source files) and remove Android library but set Android dependencies + JRE . 据我所知,您需要从源代码(也称为桌面项目源文件)创建Android项目并删除Android库,设置Android依赖项 + JRE

So your project should look like: 因此,您的项目应如下所示:

在此处输入图片说明

After that you can successfully create jar and add to classpath. 之后,您可以成功创建jar并将其添加到classpath。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM