找不到方法cppFlags()arguments()作为参数 [英] Could not find method cppFlags() arguments() for arguments

查看:405
本文介绍了找不到方法cppFlags()arguments()作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

std::function

但是编译器会抛出错误

Error:(50, 10) error: no type named 'function' in namespace 'std'

我试图修改build.gradle文件

I have tried to modify the build.gradle file

externalNativeBuild {
    ndkBuild {
        path "src/main/jni/Android.mk"
    }
    cmake {
        cppFlags "-std=c++11"
        arguments "-DANDROID_STL=gnustl_static"
        path 'src/main/jni/CMakeLists.txt'
    }
}

但是它不接受path以外的参数,并引发以下错误

But it doesn't accept arguments other than path and throws the following errors

Error:(28, 0) Could not find method arguments() for arguments [-DANDROID_STL=gnustl_static] on object of type com.android.build.gradle.internal.dsl.CmakeOptions.

请帮助我使用

std::function

更新

感谢 @Alex Cohn ,我能够配置标志和参数,现在我的文件看起来像这样

Thanks to @Alex Cohn I was able to configure flags and arguments, and now my file looks like that

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11"
                arguments "-DANDROID_STL=gnustl_static"
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        /*   ndkBuild {
               path "src/main/jni/Android.mk"
           }*/
        cmake {
            // cppFlags "-std=c++11"
            //arguments "-DANDROID_STL=gnustl_static"
            path 'src/main/jni/CMakeLists.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-annotations:25.0.1'
}

推荐答案

build.gradle 中有两个完全不同的块,它们被命名为 externalNativeBuild (感谢Google)

There are two entirely different blocks in build.gradle that are named externalNativeBuild (thanks, Google).

一个 android 顶级块下,它指定本机生成脚本 cmake ndkBuild 的路径(但不能同时包含两者)

One is under android top-level block, and it specifies the path to native build script, cmake or ndkBuild (but not both).

其他可用于从gradle中指定本机版本的一些参数.此块通常是 defaultConfig 块的子代,但也可以显示风味(请参见

The other can be used to specify, from gradle, some parameters for the native build. This block is usually a child of the defaultConfig block, but can also appear for flavors (see an example).

这些 externalNativeBuild 块也可以具有 cmake ndkBuild 子级,但是只有与 path 匹配的子级设置(请参见上文)是相关的,其他设置则被忽略.

These externalNativeBuild blocks can also have cmake or ndkBuild children, but only the child that matches the path setting (see above) is relevant, the other is silently ignored.

最重要的是,将您的块分成两部分,然后将每个块放置在 build.gradle 层次结构中的正确位置.

The bottom line, split your block in two, and put each one in correct place in build.gradle hierarchy.

这篇关于找不到方法cppFlags()arguments()作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆