22

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.

Chris Stillwell
  • 10,266
  • 10
  • 67
  • 77
Shakti Malik
  • 2,335
  • 25
  • 32
  • You may have to activate version control support manually. – Peter Niederwieser Jul 13 '14 at 19:40
  • I have tried a lot of ways to do that but couldn't. I need someone who have dome it already to give a step by step guide. – Shakti Malik Jul 13 '14 at 20:04
  • "VCS -> Enable version Control -> Git" isn't there? Google search for "Android Studio Git" seems to give many relevant results. – Peter Niederwieser Jul 13 '14 at 20:30
  • If i will do "Enable Version Control" then it will create a new repo and all old history will be gone. I need a way to keep my git history. – Shakti Malik Jul 13 '14 at 20:32
  • "Enable Version Control" doesn't create an new repo (at least not if one already exists). All it does is to activate the IDE's version control integration. – Peter Niederwieser Jul 13 '14 at 20:41
  • @PeterNiederwieser So How will i make it use ".git" directory/repository i have. Because Android Studio creates a new directory for project just imported so how would it know where to look for ".git" directory. I am sorry, I am new to git and Android Studio. – Shakti Malik Jul 14 '14 at 05:20
  • I'm an IntelliJ user, but not an Android Studio user. Usually, `import` doesn't create a new directory but imports an existing project from an existing directory. Not sure why it would be different in your case. – Peter Niederwieser Jul 14 '14 at 05:22
  • Earlier Eclipse IDE was used for android development. Android Studio used a little different directory structure then Eclipse so Google and added a new Import feature where It changes directory structure and creates a new directory for Imported Project. Now since Directory structure has changed so I am not sure how to make it work – Shakti Malik Jul 14 '14 at 05:43

3 Answers3

30

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.
Bob
  • 5,510
  • 9
  • 48
  • 80
Shakti Malik
  • 2,335
  • 25
  • 32
  • That is much simpler than I was thinking. – Daniel Jonker Nov 03 '14 at 20:49
  • What does this mean "Though imported project has different directory structure but git handles them pretty well."? I see the history, but it also shows that each file was "renamed". From my understanding I think that's the best you can do, but are you saying that some how git treated the renamed files as identical? If that is the case I am curious as to how you managed that. – nPn Dec 23 '14 at 06:00
  • Ah, you can copy the .git folder, you saved me much further hair-pulling! And don't forget to update the .gitignore respectively. – ZirconCode Jan 04 '15 at 19:21
  • I needed first to use git mv on my original repository in order to update the folders hierarchy commit, and then copied the .git to the migration folder and all worked. – Elhanan Mishraky Jan 12 '15 at 13:54
  • I don't get the files mapped correctly. I'm importing the Eclipse project through Android Studio, copy the .git folder from the Eclipse project to the Android Studio project (ordinary ctrl+c) and enable VCS. However, Git lists all old locations of the files as "missing" and the new locations as "untracked". They're not getting correctly remapped but handled as separate files. What am I doing wrong? – jomni Mar 22 '15 at 14:26
  • 5
    Got it working by, in step 4, also doing "git add ." and "git add -u" in the root folder of the new repo, before proceeding to step 5. – jomni Mar 22 '15 at 16:37
  • 1
    For me, Johe's additional step mentioned above successfully resulted in Git recognising that certain files had moved. So, after doing the `git add .` and `git add -u`, going to VCS->Commit Changes and looking at the changes showed many in blue font together with a string after them saying "moved from..." to explain how the file had moved. Before, when I tried to Commit Changes without doing the step above, I'm pretty sure it was treating them all as new files. – Trevor Apr 03 '15 at 23:00
  • Has anyone tried, after doing the above, going *back* to a version of an app that was archived *before* moving from Eclipse to Android Studio? Is the VCS in Android Studio smart enough to edit the entire git history so that files in past commits are also moved to their new folders under Android Studio? Because if it is not, then there would not seem to be much advantage in doing the above, rather than just starting version control over again from scratch after the import. I mean, if you check out an old commit and it writes the files to their old Eclipse folders, what good is that? – Carl Mar 11 '16 at 12:37
3

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!

Alexander Zar
  • 325
  • 3
  • 14
1

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.

aap
  • 398
  • 1
  • 7
  • 1
    IT worked just by copying old .git directory into root of new Project Directory and doing VCS->Enable Revision Control. I have added an answer with step by step solution. – Shakti Malik Jul 14 '14 at 17:10