未找到 Android Studio Gradle DSL 方法 : compile() while adding slf4android dependency

标签 android gradle android-gradle-plugin android-studio-2.0 slf4android

我正在尝试使用来自 https://github.com/bright/slf4android 的 slf4android 依赖项但是 gradle sync 有问题。

Build.gardle(项目)


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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Build.gardle(应用程序)


apply plugin: 'com.android.application'<p></p>

<p>android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0 rc2"</p>

<pre><code>defaultConfig {
    applicationId "com.example.vinod.myapplication"
    minSdkVersion 21
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
</code></pre>

<p>}
buildscript {
    repositories {
        maven { url "<a href="http://jitpack.io" rel="noreferrer noopener nofollow">http://jitpack.io</a>" }
    }
    dependencies {
        compile('com.gitghub.bright:slf4android:0.1.0'){
            transitive = true
        }
    }
}</p>

<p>dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile('com.gitghub.bright:slf4android:0.1.0'){
        transitive = true
    }
}</p>

<p></p>

我收到的错误:


Error:(26, 0) Gradle DSL method not found: 'compile()'
Possible causes:<li>The project 'My Application' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>

我是 android 编码的新手,不知道我错过了什么。请帮忙。

最佳答案

url“http://jitpack.io”应该进入项目级 build.gradle 而不是模块级。

将项目级构建 gradle 的 allProjects 更改为此:

allprojects {
    repositories {
        jcenter()
        maven {url "https://jitpack.io"}
    }
}

然后从 app build.gradle 中删除 jitpack url 并同步你的项目。

关于未找到 Android Studio Gradle DSL 方法 : compile() while adding slf4android dependency,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36671560/

相关文章:

android - 我怎样才能重新创建 fragment ?

android - 我在构建 gradle 时遇到此错误错误 :Execution failed for task ':app:processDebugResources' . > 没有从属进程来处理作业,正在中止

java - Gradle 同步失败 : Unsupported method: SyncIssue. getMultiLineMessage()。 (安卓工作室)

java - 如何从gradle的测试 jar 中运行测试?

android - 使用选定的风格将 Android 库 (aar) 发布到 Bintray

android - Dalvik VM 找不到多种方法

java - 应用程序崩溃....NullPointerException

android - 如何从 Sqlite ( android ) 中的日期时间字段获取日期

android - Android Studio-如何使用Gradle将资源文件包含在Java包中

gradle - STS Gradle 工具是指 build.gradle 文件的过时版本