错误:(41,0)提供的字符串模块符号'0.12.2'无效

Fai*_*ikh 3 android android-build build.gradle android-gradle-plugin

我正在将Eclipse项目导入Android Studio,并且在导入项目时遇到以下错误:

Error:(41, 0) Supplied String module notation '0.12.2' is invalid. Example notations: 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'.
Open File
Run Code Online (Sandbox Code Playgroud)

这是我的build.gradle文件:

apply plugin: 'android'

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

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.0'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
        }

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

buildscript {
    dependencies {
        classpath '0.12.2'
    }
    repositories {
        mavenCentral()
    }
}
allprojects {
    repositories {
        mavenCentral()
    }
}
Run Code Online (Sandbox Code Playgroud)

我在以下行得到错误:

classpath '0.12.2'
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 5

您的脚本似乎很旧。

您应该使用以下方式更改行classpath '0.12.2'

classpath 'com.android.tools.build:gradle:0.12.2'
Run Code Online (Sandbox Code Playgroud)

我希望这个脚本应该还有其他一些问题。

  • 将您的Android Studio更新到最新的稳定版本(2.1)
  • 使用 apply plugin: 'com.android.application'
  • 使用 classpath 'com.android.tools.build:gradle:2.1.0'
  • 使用更新更新gradle版本(gradle/wrapper/gradle-wrapper.propertiesdistributionUrl = https\://services.gradle.org/distributions/gradle-2.10-all.zip