Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ndk AssetManager和本机代码_Android Ndk - Fatal编程技术网

Android ndk AssetManager和本机代码

Android ndk AssetManager和本机代码,android-ndk,Android Ndk,我有一个config.txt文件。在apk生成期间,使用nocompress extension=“txt”选项不会压缩该文件。然后我在java代码资产管理器中打开并将其传递给本机函数。最后,我使用下面的代码打开一个文件*。 问题是,当调用fgets(第32行,文件)-其中第32行是char*-时,第行的内容不是文件的第一行 AAssetManager* mgr = AAssetManager_fromJava(env, assetManager); if(NULL == mgr) return

我有一个config.txt文件。在apk生成期间,使用nocompress extension=“txt”选项不会压缩该文件。然后我在java代码资产管理器中打开并将其传递给本机函数。最后,我使用下面的代码打开一个文件*。 问题是,当调用fgets(第32行,文件)-其中第32行是char*-时,第行的内容不是文件的第一行

AAssetManager* mgr = AAssetManager_fromJava(env, assetManager);
if(NULL == mgr) return -1;
AAsset* asset = AAssetManager_open(mgr, "config.txt", AASSET_MODE_UNKNOWN);
if (NULL == asset) {
    return -1;
}
off_t start, length;
int fd = AAsset_openFileDescriptor(asset, &start, &length);
if (fd < 0)
    return -1;
 FILE * file = fdopen(fd, "r");
AAssetManager*mgr=AAssetManager_fromJava(env,assetManager);
if(NULL==mgr)返回-1;
AAsset*asset=AAssetManager_open(mgr,“config.txt”,AAsset_MODE_未知);
如果(空==资产){
返回-1;
}
关闭开始,长度;
int fd=AAsset\u openFileDescriptor(资产、开始和长度);
如果(fd<0)
返回-1;
文件*FILE=fdopen(fd,“r”);
如(搜索“static const char*kNoCompressExt”)中所示,txt不在排除列表中,可能已被压缩! 实际上,这会导致fd小于零