【发布时间】:2019-10-16 05:54:47
【问题描述】:
我正在使用 libfont:https://github.com/julienr/libfont 中的 native android 示例来制作可以显示文本的 Android C++ 应用程序。
构建工具是 Visual Studio https://devblogs.microsoft.com/cppblog/android-and-ios-development-with-c-in-visual-studio/。
C/C++ 代码位于 jni 子目录中,字体文件 LiberationSans-Bold.ttf 位于 libfont 示例的 assets 子目录中。
应用程序编译和构建正常,但字体文件未包含在最终的 .apk 中
//
// To test if the assets are in the assets directory
//
bool _testFont()
{
AAssetManager* manager = getApp()->activity->assetManager;
AAssetDir* assetDir = AAssetManager_openDir(manager, ""); // Open root assets dir, assetDir is not NULL
const char* fileName = AAssetDir_getNextFileName(assetDir); // Get first filename there -> fileName is NULL
}
//
// Original code
//
bool _loadFont()
{
LOGI("Loading font");
AAssetManager* manager = getApp()->activity->assetManager;
AAsset* fontFile = AAssetManager_open(manager, "LiberationSans-Bold.ttf", AASSET_MODE_BUFFER);
//
// Here fontfile is always NULL
//
if (!fontFile)
{
LOGE("Error loading font file");
return false;
}
const void* fontData = AAsset_getBuffer(fontFile);
off_t fontLen = AAsset_getLength(fontFile);
font = fontlib::FTLib::getInstance()->loadMemoryFont((const char*)fontData, fontLen, 30);
AAsset_close(fontFile);
if (!font)
{
LOGE("Error loading font");
return false;
}
return true;
}
所以我的问题是: 构建过程中的什么机制使链接器将资产目录中的文件带入?
【问题讨论】: