gpt4 book ai didi

Android Studio 2.2.3 找不到

转载 作者:行者123 更新时间:2023-11-29 19:26:01 24 4
gpt4 key购买 nike

配置

操作系统:Ubuntu 16.04

Android Studio 版本:2.2.3

关键代码

~/project/build.gradle :

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

~/project/library/build.gradle :

apply plugin: 'com.android.library'

android {
...

defaultConfig {
...

externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang',
'-DANDROID_STL=gnustl_static'
// I also tried '-DANDROID_STL=gnustl_shared', result is same
}
}
}

externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
}
}

...
}

~/project/app/build.gradle :

apply plugin: 'com.android.application'

android {
...
}

dependencies {
...
compile project(':library')
...
}

~/project/settings.gradle

include ':app', ':library'

~/project/library/src/main/cpp/test.h :

#include <vector>   // vector is red, says "cannot find vector"
#include <stdint.h>

class test {

private:
std::vector<int32_t> array; // std is red, says "can't resolve container std"
};

问题描述

在文件中~/project/library/src/main/cpp/test.h , vector#include <vector>是红色的。当我将鼠标移到它上面时,它会弹出一个窗口,上面写着 Cannot find 'vector' . stdstd::vector<int32_t>也是红色的。我将鼠标移到它上面,它显示 Can't resolve container 'std' .

这个项目没有编译错误。可以编译成功并安装到我的手机上。问题是它有语法错误。我没有对某些变量进行代码补全,例如 arraytest.h .

我找到的一些资料

我导入了项目 teapots其中包含 #include <vector> .Android Studio 确实解决了 vectorstd这个项目的符号。

我的问题

我做错了什么?为什么项目 teapots没有这个问题?我的项目和 teapots 之间的主要区别是什么?这使得后者能够解决 vectorstd但我的不是?


更新

我在 Android Studio 中创建了一个新项目。在新项目向导的第 1 步中,我检查了 include C++ Support .在最后一步,我保留了默认值 Toolchain Default对于 C++ Standard选项。在我点击 finish 之后按钮,Android Studio 自动创建文件 native-lib.cpp为我。我添加了代码 #include <vector>在此文件的第 3 行。这次Android Studio解析符号vector正确。然后我创建了一个新的模块库 mylibrary对于这个项目,我在其中添加了一个 cpp文件夹和 test.h它还解析了符号 vector (mylibrary 模块的 build.gradle 已由我正确添加了 CMake 内容)。但我的问题是我需要添加 vector到我现有的项目,我现有的项目无法解析符号 vector .

最佳答案

我想通了。我没有在 CMakeLists.txt 中包含 C++ 文件 test.h。一旦我将它包含到 CMakeLists.txt add_library 括号和同步项目中,红色语法错误就消失了。

关于Android Studio 2.2.3 找不到 <vector>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41393423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com