Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
781 views
in Technique[技术] by (71.8m points)

git - Maintaining directory structure during Android Studio import

I have cloned a public github repository and am trying to import it into Android Studio 0.4.4. The import works great, but it wants to copy all the source to a new directory and creates an 'app' directory for the source. Since I am using a public repo, I want to use the repo cloned directory and keep the directory structure in tact so I can get updates and push changes without having to copy files every which way.

Is there a way to tell Android Studio to keep the given directory structure on an import?

Or, put another way, Is there a way to skip the gradle conversion and import the source as is?

Thanx in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

At present we don't have an option in Eclipse project import to preserve the existing directory structure. If you have a copy of Eclipse installed you could open it there and then export the project to Gradle build files; that does an in-place export. You'd have to modify the build files it exports since it specifies a very old version of the plugin. Specifically, you'll have to update the dependencies.buildscript.classpath statement to specify 0.8.+, and also update the distributionUrl property in the gradle/wrapper/gradle-wrapper.properties file to specify Gradle 1.10.

If you don't have Eclipse, you can use this boilerplate build.gradle file to get you started. Copy it into the project's root directory:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

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

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

Next, put this settings.gradle file in your root directory.

include ':'

Next, copy the gradlew and gradlew.bat files and the gradle directory from the root directory of another project you've created to install the wrapper in your project.

It's complete. You should now be able to import it in Android Studio and use it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...