We have a project based on COCOS2DX + LUA, using PROTOBUF in the Network section, having to read the local file when initializing the Protobuf, and using Lua's io.open to read the file on Windows,ios is no problem. The app under Android is the APK file. Since the APK is a compressed file, Io.open is powerless because the entire app is compressed into one file.
On the Internet, the data can be read by calling the Getfiledata () function in Cocos2dx, getfiledata the different platforms by checking the contents of the file. Calling different interfaces to open and read files is still not a problem on iOS and Windows, and you can still not open files when you call read files on Android. It's not enough to try a lot of methods. Find a company and a colleague to help check. The problem is resolved after the path is changed.
String relativepath = "SCRIPTS/TEST.PB"; This is okstring relativepath = "./SCRIPTS/TEST.PB"; This can does not open the file "
at that time, we did not know why this can be solved. It was thought that Linux might not support this path. After home in the Linux experiment, even if I add a few "./" does not affect the open folder. Looking at the bottom of the cocos2d-x, found that the Android part is called the NDK in the Aassetmanager_open method, only can see the header file cannot see the source code. and then we searched Google for information about the function, and there was no gain,
StackOverflowQuestions.
Indeed, the great God answered, and quoted on GitHub on this part of the source code. Read the source to want to clear. The original is not to go through this path to open the file. Instead, go to a file manager to find, my file path has "./", and the original path to compare. Nature is not found, to this the doubt is eliminated.
This is the way to start a demo sample such as:
1, the advantages 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 only to see the document. Suppose the document was not written clearly. I think it's best not to use this kind of library. If you encounter problems, cry without tears.
2, sometimes in solving this problem, do not be too brave, technical staff feel that there is no solution to the problem, but sometimes it will happen: "Do not know the truth, just the edge of this mountain," he put himself around, find an outsider may suddenly found.
3, in the process of learning computer. Slowly accumulate, lay a good foundation, do not seek fast and new. In the face of real problems, but also to see the experience and foundation.
4, whether it is a book or celebrity said is not necessarily right. There are only things that are tested by computers. is the right one.
References:
1. on GitHub on this part of the source code
COCOS2DX Open file problem on Android platform