How to load android libraries when running binary files? - android

So, I have this executable binary file that references some libraries. When I try to run it with runtime.exec(), it gives me an error on the error stream saying:
link_image[1891]: 7176 could not load needed library 'XXX.so' for 'YYY' (load_library[1093]: Library 'XXX.so' not found)CANNOT LINK EXECUTABLE
I have the XXX.so library but I have no idea where I should place it relative to the binary YYY. I want this to work for unrooted device.
Btw, I'm not very good with the building stuff in general, so if you think there's something wrong I did when I built the binary, feel free to point that out.

You have two choices
build this binary with -static flag, I think this is the best way
you can use dlopen to load this library dynamicly, such as
void *g_handle = NULL;
g_handle = dlopen("/system/lib/libskia.so", RTLD_LAZY);
_skFT_Init_FreeType = dlsym(g_handle, "FT_Init_FreeType");
/**do something */
dlclose(g_handle);

Please see https://stackoverflow.com/a/12934668 where yours truly proposed wrapper to set LD_LIBRARY_PATH in a generic way. You can use ProcessBuilder with modified environment, too. See https://stackoverflow.com/a/8962189/192373.

Related

Any library to read mdict *.MDX files in android?

I have a .mdx file that infact is a dictionary database (some android apps like bluedict can read its data).
I have used Daemon.tools but it could not open it.
I was looking for any library or sources which helps me to read MDX dictionary files in Java, I have found some resources already such as KnIfER/mdict-java but it does not work in Android Studio (it has errors on accumulation_blockId_tree.xxing(new myCpr(position,1)).getKey().value line and it is connot resolve symbol 'value'). Does any one knows a good source about these files and possible libraries which could be used for it?.
Well, actually this is my java project.
the error mentioned is just a problem of jdk version. you can add <> parentheses after myCpr and convert return of xxing to type myCpr<Integer,Integer> .
But now, I have very much reduced usage of rbtree and use more binary list searching.have a look there.

How to read .docx on Android with Apache Poi

I have .docx file in assets folder and use this part of code to to read it
AssetManager am = context.getAssets();
InputStream is;
is = (InputStream) am.open("amaretti.docx");
XWPFDocument hdoc=new XWPFDocument(OPCPackage.open(is));
and jars for this are:
poi.jar
poi-ooxml.jar
But shows me an error:
08-27 18:16:31.660: I/dalvikvm(23221): Could not find method org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1$Factory.newInstance, referenced from method org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentCreate
I guess some jar or classes are missing.
Any suggestion would be useful.
Thanks in advance
You're missing some jars. In order to read Word 2007 files using POI you also need the following libraries (they're all available in the archive you download from the official Apache POI site):
poi-ooxml-schemas (the one you're getting the error about)
xmlbeans
dom4j
stax
According to the official website, dom4j and stax are no longer needed but I found I had problems when I didn't add them.
Unfortunately, you're bound to discover that adding all of these libraries will result in a Dalvik dex error (an Android classes.dex can hold up to 64k of method declarations, which you will cross). The "official" explanation for this is that POI is simply not designed for Android. Unfortunately I have not been able to find an easy, manageable solution for that problem (there have been attempts, some partially successful, of porting POI to Android, but they're too cumbersome for my taste). I solved that problem by sending the Word 2007 files to a remote server, converted them to the old format and returned to the mobile device to be opened by POI.

Why SDL_Window is an incomplete type?

I am porting to SDL2 and the Android platform a C++ game that uses SDL 1.2. Everything went well so far except for one thing: when I try to access the fields of SDL_Window, the compiler tells me
error: invalid use of incomplete type 'SDL_Window {aka struct SDL_Window}'
I think my installation of SDL may be faulty. I have compiled SDL 2.0.0 from the source found on libsdl.org using the folloing command:
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_PLATFORM=android-18
Then, I have copied the freshly built libSDL2.so into $ANDROID_TOOLCHAIN/sysroot/usr/lib and the files in the include/ directory in $ANDROID_TOOLCHAIN/sysroot/usr/include/SDL. These files are given to CMake and referenced by the game's code. I managed to convert every SDL calls and now I am stuck with this SDL_Window problem.
I did a quick search in SDL's source code and found that SDL.h includes SDL_video.h which contains a typedef SDL_Window on struct SDL_Window. Then I searched for this struct and did not find anything except in the original source archive, in a file named src/video/SDL_sysvideo.h. Since it is not a file of the API, I doubt I have to include it in my code.
So, how to find a definition of SDL_Window in SDL2, for Android (if this is relevant)?
It appears that the problem is a lack of knowledge of SDL 2's API. Let's remember that one does not access the fields of struct SDL_Window: there are functions to get the size and the flags of the window, such as SDL_GetWindowFlags and SDL_GetWindowSize.
So the problem is absolutely not related to the installation of the SDL or to Android builds. Sorry for the waste of time, people of the Web.
I would expect that you are expected to only deal in pointers to SDL_Window objects, and not actually put a full SDL_Window object on the stack.

jni problems when system load the .so file

I have already created .so file and put it in proper path.
However,when I try to run the android program the problem came by.
the problem is:
`5-16 15:34:16.704: E/AndroidRuntime(9968): Caused by: java.lang.UnsatisfiedLinkError:
Cannot load library: reloc_library[1311]: 1584 cannot locate '_Z13raptor_decodePKhtPKtPhjPK15RaptorParam_tag'...
raptor_decode is a function which included by the jni_function.`
what should i do to correct this problem? Thanks.
I think here is your problem:
1584 cannot locate '_Z13raptor_decodePKhtPKtPhjPK15RaptorParam_tag'
if raptor_decode is the method you want to call, read up here: http://java.sun.com/docs/books/jni/html/design.html (and read up 11.3)

dlsym returning symbol not found in android after succesful return of dlopen

I am loading one shared library from another. Lets say foo2.so from foo1.so
I am using dlopen followed by dlsym
dlopen succeed with proper handle but dlsym returns with "symbol not found" error .I have used dlerror to print the error.
These are the things i tried. In foo2.so .mk file I added
LOCAL_LDFLAGS += -Wl,--export-dynamic.
I checked the symbol in foo2.so using nm and it is there.
Both the modules are in C except one wrapper file in foo1.so which is in C++, Calling file is in C.
Can any one suggest whether i missed any thing . I am running this on android emulator on froyo.
I would be tempted to poke around at the implementation level and verify things. Look in /proc/PID#/maps and make sure both libraries are loaded.
objdump both caller and callee and make sure that C++ bit didn't mangle the name.
Are you using a suitable RTLD_ flag, and is dlsym getting a valid handle returned by dlopen ?
Can you build (a simplified version of) the two libraries and test executable for a desktop linux or cygwin in order to make sure what you want to do is generally workable - ie, that the problem is android-specific?

Categories

Resources