Read Xml file from android assets folder

What i am currently working on is building c++ framework for SDL to make games for WIndows and Android

I am trying to implement a mini data base like Cocos2d-x UserDefault (if any are familar with cocos) where the you can read and write the basic types ( int, bool, float, string double) to an xml file i can get it working for windows side of things but for Android i am finding it difficult to access the xml file which is stored in the assets folder for now. When i run the apk it is not loading the file for me.

Has any one got experience with implementing this that could help me or point me in the right direction??

Thanks in advance

Android is really painful. I can’t even keep all the details in my
head. But here are a couple of things that jump into mind.

First, make sure you use the correct API to get the file and the
correct file path for that file. There is a difference between
something that is inside the APK vs something that is in external
storage. For SDL, SDL_GetBasePath() returns NULL I think for Android.
So you actually just request the file without a path when in the APK.
There is another API for the AndroidInternalStoragePath or something
like that.

Second, Android compresses certain file formats in the APK. XML might
be one of them. This pretty much breaks all non-Android Java APIs to
read files in the APK, probably including SDL’s. There is a way to
tell the build process not to compress certain files or extensions. I
don’t remember the details, but you’ll probably want to look into this
and make sure Android doesn’t compress any of your files.

Third, you need to verify your build system is actually putting your
file into the APK (and where you think it is). Again, too many details
to remember and I might be mixing stuff up, but there is something
like res/raw and assets. One is a weird Java-only system that you
should never use for NDK things like SDL, the other is what you should
be using (assets?).

-EricOn 2/21/16, Dobby90 <obrien.derek1 at gmail.com> wrote:

What i am currently working on is building c++ framework for SDL to make
games for WIndows and Android

I am trying to implement a mini data base like Cocos2d-x UserDefault (if any
are familar with cocos) where the you can read and write the basic types (
int, bool, float, string double) to an xml file i can get it working for
windows side of things but for Android i am finding it difficult to access
the xml file which is stored in the assets folder for now. When i run the
apk it is not loading the file for me.

Has any one got experience with implementing this that could help me or
point me in the right direction??

Thanks in advance

Eric Wing wrote:> On 2/21/16, Dobby90 <@Dobby90> wrote:

What i am currently working on is building c++ framework for SDL to make
games for WIndows and Android

I am trying to implement a mini data base like Cocos2d-x UserDefault (if any
are familar with cocos) where the you can read and write the basic types (
int, bool, float, string double) to an xml file i can get it working for
windows side of things but for Android i am finding it difficult to access
the xml file which is stored in the assets folder for now. When i run the
apk it is not loading the file for me.

Has any one got experience with implementing this that could help me or
point me in the right direction??

Thanks in advance

Android is really painful. I can’t even keep all the details in my
head. But here are a couple of things that jump into mind.

First, make sure you use the correct API to get the file and the
correct file path for that file. There is a difference between
something that is inside the APK vs something that is in external
storage. For SDL, SDL_GetBasePath() returns NULL I think for Android.
So you actually just request the file without a path when in the APK.
There is another API for the AndroidInternalStoragePath or something
like that.

Second, Android compresses certain file formats in the APK. XML might
be one of them. This pretty much breaks all non-Android Java APIs to
read files in the APK, probably including SDL’s. There is a way to
tell the build process not to compress certain files or extensions. I
don’t remember the details, but you’ll probably want to look into this
and make sure Android doesn’t compress any of your files.

Third, you need to verify your build system is actually putting your
file into the APK (and where you think it is). Again, too many details
to remember and I might be mixing stuff up, but there is something
like res/raw and assets. One is a weird Java-only system that you
should never use for NDK things like SDL, the other is what you should
be using (assets?).

-Eric


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for your reply but i have managed to get it working using in the end quite easily using SDL_rwops() to load file into a buffer and then i was able to parse the buffer to find the element i wanted