如何在Android studio中正确导入Android项目?

时间:2014-02-22 11:09:57

标签: java android gradle android-gradle

我一直在与Android Studio争夺2天,因为我无法在IDE中导入2个eclipse项目。这就是我所做的。

项目是2个Eclipse项目,我通过FILE>导出它们。出口>生成build.gradle文件。

当我尝试在Android Studio中导入项目时,出现此错误:

Failed to refresh Gradle project 'SourceFiles'
You are using Gradle version 1.11, which is not supported. Please use version 1.9.
Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (if applicable.)
Fix Gradle wrapper and re-import project Gradle settings

如您所见,我使用最新的gradle分发版(1.11版),但它仍然不起作用。 有人能告诉我在Android Studio中导入这些项目的正确方法吗?

我在 Linux OpenSuse版本13.1 Android Studio:0.4.2 Java:1.7

[编辑]我的项目由目录Sourcefiles组成,其中包含2个子目录SkeletonsTestcaseSkeletons包含源文件,TestCase包含与Skeletons中项目关联的测试用例。

以下是Eclipse生成的build.gradle: 在SourceFiles级别:

task wrapper(type: Wrapper) {
    gradleVersion = '1.9'
}

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

在Skeletons级别:

android {
    compileSdkVersion 18
    buildToolsVersion "19.0.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')
    }
}

在测试用例级别目录中:

apply plugin: 'android'

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

android {
    compileSdkVersion 18
    buildToolsVersion "19.0.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')
    }
}

我还必须承认我仍然是一个平庸的菜鸟。    我还在金丝雀频道更新了Android Studio最新版本,并在我的项目中引用了gradle 1.9 of gradle。 任何帮助将不胜感激。

我想使用Eclipse IDE,但它一直在崩溃。

1 个答案:

答案 0 :(得分:0)

最新的gradle版本有很多问题,你应该尝试使用较旧的版本,1.9很好。将其添加到根build.gradle并从控制台运行gradle wrapper

task wrapper(type: Wrapper) {
    gradleVersion = '1.9'
}

它应该在项目中创建一个gradle路径。之后,在命令行中使用gradlew而不是gradle,或者在Android Studio中创建项目时选择“可自定义的gradle wrapper”选项。

如果您遇到版本的其他问题,请在distributionUrl

中更改gradle\wrapper\gradle-wrapper.properties的值