Eclipse Project is compatible with Java SE and Android

I created a Java library for Java SE, and recently I used it in an Android application. I would like to maintain compatibility in the library with Java SE and Android.

What is the best practice when creating a project in Eclipse for this situation? At the 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 Java SE, and also in android.jar when it is for Android, but this is kind of a pain.

2) Create two Java projects, one for Java SE and one 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 any better solutions?

+6
source share
1 answer

If you have a jar file created using Java SE, you can use it directly in your Android project. You just need to be careful not to use anything not supported on Android. For example, many javax libraries. * Not included.

In Eclipse you can do Properties-> Java Build Path-> Libraries-> Add External Jar

0
source

Source: https://habr.com/ru/post/907661/


All Articles