Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import source java project in Android project

Is it possible to import an existing Java project which is in my workspace, in an Android project which is also in my workspace? The Java project doesn't use stuff that is incompatible with Android. I could do it using a .JAR, but since I'm modifying the Java project a lot, I would like to import the whole source code and change it once in a while. Is it possible? Thanks

like image 610
Paulo Barros Avatar asked Oct 12 '11 07:10

Paulo Barros


People also ask

How do I import a project from one project to another in Android Studio?

Go to File->New->Import Module then browse you project. After importing module go to project structure and add module dependency to your project. Save this answer.


2 Answers

This is somewhat of a hack, but worked for my project:

  1. Add both Android project and plain Java project to workspace
  2. Go to properties for Android project -> Java Build Path -> Source
  3. Click Link Source, in "Folder name", make sure to select the root directory of the plain Java project's src tree
  4. Use a descriptive name for "Linked folder location", like "java_project_src".
  5. Press Finish and compile

This setup will compile the plain-java code as Dalvik bytecode. In my case, I had pure java code with very limited dependencies, but wanted to share the pure java code with non-Android projects, instead of separately maintaining these files in every project.

like image 60
raider33 Avatar answered Oct 23 '22 19:10

raider33


I think you are talking about referencing other projects into the current project, if this is the case then you can do this by Right click on project, properties->Project Reference.

like image 21
Paresh Mayani Avatar answered Oct 23 '22 19:10

Paresh Mayani