这个项目可能使用的是不包含方法'compileSdkVersion()'的Gradle版本。

19

当我尝试运行最初在Eclipse ADT上创建的项目时,我遇到了这个问题。

Error:(17, 0) Gradle DSL method not found: 'compileSdkVersion()'
Possible causes:<ul><li>The project 'TaxiAndroidOpen-master' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

我已经将它转换为Android Studio gradle系统。

但是由于这个错误,我不能运行也无法编译它。以下是生成的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.0.0'
   }
}
allprojects {
repositories {
    jcenter()
   }
}

ext {
compileSdkVersion 17
buildToolsVersion '18.1.0'
}
dependencies {
}

我在SO上找到了一些其他帖子,出现了类似的错误,但没有人遇到这个特定的错误。

我正在使用Android Studio 1.0.2,x86版本。

有人能够解决这个问题吗?

提前致谢!

编辑

更新后的build.gradle文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 17
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.opentaxi.android"
    minSdkVersion 9
    targetSdkVersion 19
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

dependencies {
compile project(':comtaxibulgariamap_mapsforge_044201406271417533')
compile files('libs/littlefluffylocationlibrary_r15.jar')
}
4个回答

16

您的应用程序模块的 build.gradle 文件应该像这样。

apply plugin: 'com.android.application'

android {
   compileSdkVersion 17
   buildToolsVersion "21.1.2"

defaultConfig {
     applicationId "com.opentaxi.android"
     minSdkVersion 9
     targetSdkVersion 19
  }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {

    compile project(':comtaxibulgariamap_mapsforge_044201406271417533')
    compile fileTree(include: ['*.jar'], dir: 'libs')
}

如果存在的话,请从应用程序根目录下的主 build.gradle 中删除您发布的这些行。

  ext {
      compileSdkVersion 17
      buildToolsVersion '18.1.0'
    }
    dependencies {
    }

9

最近升级到Android Studio 1.0了吗?如果是的话,请在您的app/build.gradle中用minifyEnabled替换runProguard。


1
在我的 app/build.gradle 文件中,没有 runProguard,而是使用了 "minifyEnabled false"。 - NeoVe
哦,还有"proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'" 有什么想法? - NeoVe
不会有任何问题。你能发一下你的app/build.gradle文件吗?那很可能是出问题的文件。 - Bill Mote

3

在build.gradle(模块)文件中添加下面这行内容,对我来说起作用了:

apply plugin: 'kotlin-kapt'


1
如果将实现文件放在错误的gradle中,也会出现此错误。

应该将其放在build.graddle(模块)内部。

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

不是在 build.gradle(App) 中,而是在 HTML 中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接