0

I have an Eclipse code project (pure Java and libreries) that I would like to continue add maintain under Eclipse.
In parallel, I would like to use this project as part of an Android Studio project.


I prefer not do a "one time import" of the Eclipse project into Android Studio (as described here and in many other SO answers I saw), but to ADD the Eclipse project to the AS project, so when I change the Eclipse project, it is reflected in the AS project. (I can migrate the Eclipse project to Gradle if it is of any help).


If this is not practical I would go for the next option: have AS project use the source folders of the Eclipse project.

Is it feasble ?


Edit: to add clarity following the comments and amswers: The Java code I am refering to, is part of an eclipse projects. For the sake of this discussion one can assume that it is a common "logic part", for which I'll have a desktop GUI and graphics which I do on Eclipse, and mobile GUI and graphics which I will do on AS. The java logic part is a common core, around which I build.

Community
  • 1
  • 1
c0der
  • 18,467
  • 6
  • 33
  • 65
  • 1
    As a side note, it's probably not a good idea to keep using Eclipse ADT for Android development now as [Google has officially ended its support](http://android-developers.blogspot.de/2016/11/support-ended-for-eclipse-android.html). – sschuberth Nov 14 '16 at 16:01
  • Option #1: Have the Eclipse project publish a JAR that the AS project uses as a dependency. For example, you could use a local Maven repo. Option #2: Move the Eclipse project inside your Android Studio project as a module. Add a `build.gradle` to this module, configuring the source sets and teaching Gradle (and the Android plugin) how to find files in the Eclipse project structure. Add the module to `settings.gradle` in the project root. Then, have other modules in the project refer to this module via `compile project()`. – CommonsWare Nov 14 '16 at 16:01
  • @sschuberth Thanks for the side note. I use Eclipse for Java (only) projects, and AS for Android. That is why I need the sharing option. – c0der Nov 14 '16 at 16:04
  • @CommonsWare Thanks for your suggestions. Would you post is an an answer ? re option #1: isn't it cumbersome to do it for every minor change in the Eclipse project ? re option #2: I'll have to try and learn how to. – c0der Nov 14 '16 at 16:11
  • 1
    FWIW, Android Studio (being an IntelliJ IDEA fork) can also handle pure Java projects. So if you're not inclined to continue using Eclipse, another option is to move the pure Java project to Gradle (also pure, without applying android-gradle-plugin) and use that as a module in both your Android and pure java projects. – sschuberth Nov 14 '16 at 16:15

1 Answers1

1

In parallel, I would like to use this project as part of an Android Studio project.

I am assume that this project produces a library; otherwise, I am not sure what you will do with it in an Android project. The question then becomes: is this library being used by other projects, separate from your planned Android Studio project?

If the answer is "yes, this library has lots of clients", then you should really consider having that library be published as an artifact to a repository. That could be a repository on your own development machine, or one on a local server for your team, or a public one (e.g., if this is an open source project). Each of your clients may need different versions of this library, and so having distinct editions of your library published as versioned artifacts would seem to be useful.

If the answer is "well, really, this Java code's JAR might be used separately, such as from the command line, but as a library, the only client is the Android Studio project", then you could set up a hybrid Android Studio/Eclipse project, moving the Eclipse project inside the Android Studio project, so it can serve as a library module.

The key then is to add a build.gradle file to the Eclipse project/AS module that teaches Gradle/AS how to build your Eclipse project. For example, if you have the sort of file structure that pre-AS Android projects used, you might have an android closure like this:

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

You will also need to add this module to your settings.gradle file in the project root. At that point, other modules can use compile project(':whatever-you-call-it') in dependencies to pull in your library.

That being said, as sschuberth notes, Android Studio supports pure-Java modules, at least as of Android Studio 2.2. I would go that route, as two IDEs will be extremely system-intensive, since neither Eclipse nor Android Studio exactly qualifies as "svelte".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491