在 Android Studio 导入期间维护目录结构 [英] Maintaining directory structure during Android Studio import

查看:22
本文介绍了在 Android Studio 导入期间维护目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经克隆了一个公共 github 存储库并尝试将其导入 Android Studio 0.4.4.导入效果很好,但它想将所有源复制到一个新目录并为源创建一个app"目录.由于我使用的是公共存储库,因此我想使用存储库克隆的目录并保持目录结构完整,这样我就可以获取更新和推送更改,而无需以任何方式复制文件.

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.

有没有办法告诉 Android Studio 在导入时保留给定的目录结构?

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

或者,换句话说,有没有办法跳过 gradle 转换并按原样导入源?

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

提前谢谢.

推荐答案

目前我们在 Eclipse 项目导入中没有保留现有目录结构的选项.如果您安装了 Eclipse 的副本,您可以在那里打开它,然后将项目导出到 Gradle 构建文件;就地导出.您必须修改它导出的构建文件,因为它指定了一个非常旧的插件版本.具体来说,您必须更新 dependencies.buildscript.classpath 语句以指定 0.8.+,并更新 gradle/wrapper/中的 distributionUrl 属性gradle-wrapper.properties 文件来指定 Gradle 1.10.

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.

如果您没有 Eclipse,您可以使用这个样板 build.gradle 文件来开始.复制到项目根目录:

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')
    }
}

接下来,将这个 settings.gradle 文件放在您的根目录中.

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

include ':'

接下来,将 gradlewgradlew.bat 文件和 gradle 目录从您创建的另一个项目的根目录复制到在您的项目中安装包装器.

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.

完成了.您现在应该可以在 Android Studio 中导入并使用它.

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

这篇关于在 Android Studio 导入期间维护目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆