Tbadams
Tbadams

Reputation: 469

Get Android application lib directory

I need to specify the location of some native libraries in my Android application. I was accomplishing this with a hard-coded string:

public static final String DLL_DIR_STR = "/data/data/my.application.package/lib";

but wanted to get the path from Android instead. Following posts like this, I used getDir() to find the lib directory, changing

superCollider = new SCAudio(DLL_DIR_STR);

to

superCollider = new SCAudio(container.$context().getDir("lib", 0).getAbsolutePath());

Oddly, the initial libraries seem to load correctly

Trying to load lib /data/data/my.application.package/lib/libsndfile.so 0x42718d80
Added shared lib /data/data/my.application.package/lib/libsndfile.so 0x42718d80
No JNI_OnLoad found in /data/data/my.application.package/lib/libsndfile.so 0x42718d80, skipping init
Trying to load lib /data/data/my.application.package/lib/libscsynth.so 0x42718d80
Added shared lib /data/data/my.application.package/lib/libscsynth.so 0x42718d80

But when libscsynth tries to load some additional code, it's using the wrong path:

OK, listing opendir(/data/data/my.application.package/app_lib)

Any ideas where the "app_" comes from? I thought I must be using getDir() wrong, but the initial files load fine. Could it be something in the native code? Thanks for your help.

Upvotes: 1

Views: 5931

Answers (2)

Tbadams
Tbadams

Reputation: 469

I found the answer, quite by accident, in this post. ApplicationInfo.dataDir holds the location of the data directory, and "lib" is easily navigated to from there:

superCollider = new SCAudio(container.$context().getApplicationInfo().dataDir + "/lib");

Alternatively, nativeLibraryDir takes you directly to the lib directory, but requires API level 9.

Thanks for your help!

Upvotes: 2

Justin Morris
Justin Morris

Reputation: 7329

getDir will always prepend app_ to the directory name so it is very odd that it is working the first time. I would either just expect the app_ to be there or try using getFilesDir, at least you always know what it will return. Does SuperCollider have a restriction on what the directory name is?

I found another SuperCollider Project that seems to be doing the same thing you did initially with the comment "// TODO: not very extensible,".. I found that funny :)

Upvotes: 1

Related Questions