Question

I am currently working on an Android project (let's call it project A), and i want to add an already existing project (B) to my A-project, so that i can use the methods of project B. First I tried adding the project via the Java Build Path, but that was impossible, because my original Project-B-Folder was just a default-project, and not a java-project. I changed it to be a java-project, and then i added it in my java build path of project A.

Now when I did this the first time, it worked quite well for me. The Files in the Project-B-Folder turned into Packages, which i could import into my .java-files from Project A. Eclipse found the packages while i was typing them, but when i saved the file, it showed the "The import XXX cannot be resolved error". I decided to redo all the build path stuff, but now, all my folders in Project B remain to be folders, and won't turn into packages. And in Project A, I cannot find them via the import command, although i have added the project B to my Java Build Path again.

Do you have any help for me? Thx in advance!

Was it helpful?

Solution

You can do that in atleast two ways as I know. This answer assumes that you are using Eclipse.

  1. Mark project B as a library project and add it as a dependency through the Android tab in the project properties.
  2. Export the project-B into a library JAR and add the jar into the \libs folder and then to the build path of Project-A

In the first case, you have the opportunity to make changes to the library project and avail the latest updates in your dependent project after a clean up. To use this method, right click on the project folder, and select properties. The in the Android tab on the left, tick the check-box which says Is Library. Once this is done, go to project A, which is the dependent project and reach the Android tab through the same menu. Then under Library, click Add and select Project-B as a dependency. Clean up both the projects and build them. You are ready to go.

In the second case, click on Project-B and go through File -> Export -> Java -> Jar File. Then choose a destination folder and generate a jar. Once the jar is created, copy it into the project's \libs folder. You may optionally add this into the build path as well, but in normal case it will already be added once you copy it there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top