Hans En
Hans En

Reputation: 926

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

I have 2 Android projects in Eclipse. 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.

Upvotes: 1

Views: 642

Answers (3)

Sami Eltamawy
Sami Eltamawy

Reputation: 9999

You can use the feature of isLibrary project.

1)Create a new Android project.

2)Add all the classes that you want to share them between multiple projects.

3)Right click on this project and select properties.

4)From Android section in left menu mark the project as isLibrary project checkbox.

5)Right click on all the project you want to share the class with them and select properties.

6)From Android section in left menu click on the button Add and select the library project.

7)Use the class normally as if it is in your project and add its imports.

I hope it helps.

Note: The previous steps is for Eclipse

Upvotes: 4

NickT
NickT

Reputation: 23873

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. (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.

It will have to have the same package name in both projects.

Upvotes: 0

Muhammad Ali Hassan
Muhammad Ali Hassan

Reputation: 192

Mark project(that contains the class to be use in another) as library by right clicking the project and then properties.

Upvotes: 0

Related Questions