android - 构建 gradle : Could not find method packagingOptions() for arguments root Project "fasterDev"

标签 android gradle build dependencies build.gradle

我在应用程序中使用单个 build.gradle 文件。 关于 1.6 版,它工作正常。 但我想用它来更新模块的位置。

apply plugin: 'com.android.application'
...

dependencies {
    compile 'com.google.android.gms:play-services:fp9.0.0'
}

这是我的 build.gradle。

构建.gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 15
    buildToolsVersion "21.1.2"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}  

对此有任何教程或建议吗?

日志:

org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: org.gradle.api.internal.MissingMethodException: Could not find method packagingOptions() for arguments [build_b54s9k8r9uto6awxmkxnu2ipo$_run_closure3@3a2d3196] on root project 'fasterDev'.
    at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:68)

最佳答案

您已经在 android 闭包之外提供了 packagingOptions,这就是 Gradle 假设的原因,它是某个根项目的方法。

只需将它移动到 android 闭包中,如:

android {
    ...

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }      
}

关于android - 构建 gradle : Could not find method packagingOptions() for arguments root Project "fasterDev",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37404374/

相关文章:

Android Studio 构建失败 - 任务 ':app:dexDebug' 执行失败

gradle - 使用 flyway 迁移 gradle 插件管理多个数据库

安卓工作室 "Your app does not have the latest code changes.."

android - 添加SQLCipher后如何测试数据库是否加密?

gradle - 如何正确编写 gradle-wrapper.properties 文件?

visual-studio - TFS 2010 - 每晚构建和测试

安卓工作室 : Create a simple Library and import in project

java - Ant 在 centos5.11 中失败,错误为 "Failed to locateorg.apache.tools.ant.Main"

java - DatagramChannel.receive() 导致 IndexOutOfBoundsException

java - 如何将ImageView链接到指定的电话号码?