Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 27
Registered: ‎08-06-2012
My Device: PlayBook
My Carrier: Cosmote
Accepted Solution

NDK Assets folder

It seams that applications perform differently when debugged - run on the device (PlayBook tablet) and when they are signed.

 

I have included some files in my assets folder

eg:

app/native/assets/Home/myfile.dat

 

and at some point in my code I have: 

std::string strFile = "app/native/assets/Home/myfile.dat";

FILE* pFile = fopen( strFile.c_str(), "r+b" );

if ( pFile )

{

// do something

}

 

the above code works ok when running an unsigned application whether its a debug or release version. The moment I sign my .bar and upload it on the device the fopen fails.

 

Calling:

if (stat(strFile.c_str(), &sts) != 0 )

     fprintf(...., "%d, %s\n", errno, strerror(errno) );

 

To check the reason for failing I get the error code: 3 which is: No such process

On the other hand if I have:

FILE* pFile = fopen( strFile.c_str(), "rb" );

then the code runs ok and pFile != NULL

 

As I said It seams that applications perform differently when debugged - run on the device (PlayBook tablet) and when they are signed.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: NDK Assets folder

The entire app/ folder (contents of the .bar file, unpacked) are read-only when running on the device as a signed app.

In debug mode, they're writable, but that's intended solely to support development capabilities such as updating only some of the files, to speed deployment.

Apps should/can never actually modify their own assets or code, and all files that need to be delivered with the app but changed at runtime must be copied over to the data/ folder the first time the app is launched.

See https://developer.blackberry.com/native/documentation/com.qnx.doc.native_sdk.devguide/com.qnx.doc.na... for some background.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 54
Registered: ‎05-23-2012
My Device: Developer
My Carrier: Developer

Re: NDK Assets folder

Information is a bit thin in that and related links. How do I access the /data folder with fopen()? How do I use the $HOME environment variable in code?
----
I know exactly where the problem *might* be.
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: NDK Assets folder

You should start a new thread. New questions posted in answered threads don't usually get many eyes on them, and they're not as helpful as new threads for people who are trying to search for answers.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 54
Registered: ‎05-23-2012
My Device: Developer
My Carrier: Developer

Re: NDK Assets folder

[ Edited ]

I don't think it should be a new question. It's directly related and compliments the information you provided. I came to this thread with the exact same fopen() issues in the signed BAR as the OP. Anyway, here's what I found for others who come to this thread:

 

The $HOME environment variable contains the full path to your app's /data directory. You can get it and contruct a path like so: 

 

char* homeData = getenv("HOME");

sprintf(filePathBuf, "%s/my_file.mf", homeData);

...

remove(filePathBuf);                        // (1) Delete existing file if present.

FILE* pStream = fopen(filePathBuf, "a+b");  // (2) Create new file.

 

I can confirm both (1) and (2) now work for me in a signed BAR.

 

See: https://developer.blackberry.com/native/reference/com.qnx.doc.neutrino.lib_ref/topic/g/getenv.html

 

 

----
I know exactly where the problem *might* be.