HarmonyOS 鸿蒙Next中在windows上找不到c++文件只会显示proj.ohos中的文件
HarmonyOS 鸿蒙Next中在windows上找不到c++文件只会显示proj.ohos中的文件 在windows上使用deveco 5.0.1打开cocos2dx的native的鸿蒙工程,只会显示proj.ohos目录下的文件,c++源码都显示不出来,无法添加断点。在mac下就可以
2 回复
请问您的工程是native的工程么?如果不是,请创建native工程,参考链接如下:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/create-with-ndk-V5
请验证一下代码:
native读取沙盒文件
#include "ReadFile.h"
#include <bits/alltypes.h>
#include <node_api.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include "hilog/log.h"
#define LOGI(format, args) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "logI", format, args);
napi_value ReadFile::Readfile(napi_env env, napi_callback_info info){
napi_status status;
napi_value file_name;
size_t argc = 1;
// 获取arkts传递过来的文件路径
status = napi_get_cb_info(env, info, &argc, &file_name, NULL, NULL);
if (status != napi_ok)
return NULL;
// 确保传入的参数是字符串
napi_valuetype valuetype;
status = napi_typeof(env, file_name, &valuetype);
if (status != napi_ok)
return NULL;
if (valuetype != napi_string) {
napi_throw_type_error(env, NULL, "Expected a string");
return NULL;
}
// 获取路径字符串内容
size_t strSize;
char strBuf[256];
napi_get_value_string_utf8(env, file_name, strBuf, sizeof(strBuf), &strSize);
std::string dirName(strBuf, strSize);
LOGI("===============file path%s", strBuf);
if (status != napi_ok)
return NULL;
// 打开文件
FILE *file = fopen(strBuf, "r");
if (file == NULL) {
LOGI("===============open file fail%s", "=====");
return NULL;
}
//读取文件内容
size_t size;
ssize_t read;
char *line;
line = (char *)malloc(64);
while (read = getline(&line, &size, file) != EOF) {
LOGI("===============文档输出%s", line);
}
// 关闭文件
if (file) {
fclose(file);
}
return nullptr; // 返回undefined
}
arkts创建文件
createFile(filesDir: string): void {
// 新建并打开文件
let file = fs.openSync(filesDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
// 写入一段内容至文件
let writeLen = fs.writeSync(file.fd, "Try to write str.");
console.info("The length of str is: " + writeLen);
// 关闭文件
fs.closeSync(file);
}
更多关于HarmonyOS 鸿蒙Next中在windows上找不到c++文件只会显示proj.ohos中的文件的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,如果你在Windows上找不到C++文件,只显示proj.ohos
中的文件,可能是由于项目配置或IDE设置问题。proj.ohos
是鸿蒙项目的默认目录结构,通常包含项目的配置文件和资源。C++文件可能未被正确识别或未包含在项目视图中。
检查项目的CMakeLists.txt
或BUILD.gn
文件,确保C++源文件和头文件路径正确配置。如果使用DevEco Studio,查看项目结构设置,确认C++文件是否被包含在项目视图中。若问题依旧,尝试清理项目缓存并重新导入项目。