1
我在Android Studio中有一個項目。我需要在這個項目中導入一個模塊:https://github.com/square/android-times-square/ 這個包裏有一個庫和一個樣本。我導入他們兩個。 我下載.ZIP和Android Studio中做文件 - >新建 - >導入模塊 而在此之後,我得到了graddle錯誤:未找到Gradle DSL方法:將模塊導入到項目後的'compileSdkVersion()'
Error:(16, 0) Gradle DSL method not found: 'compileSdkVersion()'
Possible causes:
The project 'MyProject' may be using a version of the Android Gradle plug-in that does not contain the method
(e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 2.3.3 and sync project. The project 'MyProject' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file. The build file may be missing a Gradle plugin.
Apply Gradle plugin
我點擊了此錯誤消息中列出的所有鏈接。但它沒有幫助。 Gradle腳本有什麼問題? 我不明白爲什麼有這麼多的文件的gradle和我需要修復(((
的build.gradle(MyProject的)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
compileSdkVersion 25
buildToolsVersion "25.0.2"
minSdkVersion 16
targetSdkVersion 25
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
的build.gradle(庫哪一個)
apply plugin: 'com.android.library'
apply plugin: 'checkstyle'
task checkstyle(type: Checkstyle) {
configFile rootProject.file('checkstyle.xml')
source 'src/main/java'
ignoreFailures false
showViolations true
include '**/*.java'
classpath = files()
}
afterEvaluate {
if (project.tasks.findByName('check')) {
check.dependsOn('checkstyle')
}
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
}
lintOptions {
warning 'MissingTranslation'
textReport true
textOutput 'stdout'
}
}
dependencies {
testCompile deps.festandroid
testCompile deps.junit
testCompile deps.robolectric
testCompile deps.intellijannotations
}
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
的build.gradle(樣品)
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileOptions {
sourceCompatibility rootProject.ext.sourceCompatibilityVersion
targetCompatibility rootProject.ext.targetCompatibilityVersion
}
defaultConfig {
applicationId 'com.squareup.timessquare.sample'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName '1.0.0'
}
lintOptions {
disable 'MissingTranslation'
}
}
dependencies {
compile project(':library')
}
的build.gradle(模塊:APP)
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.myproject.myproject2"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:25.3.1'
testCompile 'junit:junit:4.12'
}
settings.gradle
include ':app', ':sample', ':library'
謝謝。我更改了頂層文件(我只留下了compileSdkVersion和buildToolsVersion)。 – Evgenia
我還更改了模塊的gradle文件,因爲選項rootProject.ext.minSdkVersion和rootProject.ext.targetSdkVersion導致新的錯誤(它們不存在)。我將它們改爲數字。現在還有一個問題:錯誤:(46,1)評估項目':library'時發生問題。 >無法獲取類型爲org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的對象的未知屬性'deps'。 – Evgenia
@Evgenia我的腳本就是一個例子。你也可以使用'minSdkVersion','targetSdkVersion',但是如上面所報告的那樣,使用與'='相同的語法。 –