Android third-party dynamic link library so called to resolve a function call that is not open to Java, resolving class name alignment issues

Source: Internet
Author: User

So library for the Android version of the connection library (*.so file) role: As long as the development to provide us with interface instructions, we can directly do interface testing, no longer need to grab a packet to analyze, to reduce the technical difficulty of interface testing

The general project calls its own so by placing the so file directly under Libs/armeabi, then system.loadlibrary ("XXX") in the code, and then public native static int xxx_xxx_xxx () Next, you can call the Xxx_xxx_xxx () method directly;

But one problem is that you must align the class name, and you cannot tune a function that is not open to Java

For example: These are the only calls that are open to the outside, because this involves java,c the platform call

The next step is to solve how this kind of undefined method calls

The way to do this is to create your own so file, call third-party so in your own so file, and call your own so in the program.

Based on the last (Android Dynamic link Library series-writing so)

1. Write a so yourself first

Then add the following to so:

Jstring Java_com_abso_jnigg2_callxg (jnienv* env, Jobject thiz)
{
jstring ret;
So path:/data/data/The package name of my program/lib/my so file name
void * FileHandle = Dlopen ("/data/data/com.abso/lib/libjninetutil.so", Rtld_lazy);
void * FileHandle = Dlopen ("/data/data/com.abso/lib/libgame.so", Rtld_lazy); ###### #com. ABSO is our package name
if (filehandle)
{
char * (* Funcptra) (void) = NULL;
Funcptra = Dlsym (FileHandle, "tiffgetversion");
if (Funcptra)
{
ret = (*env)->newstringutf (env, Funcptra ());
}
Else
{
ret = (*env)->newstringutf (env, "Dlsym zlibversion failed!");
}
Dlclose (FileHandle);
}
Else
{
ret = (*env)->newstringutf (env, "Dlopen failed!");
}
return ret;
}

So the code is to let go of the Three Kingdoms for example

2. Then add the code and then run Ndk-build to generate our

3. Copy libgame.so to this directory

4. Call in Android

5. After running the program, the results are as follows:

Android third-party dynamic link library so called to resolve non-Java-open function calls to resolve class name alignment issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.