构建 build.gradle 文件后无法将 Android 项目从 Eclipse 导入到 Android Studio

Cannot import an Android project from Eclipse to Android Studio after building a build.gradle file

我从 Eclipse 生成了一个 Android 项目的 Gradle 文件,以便继续在 Android Studio 中处理该项目。然后我导入 Gradle 文件以在 Android Studio 中打开项目,但非常令人困惑的是它无法构建项目,显示以下消息。

Error:SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

我一直在 Android Studio 中处理其他 Android 项目,在这个问题上没有问题,所以我变得很困惑。我也搜索了关于同一件事的问题,但其中 none 似乎明确提出了解决方案。

为了让您更好地理解,我向您展示几个与构建项目相关的内容。

1. build.gradle

 apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:appcompat-v7:22.2.0'
    }

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc3"

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

2。 local.properties

sdk.dir=/Users/marshall/android-sdks

AndroidSDK按照上面那个方向安装正确。我现在该怎么办?

正在 ANDROID 工作室中导入 ECLIPSE 项目:

如果要在 Android Studio 中导入 Eclipse 项目:

1. 启动 Android Studio Select导入项目(Eclipse ADT、Gradle等)

2. 然后没什么特别的,只需按照向导中的说明进行操作即可。

注意: 请确保您选择了包含 src 文件夹的 Eclipse 项目文件夹。并确保目标文件夹为空。 您不需要创建 build.gradle 或从 Eclipse 导出任何东西,因为 Android Studio

不再需要这些步骤