"Android Development" NDK Development (3)-JNI Development Tips

Source: Internet
Author: User

First, JNI print debugging information

1. Add the following in the android.mk file:

Local_ldlibs + =-l$ (sysroot)/usr/lib-llog

  2 . Add the following in the. c File:

#include <android/log.h>

3. Print log information:

__android_log_print (Android_log_info, "Init_getgpsinfo", "Get_gps_info"); // or  "Init_getgpsinfo", "LAN =%f", LAN);

Ii. calls to third-party . So or . So.1 dynamic-link Libraries

If a call to a third-party . so or. so.1 link library is used in the project, it is not feasible to call the method name directly in the library, and you can use the dlopen and dlsym functions as follows:

1 //open a link library2 3 void*handle = Dlopen ("Libapi.so.1", Rtld_now);4 5 //declares a "local" method, the first int is the method return type, Get_number is the method name, and the second int in parentheses is the parameter type6 7 int(*get_number) (int);8 9 //binds the declaring "local" method to a method in the class library, writes only the method name, does not write the parameterTen  OneGet_number = Dlsym (handle, "Get_number"); A  - //Method Invocation -  the intA = 0; -  - intNumber = Get_number (a);

the path of the System.load () function

In (b), a link library that references a third party needs to be added to the project, but using method System.loadlibrary ("Libapi.so.1") often does not work, and the System.load () method can be used.

The System.load () method needs to provide the absolute path to the link library, which is relative to the Android filesystem, and can put the libapi.so.1 file in the System/lib directory, called by:

System.load ("/system/lib/libapi.so.1");

Iv. using the ADB push file to the Android file system

If there is a need to copy files to the emulator's file system, then you might think of a way to tell the emulator root, but this step is often difficult, but you can use the following method to copy files to the file system, without the need for root.

1, first create a new AVD "MYAVD"

2. At the command line, enter:

EMULATOR-AVD myandroid-partition-size 128-no-snapshot-load

3. After the simulator is fully open, enter the following command to obtain write access to the/system system directory:

adb shell Mount-o rw,remount-t yaffs2/dev/block/mtdblock0/system

4. Use the Push command to copy the file to the emulator file system (su is the file name):

ADB push su/system/xbin/

To view the emulator's file system, you can use the ADB shell command to enter the emulator's terminal.

Another: Execute permissions for files:

ADB shell chmod 06755/system/xbin/su

v. Use of wireless ADB

The use of wireless adb, eliminating the link of the data line is very convenient!

If there is a need for the project, Android needs to connect both the PC and the external module, so the wireless ADB will greatly facilitate your program debugging.


Related Article

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.