我更新了Android工作室的插件。现在当我尝试打开现有项目时,我收到了一个错误。
Error:(10, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'TuteSample' may be using a version of Gradle that does not contain the method.
The build file may be missing a Gradle plugin.
这是我的build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
compile "com.android.support:appcompat-v7:21.0.+"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files }
}allprojects {
repositories {
jcenter()
}
}
答案 0 :(得分:4)
确保将依赖项放入单个模块的build.gradle文件中,而不是放在最顶层的build.gradle文件中。将您的依赖项放置为:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:21.0.+"
}
将compile "com.android.support:appcompat-v7:21.0.+"
添加到Module build.gradle中:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "your_package_name"
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:21.0.+"
}
顶级build.gradle将是:
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files }
}allprojects {
repositories {
jcenter()
}
}
答案 1 :(得分:2)
将compile 'com.android.support:appcompat-v7:21.0.+'
从项目build.gradle复制到模块bulid.gradle中。喜欢这个文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "xxxx"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.0.+'
}