Convert existing project into Android project in Eclipse?

AndroidEclipse

Android Problem Overview


How do you convert an existing project into an Android project in Eclipse?

In particular, I want to convert a plain old Java project into an Android Library project.

Thanks.

Android Solutions


Solution 1 - Android

You need to change the nature of the project (this has already been answered, but nobody gave the actual string you need for that.)

  • Close eclipse

  • Open the .project file in your project

  • Make the natures section look like:

      <natures>
      	<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
      	<nature>org.eclipse.jdt.core.javanature</nature>
      </natures>
    

Start eclipse again, have fun.

Note: If you are using maven you can configure the project's nature in your pom, see the maven eclipse plugin doc

Solution 2 - Android

I had an app that was built with Eclipse 3.5 and used java projects instead of properly built Android Library projects. I'm not sure how it originally worked (the app was published and worked fined), but I couldn't get it to run when I tried setting up a dev environment on a different machine. I keep getting ClassNotFoundExceptions for references to the Java project.

Since I had a couple years of check-in history, I really didn't want to move projects as some answers stated. For me, converting the Java project into a proper Android Library made more sense.

Here are the steps I had to take to get it working:

Add AndroidNature to ".project" file

<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>

Add a simple "AndroidManifest.xml"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.convertproject.test"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
</manifest>

Add a "project.properties" file

target=android-7
android.library=true
  • Create an empty folder off the root of the project for called: "res"
  • Refresh in Eclipse
  • Right click on project, select Android Tools, Fix Project Properties Rebuild

NOTE: when you add library to your main project, import using the Android / Libray tab (under project properties) instead of Java Build Path / Projects

Solution 3 - Android

What subsystem/plugin are you using for Eclipse Android development?

Generally speaking, the process is called "changing the project nature" e.g.,

http://enarion.net/programming/tools/eclipse/changing-general-project-to-java-project/

Solution 4 - Android

I met the same problem. Here are my steps:

  • create an new android project
  • copy .project, .classpath files into the plain old Java project
  • refresh the plain old Java project in eclipse, and then the "Android Tools" appears at context menu when you right click the plain old Java project.
  • "Android Tools" | "fix Project Properties"

In the last step, Eclipse will add "Android Resource Manager", "Android Pre Compiler" and "Android Package Builder" into "Builders" and soon compile the project, create the "gen" folder, BuildConfig.java and R.java.

done.

Solution 5 - Android

My solution is:

  1. Copy an AndroidManifest.xml and project.properties file to the root directory of this project.
  2. Click "File" -> "Import", choose "Android" -> "Existing Android Code Into Workspace".
  3. Configure proper source code path and Android Lib version.

Solution 6 - Android

Are you aware of this guide?

I don't know if there's a way to convert an existing Java project, but if not I'd suggest building a new library project as described and then moving your code to it.

Solution 7 - Android

If I have to convert I usually just create a new project and copy the files in there.

If I took the time to do it properly, it would've been a Mavenized project which I can just import. You can look at my app to help you get some ideas. https://github.com/trajano/GasPrices

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhpiqueView Question on Stackoverflow
Solution 1 - AndroidhennrView Answer on Stackoverflow
Solution 2 - Androidraider33View Answer on Stackoverflow
Solution 3 - AndroidUriView Answer on Stackoverflow
Solution 4 - AndroidjoeaniuView Answer on Stackoverflow
Solution 5 - AndroidpeacepassionView Answer on Stackoverflow
Solution 6 - AndroidJRLView Answer on Stackoverflow
Solution 7 - AndroidArchimedes TrajanoView Answer on Stackoverflow