Vikasdeep Singh
Vikasdeep Singh

Reputation: 21766

One Android project for Eclipse and Android Studio

As we all know Android Studio is official IDE for development of Android applications but still many developers are using Eclipse.

I am facing such issue because some of our developers are using Eclipse and some are Android Studio. In Such situation can we make one android project compatible on Eclipse and Android Studio by making changes in folder structure or something similar?

It will be interesting if we can do it. Thanks!

Upvotes: 2

Views: 2800

Answers (7)

Pipin Indrawan
Pipin Indrawan

Reputation: 81

I found easier but not clean.

on folder app\src\main create 3 file (or copy from existing android eclipse project)

1 .classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="java"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con"  path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
....

2 .project

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
     <name>YOUR_PROJECT</name>

...

3 project.properties

# Project target.
target=android-22

then open app\src\main as root of your new project.

the hard part is adding lib to your eclipse project example on android studio you only need add line like

<orderEntry type="library" exported="" name="facebook-android-sdk-3.20.0" level="project" />

but in eclipse you need to download the FacebookSDK project and add as library on your project.

but the apps will be running on both IDE just remember for Android studio do not update folder bin & gen (created by eclipse) or ask eclipse programmer not to commit those 2 folder.

cheers

Upvotes: 1

Kishan B Manavadariya
Kishan B Manavadariya

Reputation: 447

I found perfect working solution.

it's not too hard to make it possible:

  1. Create a new Android blank project with same package in eclipse (You can found package name in manifest or just follow the folder pattern as example --> src/java/com/xyz/library --> com.xyz.library is the package name)

  2. Copy and replace the fresh res/ folder and all the sub-folders in eclipse with the ones from the Android Studio project

  3. Copy the content of the src/java/com/xyz/library folder from the Android Studio project to your package in Eclipse. also add your needed libraries if it's needs to be added.

So now we know that the Android application needy elements are just the java files, the manifest file and the resources. From there you can rebuild a project in your favorite Eclipse IDE.

Hope it will be helpful for you.

Upvotes: 1

ricalo
ricalo

Reputation: 191

My team just published a project. One of the requirements is that the project must be usable by Android Studio and Eclipse users. Basically, our project is an Android Studio project, but we provided a gradle build file that "converts" the project to Eclipse.

After I run gradle -b eclipse.gradle I actually can open the project in both IDEs. I worked with my team this way for a couple of days. We were just careful of including the .classpath, .project and other Eclipse-related files in our .gitignore file since we don't want those files in our repository.

Here are the contents of eclipse.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

// Add the natures and build commands to the project
eclipse.project {
  	natures 'com.android.ide.eclipse.adt.AndroidNature'
	natures 'org.eclipse.jdt.core.javanature'
	buildCommands.clear();
	buildCommand 'com.android.ide.eclipse.adt.ResourceManagerBuilder'
	buildCommand 'com.android.ide.eclipse.adt.PreCompilerBuilder'
	buildCommand 'org.eclipse.jdt.core.javabuilder'
	buildCommand 'com.android.ide.eclipse.adt.ApkBuilder'
}

// The source code is in the java folder
sourceSets.main.java.srcDirs 'java'

dependencies {
    // declare your dependencies here
}

However, I think it would be really hard if the Android Studio project included some dependencies in aar format. AFAIK, Eclipse won't recognize aar. If this is the case you would have to:

  1. Unzip the aar file
  2. Extract the jar
  3. Add the resources from the aar file to your project

Upvotes: 0

codezjx
codezjx

Reputation: 9142

Yes, we can do it, that's the way I do. You should import your eclipse project by manual. Ok, follow my step:

0.In Android Studio, Use File->New Project to create a new Android Studio Project.

1.Copy you Eclipse project to your Android Studio project root folder.

2.Modify the settings.gradle file (In your Android Studio project root folder), add following code:

include ':YourProjectName'

3.Add a build.gradle file to the project which you want to import, just like (This can keep your eclipse project structure):

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "21.1.0"

    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')
    }
}

4.Finally, click Build->Rebuild Project in toolbar, and you will see a *.iml file is auto generate.

Hope this can help you!

Upvotes: 0

Naitik
Naitik

Reputation: 1465

Yes that's interesting. But you can do with some minor changes.

For Android Studio project to Eclipse do following:

  • Create a new Android empty project in eclipse
  • Overwrite the fresh res/ folder and the AndroidManifest.xml file, with the ones from the Android Studio project
  • Copy the content of the java/ folder from the Android Studio project (it should contain your package name folder structure, like com/example/app/, and the java files of course) in the Eclipse src folder
  • Link your needed libraries if it's the case

For Eclipse to Android studio:

Follow the answer of following link:

How do you import an Eclipse project into Android Studio now?

But you can't developed single project for source which compitable with both without modification.

Thanks Hope it'll help you

Upvotes: 0

Jeyaprakash Chinaraj
Jeyaprakash Chinaraj

Reputation: 62

Both are different IDEs (eclipse and intellij). the build environment, structure of the project are entirely different. i believe it is not possible

Upvotes: -1

Related Questions