Import an eclipse android project with version control system into Android Studio

I am trying to import an eclipse project with version control system into Android Studio.

Support for direct eclipse project import was added in Android-Studio version "0.5.5" where we don't need to export project first from eclipse to import it into Android-Studio.

I have an eclipse Android Project which I am trying to import into Android Studio. Import is successful but imported project no more has version control.

Edit:- More detail

Suppose I have following Directory Structure

Project ----
           |---------- .git/
           |----------- MyApp 
           |------------MyApp_imported

During project import, I point Android Studio to Project Directory "MyApp", It copies all files in my project "MyApp" to new directory "MyApp_Imported". But imported project doesn't have version control enabled. Now I am not sure how to proceed further. How should I tell Android Studio to use old repository for imported project. A step by step guide to do this will be very helpful .

Here is text from Android Tools Project Site

Project - Importing modules should now work properly. You can import existing Eclipse ADT projects as well as Gradle modules into an existing Gradle project; it will copy in the sources as is done for full project import, as well as handle dependencies transitively. Import modules either from the project structure dialog or the File | Import Module action. - New project structure dialog implementation: Should be faster, includes Gradle sync notification, should only perform a Gradle sync at the end when necessary, and won't list invalid IntelliJ module warnings as before.
This is actively being worked on and the individual editors (for flavors, build types, signing configurations etc) will be improved in upcoming builds.


Solution 1:

Here is the step by step solution to do it.

  1. Open Android Studio -> Import Project-> Select your project directory. (In above case "MyApp") Remember Select the directory which contains Manifest file otherwise new "direct import wizard" doesn't get triggered and android studio uses old import wizard.
  2. Android Studio will create a copy of your project "MyApp_imported" with new directory structure.
  3. Copy your existing ".git" directory inside "MyApp_imported"
  4. Android Studio -> VCS -> Enable version control This will make Android Studio use your existing repository for imported project. Though imported project has different directory structure but git handles them pretty well. You might want to also call git add . and git add -u in the root folder of the imported project to make sure all new files are added and existing file moves are detected by git.
  5. Android Studio -> Changes Review all files and commit. Git will automatically handle new directory structure and file history etc will not be lost.
  6. Now you can share it on github/Bitbucket by VCS-> Share it on GitHUb Note:- For bitbucket you will have to install "Bitbucket plugin" for Android Studio.

Solution 2:

Couple of months ago I got my job as android developer.The first problem i had faced were my collegues who using Eclipse.I was allowed to use Android studio if I will not make any changes to existing project structure.After 3-4 attemps I finally found a decision.Here is steps to open Eclipse git project without migrating to Gradle and without changing project structure.

  1. Clone git repository of project
  2. Add /gen and /.idea to .gitignore
  3. Open any of already created Android Studio projects.
  4. File -> Open -> Choose path root project folder(with src and res inside)
  5. Doble-click project to open project structure
  6. Select root project folder -> F4
  7. Project -> Project SDK -> Android API XX Platform && Project language level -> Override in interfaces
  8. Modules -> Sources tab. Mark src as Sources && res as Resources.
  9. Modules -> Paths tab. Use module compile output path.Create folders output and output_test inside gen folder (create gen if folder not exist yet).Output paths should look like C:\Users\User\project_rep\project\gen\output
  10. Modules -> Dependencies tab. Click "+" -> Jars or directories.Select all .jar libraries which are using by your project.(Android Studio can pretend like its added only one jar but thats not true)
  11. Facets -> "+" -> Android
  12. Facets -> Structure tab -> Reset to defaults.
  13. Close Project Structure window.
  14. Run -> Edit configurations -> Android Application -> Module -> Select your module.Target device -> Show chooser dialog.
  15. Edit configurations -> Before launch -> remove Gragle aware make, add Make.

Finally, after all of those steps you are able to hit Run button.Enjoy!

Solution 3:

The import process does not make this easy. But here's something to try:

Let Android Studio do what it wants to do. It creates a file in the root of the new copy of the project which shows what was moved where.

Make a fresh (scratch) copy of the original git repository. Use "git mv" commands to duplicate the directory structure changes which Android Studio made. Commit the changes.

Copy the resulting .git directory into the project made by Android Studio. Use "git status" there to see how the result of the import process differs from what you did in your scratch copy of the project. At this point you might just choose to commit the remaining differences right there.