4

I have an Android project as Git repository based on Eclipse old build system etc. Is it possible to import him into Android Studio in order to make migration, such that from Git perspective, we not loss information?

Example: If we move files between dirs inside Git repository, Git still knows about it and we have this metadata and therefore can track changes in the code to the point before the AS migration happened (because it's same file that moved and the history of location stored and tracked). But it seems that the migration process is "more than just move files between dirs etc", So how does it affects? Also I want to distinguish between:

  1. Simple Project - Usually the automated AS migration toll handle this.
  2. Complex Project - Manuel migration (even starting new project & copy-paste files).

Thanks,

michael
  • 3,835
  • 14
  • 53
  • 90
  • Possible duplicate of [Import an eclipse android project with version control system into Android Studio](http://stackoverflow.com/questions/24726041/import-an-eclipse-android-project-with-version-control-system-into-android-studi) – bmaupin Mar 17 '17 at 17:14

4 Answers4

3

The way I did this was something like this:

  1. Make sure you have pulled all the latest things

  2. Import the project to Android Studio from File - Import project. This creates the project in a new folder. For more details, see the official documentation.

  3. Copy .git directory and .gitignore from the old project folder to the new project folder

  4. Modify .gitignore so that .gradle/, .idea/ and all .iml files are ignored

  5. git add -A, then git status - it should show the files as renamed.

  6. Commit & push

1615903
  • 32,635
  • 12
  • 70
  • 99
1

Create a branch in git as :

git checkout -b android_studio_code
git push origin android_studio_code

This woul track the files seperatly or if you wanna maintaing the same repo, you could anytime be back with commit id as :

git reset --hard <sha-id>

or forcefully merge the new project as :

git push -f origin master
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
1

I'm not sure you really have to think about git until you have to include CI builds that increment the versioning automatically.

If you just want to keep your file structure you can specify the locations of everything.

android {
    ...
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
}
JBirdVegas
  • 10,855
  • 2
  • 44
  • 50
  • The OP wants to know how to preserve the git information in their old Eclipse project hierarchy. For example, the OP might need to go back to a prior version of project source. So unless I'm mistaken, this does not address the question. – Carl Mar 11 '16 at 03:18
0

Basically you should use the following steps:

  1. Start Android Studio and close any open Android Studio projects.
  2. From the Android Studio menu select File > New > Import Project.
  3. Select the Eclipse ADT project folder with the AndroidManifest.xml file and click Ok. enter image description here
  4. Select the destination folder and click Next. enter image description here
  5. Select the import options and click Finish enter image description here

Since you will import from your local project, your git settings should be imported too.

See here for more details.

dan
  • 13,132
  • 3
  • 38
  • 49