Gradle: unsupported Gradle DSL method found: '

2019-05-25 12:55发布

问题:

Here's my dependencies section:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services-base:6.5.87'
    compile files('libs/unity/classes.jar') {
        exclude module: 'com.unity3d.player'
        exclude module: 'org.fmod'
    }
}

The gradle documentation shows this:

dependencies {
    compile("org.gradle.test.excludes:api:1.0") {
        exclude module: 'shared'
    }
}

So it looks to me like I at least have the syntax correct.

I found these SO answers:

Gradle failed: unsupported Gradle DSL method found: 'exclude()'

Unsupported Gradle DSL method found: 'exclude()'

And neither of them fixes my problem.

回答1:

This accomplishes what I want:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services-base:6.5.87'
    provided files('libs/unity/classes.jar')
}

The provided keyword apparently tells the system that the jar is needed for compilation, but will be provided externally, and doesn't need to be in the .aar file.