简体   繁体   English

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

[英]How to properly import Android projects in Android studio?

I have been fighting with Android Studio for 2 dayys because I cannot import 2 eclipse projects in the IDE.Here what I have done. 我已经与Android Studio战斗了2天,因为我无法在IDE中导入2个eclipse项目。

The projects are 2 Eclipse projects and I export them by doing FILE > EXPORT > Generate build.gradle files. 这些项目是2个Eclipse项目,我通过执行FILE> EXPORT> Generate build.gradle文件将其导出。

When I try to import the projects in Android Studio, I have this error : 当我尝试在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

As you see I use the latest distribution of gradle (version 1.11) and it still does not work. 如您所见,我使用了最新版的gradle(1.11版),但仍然无法正常工作。 Can someone show me the proper way to import those projects in Android Studio? 有人可以告诉我在Android Studio中导入这些项目的正确方法吗?

I am on Linux OpenSuse version 13.1 Android Studio : 0.4.2 Java : 1.7 我在Linux OpenSuse版本13.1 Android Studio:0.4.2 Java:1.7

[EDIT] My project is comprised of directory Sourcefiles which contains 2 sub-directories Skeletons and Testcase . [编辑]我的项目由目录Sourcefiles组成,其中包含2个子目录SkeletonsTestcase Skeletons contains the source files and TestCase contains the test case associated with the project in Skeletons . Skeletons包含源文件, TestCase包含与Skeletons中与项目关联的测试用例。

Here are the build.gradle generated by Eclipse : In SourceFiles level : 这是Eclipse生成的build.gradle:在SourceFiles级别:

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

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

In the Skeletons level : 在“骨骼”级别:

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

In the testcase level directory : 在测试用例级别的目录中:

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

I also have to admit that I am still a noob in gradle. 我还必须承认,我仍然是菜鸟。 I also updated the Android Studio the latest version in the canary channel and references the verison 1.9 of gradle in my project. 我还在canary频道中更新了Android Studio的最新版本,并在我的项目中引用了gradle的Verison 1.9。 Any help would be appreciated. 任何帮助,将不胜感激。

I would want to use the Eclipse IDE but it keeps crashing. 我想使用Eclipse IDE,但是它一直崩溃。

Latest gradle versions have many issues, you should really try to use an older one, 1.9 is fine. 最新的gradle版本有很多问题,您应该尝试使用旧版本,1.9很好。 Add this to the root build.gradle and run gradle wrapper from console: 将其添加到root build.gradle并从控制台运行gradle wrapper

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

It should create a gradle path in your project. 它应该在您的项目中创建一个gradle路径。 After that, use gradlew instead of gradle in command line or pick a "customizable gradle wrapper" option when creating a project in Android Studio. 此后,在Android Studio中创建项目时, gradle在命令行中使用gradlew代替gradle或选择“可自定义的gradle包装器”选项。

If you'll encounter further issues with versions change the value of distributionUrl in gradle\\wrapper\\gradle-wrapper.properties 如果你会遇到其他问题与版本改变的值distributionUrlgradle\\wrapper\\gradle-wrapper.properties

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM