Android ndk usage Common Errors

Source: Internet
Author: User
Document directory
  • Andorid ndk uses a brief process [from overview.txt In the android ndk document]
  • 1. Make: *** no rule specified and no make file found. Stop.
  • 2. Make: *** no rule to make target "xxxxxx", needed by "ndk-app-XXXXX". Stop.
  • 3. Make: *** [xxxx] errror 1
  • 4. crash when running the program. At this time, we need to pay attention to the following issues:
Andorid ndk uses a brief process [from overview.txt In the android ndk document]

Here's a very rough overview of how you can develop native code with the android ndk:

1/run build/host-setup.sh to configure the ndk
2/place your native sources under $ Project/JNI /...
3/Write $ Project/JNI/Android. mk to describe your sources to the ndk build system
4/Write apps/<MyApp>/application. mk to describe your application and the native sources it needs to the ndk build system
5/build your native code by running "make APP = <MyApp>" in the top-level ndk directory.

The last step will copy, in case of success, the stripped shared
Libraries your application needs to your application's root Project
Directory. You will then need to generate your final. APK through
Usual means.

According to the above steps, we will describe the possible errors in each step. [step 1, we will not detail them here. There are many good articles on the Internet ].

Common Errors:

1. Make: *** no rule specified and no make file found. Stop.



The cause of the error is estimated to be (Cat: Linux Command, display file content): The project name is inconsistent with app_moudles in aplication. mk.

2. Make: *** no rule to make target "xxxxxx", needed by "ndk-app-XXXXX". Stop.

The main cause of this error is: compiling the c file as the final so library file requires two files: application. mk and Android. mk, as shown in:

How to Set up the MK file. After reading the figure above, you can see the [Detailed description or document]. Pay attention to the following points:

  • Check whether the relative path of the file is correct (app_project_path in application. mk sets the relative path), as shown in:

    These are strictly regulated in Android ndkzhong and detailed in Android-ndk documents.
  • Project File Name
    In aplication. mkApp_moudles
    In Android. mLocal_src_files
    Yes
    No. Local_src_files in Android. m is the name of the output library file. [ndk adds the default prefix lib (if
    Local_src_files is already started with lib and will not be added), and the suffix. So], but after trying to find this place must be in
    App_moudles is consistent. Otherwise, the above error will occur.
3. Make: *** [xxxx] errror 1

This error is a compilation error of C and cannot be compiled by C code.

How to compile the function description in the C file [Native file? To export a C/C ++ native file from a Java source file, see the following four steps:

1)Compile the Java file [Java sources: contains the native function we need]
, As shown in:

2)Run javac jnitest. JVA & javah jnitest
, Two files are added after the command is run:

Jnitest. JVA compiled files jnitest. Class and jnitest. H. This file is the header file we need, as shown in:

3)Modify function name
, How to modify? Let's first analyze the example program in Android-ndk:

The preceding example shows that the function name is divided into four parts:

You can follow the above rules to modify it.

4) copy the above function declaration and create a *. c file in the JNI file. Follow the above function structure.Implementation Functions
, As shown in:

In this wayJava source file
Step by stepC/C ++ native File
.

4. crash when running the program. At this time, we need to pay attention to the following issues:

Library file loading
:

The compiled so file is libjnitest. So, and the actual file name of the loaded library is jnitest [This is actually a Unix "standard", in Android
The ndkfile overview.txt has a detailed description]; and the Linux system is case sensitive, so if the code above writes the loaded library file name as jnitest
This will cause a running crash.

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.