Snowcrash
Snowcrash

Reputation: 86097

git - checkout remote git code into Android Studio imported project with Gradle build

I've got some code that I imported into Android Studio.

It's now got a Gradle build (which it didn't have previously). I now need to do a git pull. However, given the directory structure has changed slightly I'm not sure how to go ahead with this.

The Android Studio directory structure under app/src/main looks similar to the original, e.g.:

Android Studio

[main]$ ls
AndroidManifest.xml assets          java            res
[main]$ ls java/
LICENSE.txt README.md   com

The original

$ ls
AndroidManifest.xml README.md       res
LICENSE.txt     assets          src
$ ls src/
com

Under com it's pretty similar except the reverse domain path is slightly different (e.g. com/original and com/new). i.e. it seems like the only significant file is AndroidManifest.xml that's in a different location. However, if I do a git pull it's going to put the AndroidManifest.xml in a different place and check out com/original on top of com/new.

Any suggestions how I deal with this?

Upvotes: 4

Views: 430

Answers (2)

Steve Bergamini
Steve Bergamini

Reputation: 14600

If the situation is such that this is an old Eclipse code base that you are migrating into Android Studio and you're going to still continue to use the same repository moving forward, I would suggest setting up the project "by hand" in android studio. In other words, don't use the automated import that moves files - source, resources, the AndroidManifest, etc. - to the default locations.

Keep everything in your original locations by defining where they are in the gradle build script "sourceSets" definitions. For example:

android {   
 sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']  
            }
...

}

This might be a simpler alternative.

Upvotes: 0

VonC
VonC

Reputation: 1324218

You need to reorganize first your files in order to match the target (that is the current Gradle structure)

  • clone your repo (anywhere else, not in your Android project)
  • do the relevant git mv, and then commit.
  • add your latest version:

    cd /path/to/local/clone
    git --work-tree=/path/to/gradle/project add .
    git commit -m "Import local dev"
    git push
    

(That will version any difference you might have done locally)

Then You can go back to your Android-gradle project, and do a git pull.

Upvotes: 5

Related Questions