如何在不创建存储库重组副本的情况下将eclipse项目导入Android Studio? [英] How do I import an eclipse project into Android Studio without creating a reorganized copy of the repo?

查看:293
本文介绍了如何在不创建存储库重组副本的情况下将eclipse项目导入Android Studio?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个当前在Eclipse中开发的Android项目.我想过渡到Android Studio,而又不失去使用Eclipse的能力.

I have an Android project currently developed in Eclipse. I would like to transition to Android Studio, without losing the ability to fall back on Eclipse.

当我导入非android studio项目"时,将创建存储库的副本,并重新组织目录结构以符合gradle样式.

When I import a "non android studio project", a copy of my repository is made, and my directory structure is reorganized to conform to the gradle style.

我的问题是,如何在不重新组织目录结构的情况下就地导入我的存储库?

My question is, how can I import my repository in-place, without reorganizing the directory structure?

推荐答案

您将需要手动设置build.gradle文件.然后,当您导入Android Studio时,它将看到build.gradle文件并使用它,而不是执行重组过程.

You will need to set up your build.gradle file manually. Then, when you import into Android Studio, it will see the build.gradle file and use it, rather than go through the reorganization process.

这是一个起始文件build.gradle,您可以将其放入Eclipse项目目录:

Here is a starter build.gradle file you can drop into your Eclipse project directory:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

apply plugin: 'com.android.application'

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

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"

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

您需要调整的主要内容是:

The big things that you will want to adjust are:

  • compileSdkVersion,它应该与您用于Eclipse的构建目标相匹配(请参见project.properties文件)

  • the compileSdkVersion, which should match the build target that you are using for Eclipse (see your project.properties file)

buildToolsVersion,其中应引用您已在SDK Manager中安装的构建工具"(其中"21.1.2"是当前最新版本)

the buildToolsVersion, which should reference a "Build-tools" that you have installed in the SDK Manager (where "21.1.2" is the currently-latest version)

上面的注释之所以存在,是因为该文件以从Eclipse导出的文件开头,就像您在当前的ADT插件上一样,您可以导出build.gradle文件.但是,该插件已经有一段时间没有更新了,我希望它将生成的build.gradle文件在很大程度上被破坏.

The comments shown above are there because the file started with one exported from Eclipse, as if you are on the current ADT plugin, you can export a build.gradle file. However, that plugin has not been updated in quite some time, and I expect that the build.gradle file it would generate would be largely broken.

您可能还希望设置一个基本的Gradle包装器,以简化导入过程.为此,请在Eclipse项目根目录下创建一个gradle/wrapper/gradle-wrapper.properties文件,其中包含以下内容:

You may also wish to set up a basic Gradle wrapper, to smooth the import process. To do that, create a gradle/wrapper/gradle-wrapper.properties file off your Eclipse project root, with the following contents:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip

这里最重要的是distributionUrl,它指向Gradle的正式发行版,特别是Android Studio 1.0和适用于Android 1.0的Gradle的2.2.1.

The big thing here is the distributionUrl, which points to an official Gradle distribution, specifically the 2.2.1 that Android Studio 1.0 and Gradle for Android 1.0 like.

因此,将这两个文件添加到Eclipse项目中,然后Android Studio应该就地导入而无需任何文件重组.

So, add those two files to your Eclipse project, and then Android Studio should import-in-place without any file reorganization.

您可以看到以这种方式设置的数百个项目.

这篇关于如何在不创建存储库重组副本的情况下将eclipse项目导入Android Studio?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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