I have built a Java library for Java SE, and recently I’ve used it in an Android application. I would like to maintain compatibility in the library with both Java SE and Android.
What is the best practice when making a project in Eclipse for this situation? Top of my head, I see three solutions:
1) Create a Java project, and then switch the system library to JRE when I want to compile for Java SE, and to android.jar when it is for Android, but it is kind of a pain.
2) Create two Java projects, one for Java SE and another for Android, and share the same source folder.
3) Use Android as the least common denominator and create an Android project, and use it as a library in Java SE projects.
Is any of these viable? Are there better solutions?
If you have a jar file created using Java SE you can use it directy in your Android project. You just have to be careful not to use anything not supported on Android. For example many of the javax.* libraries are not included.
In Eclipse you can do Properties->Java Build Path->Libraries->Add External Jar