简体   繁体   English

如何在Eclipse中的两个Android项目之间共享类?

[英]How do I share classes between two Android projects in Eclipse?

I have 2 Android projects in Eclipse. 我在Eclipse中有2个Android项目。 Now the both need to share one class. 现在两者都需要共享一个类。 As soon as I add a Project to the buildpath of the other, the folder is added but always marked with a red cross. 将项目添加到另一个项目的构建路径后,该文件夹即被添加,但始终标有红叉。 How can I resolve this? 我该如何解决? Thanks for any help. 谢谢你的帮助。

You can use the feature of isLibrary project. 您可以使用isLibrary项目的功能。

1)Create a new Android project. 1)创建一个新的Android项目。

2)Add all the classes that you want to share them between multiple projects. 2)添加要在多个项目之间共享的所有类。

3)Right click on this project and select properties . 3)右键单击该项目,然后选择properties

4)From Android section in left menu mark the project as isLibrary project checkbox. 4)在左侧菜单的Android部分中,将项目标记为isLibrary project复选框。

5)Right click on all the project you want to share the class with them and select properties . 5)右键单击要与他们共享课程的所有项目,然后选择properties

6)From Android section in left menu click on the button Add and select the library project. 6)在左侧菜单的Android部分中,单击Add按钮,然后选择库项目。

7)Use the class normally as if it is in your project and add its imports. 7)像在项目中一样正常使用该类,并添加其导入。

I hope it helps. 希望对您有所帮助。

Note: The previous steps is for Eclipse 注意:前面的步骤适用于Eclipse

右键单击项目,然后单击属性,将项目(包含要在另一个项目中使用的类)标记为库。

You don't have to do it by means of a library project, you could use a common source folder. 不必由库项目的方式做到这一点,你可以使用一个共同的源文件夹。

If you are developing in Eclipse then the trick is to have a common source folder (common to both projects) Make this folder outside of both projects and in the build properties/source, click 'link source' and browse to the location of the common source. 如果您是在Eclipse中进行开发,则诀窍是拥有一个公共源文件夹(这两个项目都公用)。将此文件夹置于两个项目之外,并在构建属性/源中,单击“链接源”并浏览到该公共位置。资源。 (You can call it any name you want) Do this in both projects and it will appear in both projects' Package Explorer and when you change it in one project, the other will get updated too. (您可以将其命名为任意名称)在两个项目中都执行此操作,它将显示在两个项目的Package Explorer中,并且在一个项目中进行更改时,另一个项目也会被更新。

It will have to have the same package name in both projects. 两个项目中的软件包名称必须相同。

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

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