1

I want to create an application having two versions: one for desktop - java standard edition, and one for android. As GUI would be quite simple and huge part of logic would be probably platform independent (only basic Java packages used). I would like of course to share this main core part.

Thus question: How should I construct my project in Eclipse? 3 projects: android, standardEdition, core? Or can I put everything into one project with two different destination platforms and if yes how to do that?

How to learn android and standardEdition project to learn to use shared core project?

Diego C Nascimento
  • 2,801
  • 1
  • 17
  • 23
user2707175
  • 1,133
  • 2
  • 17
  • 44
  • 2
    Would the common core make sense as a library with its own API, stored in a Jar? If so, that may be the most flexible approach. There would be a project to develop the library, and its result would be imported into an Android application project and a desktop application project. – Patricia Shanahan Sep 12 '13 at 13:30

1 Answers1

0

I would use the 3-project approach. As you have already said, make a seperate project for the core. (API)

That way you can also create unit test for the core only and your setup will still look clean. What you should add to the 'core' project is an ant file or something similar to generate a jar file from the project, thus making it possible to import your core into the other projects. Another advantage is that any library used in the core, will only have to be imported there, as the import of the core will use those.

LuigiEdlCarno
  • 2,410
  • 2
  • 21
  • 37
  • Thanks for help. How to create jar files automatically in Eclipse? I know how to do it manually, but of course it would be better that after every change or periodically ex. every 5 minutes Eclipse generate new jar file. – user2707175 Sep 12 '13 at 17:40
  • The problem seems to be much more complicated that it could look at first time. I created two projects: 1) standard android application 2) libraries - however here this project is just java application, not as android app (as it will be shared between java se and java android). – user2707175 Sep 12 '13 at 19:54
  • Next I exporter jar file from project no 2 and imported this to project 1 under libs. I've also checked Build Path (both Libraries and Order and Export tab and they seems to be ok). Program complies without problems. However when running it on adroid device all classes from project 2 are invisible (FATAL EXCEPTION, Could not find class, Unable to resolve superclass). – user2707175 Sep 12 '13 at 20:06
  • Simply it seems that virtual machine on Android device is not capable to see all library classes. I've tried to find the solution, and the only thread which could be a part of the answer is here: http://stackoverflow.com/questions/12270493/android-unable-to-resolve-superclass User BigBadaboom proposes to create library as Android project (in my case project 2) and in properties mark it as library (checkbox). However I'm not sure if it's the answer in my case, as then library will not be any longer universal set of libraries but android type library. Any help, suggestions? – user2707175 Sep 12 '13 at 20:07
  • BigBadaboom did not propose creating the library as an android project, but merely suggested some settings on the existing project. I am not sure though, how this will affect other projects using your API. I cannot test it right now. Just try out the way he mentioned and post the results. Maybe the 2nd step "Adding the library" is enough in your case. – LuigiEdlCarno Sep 13 '13 at 06:54
  • The best solution in my case, but still not ideal, it seems to create 3 projects and then to use the functionality of linking source (project properties/Java Build Path/tab Source/Link Source button - then I point the src directory of another project and as folder name I enter the first part of my package name, ex. A for package A.B.C) It works however sometimes Eclipse is not capable to see changes done simultaneously in sub-linked project. – user2707175 Sep 13 '13 at 16:10