无法将Eclipse项目导入Android Studio

时间:2023-01-17 18:15:12

I'm trying to import an Android project build on Eclipse into my Android Studio IDE. I'm following the steps to import properly the project with a build.gradle file but when I'm trying to compile, I get this weird error: Plugin with id 'android' not found. I have this version of Android Studio: Android Studio (Preview) 0.4.3. Here is my build.gradle:

我正在尝试将Eclipse上的Android项目构建导入到我的Android Studio IDE中。我正在按照以下步骤使用build.gradle文件正确导入项目,但是当我尝试编译时,我得到了这个奇怪的错误:找不到ID为'android'的插件。我有这个版本的Android Studio:Android Studio(预览版)0.4.3。这是我的build.gradle:

 apply plugin: 'android'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':workspace:DesignDialogLibrary')
compile project(':workspace:HoloColorPickerLib')
compile project(':workspace:MbAdBleamSdkReaderLibrary')
compile project(':workspace:ViewPagerLibrary')
compile project(':workspace:PullToRefreshLibrary')
compile project(':workspace:SlidingMenuLib')
}

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

    instrumentTest.setRoot('tests')

    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
 }
}

1 个解决方案

#1


5  

You're missing this block in your build.gradle file:

您在build.gradle文件中缺少此块:

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

This block tells Gradle where to find the "android" plugin that you're missing.

这个块告诉Gradle在哪里可以找到你缺少的“android”插件。

It's standard in projects created in newer versions of Android Studio to put this in the build.gradle that's in your project's root directory and omit it from the one that's in your module's directory, so look there and see if looks like it's in order.

它是在较新版本的Android Studio中创建的项目中的标准,将它放在项目根目录中的build.gradle中,并从模​​块目录中的那个中省略它,所以看看它是否按顺序看起来。

If you don't have that root-level build.gradle file and you've only got one directory and one build file, then add this block to that file. Be aware, however, that Android Studio currently has a few bugs that prevent the Project Structure dialog from working properly with projects in this single-module format, though I believe they'll otherwise build and run fine.

如果您没有该根级build.gradle文件,并且您只有一个目录和一个构建文件,则将此块添加到该文件。但请注意,Android Studio目前有一些错误会阻止“项目结构”对话框与此单模块格式的项目一起正常工作,但我相信它们将构建并运行正常。

#1


5  

You're missing this block in your build.gradle file:

您在build.gradle文件中缺少此块:

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

This block tells Gradle where to find the "android" plugin that you're missing.

这个块告诉Gradle在哪里可以找到你缺少的“android”插件。

It's standard in projects created in newer versions of Android Studio to put this in the build.gradle that's in your project's root directory and omit it from the one that's in your module's directory, so look there and see if looks like it's in order.

它是在较新版本的Android Studio中创建的项目中的标准,将它放在项目根目录中的build.gradle中,并从模​​块目录中的那个中省略它,所以看看它是否按顺序看起来。

If you don't have that root-level build.gradle file and you've only got one directory and one build file, then add this block to that file. Be aware, however, that Android Studio currently has a few bugs that prevent the Project Structure dialog from working properly with projects in this single-module format, though I believe they'll otherwise build and run fine.

如果您没有该根级build.gradle文件,并且您只有一个目录和一个构建文件,则将此块添加到该文件。但请注意,Android Studio目前有一些错误会阻止“项目结构”对话框与此单模块格式的项目一起正常工作,但我相信它们将构建并运行正常。