we have a project based on the COCOS2DX + LUA, in the network part of the use of PROTOBUF, in the initialization of protobuf need to read local files, with Lua Io.open read files on the Windows,ios is no problem, Android app is apk file, because the APK is compressed file, so Io.open powerless, because the entire app is compressed into a file. The data can be found on the Internet by calling the Getfiledata () function in COCOS2DX to read the contents of the file, getfiledata by detecting different platforms, invoking different interfaces to open and read files, on iOS and Windows still no problem, You can still not open the file when you call it on Android. Try a lot of methods can not, find the company another colleague to help view, will be modified after the path to solve the problem.
String relativepath = "SCRIPTS/TEST.PB"; This is okstring relativepath = "./SCRIPTS/TEST.PB"; This can does not open the file "
At that time, we do not know why this can be solved, at that time thought might be Linux does not support this path, home after the Linux experiment, even if I add a few "./" does not affect the Open directory. Looking at the bottom of the cocos2d-x, I found that the Android part is the Aassetmanager_open method in the called NDK, only to see the source code in the header file. and then we searched Google for information about the function, and there was no gain,
StackOverflowask questions. There is a big God answer, and quoted on GitHub on this part of the source code, read the source code to understand that the original is not to go through this path to open the file, but go to a file manager to find, my file path has "./", and the original path to compare, nature is not found, to this this doubt eliminated. This event is inspired by the following:
1, the benefits of open source, in the face of problems only need to look at the source code can be, relatively closed source of things, encountered problems can only go to view the document, if the document is not written clearly, I think such a library is best not to use, once encountered problems to cry without tears.
2, sometimes in solving the problem, do not be too brave, technical staff think there is no solution to the problem, but sometimes it will happen: "Do not know the truth, only the edge of this mountain," he put himself around, find an outsider may suddenly found.
3, in the process of learning computer, bit by bit slowly accumulate, lay a good foundation, do not seek fast and new, in the real encounter problems, but also to see the experience and foundation.
4, whether it is the book or celebrity said is not necessarily right, only through the computer test things, is correct.
Reference:
1.The
source code for this section on GitHub
COCOS2DX Open file problem on Android platform