Take the hello Android project as an example.
Build a projecthello-a, InjniCreate a file under the Directoryhello-a.c,The file content is as follows. (Note that the JNI directory will cause errors when compiling with the src directory.)
#include <stdio.h>int main(){ printf("Hello Android!\n"); return 0;}
In this directory, createAndroid.mkFile, the content is as follows:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS)LOCAL_MODULE:= helloaLOCAL_SRC_FILES := hello-a.cinclude $(BUILD_EXECUTABLE)
Note that the red section above specifies that an executable file is to be generated.
Run under projectndk-build, Error message returned:
This prompt tells us that it is not found in the projectAndroidmanifest. xmlFile. IfJavaThe application automatically generates the file. In this file,Describes a global variable of the package, including the application components (activities, services, and so on) and the Implementation class of each component, the data that can be operated, and where the program runs. Here, we do not need this file. So why is there such an error prompt?
In fact, this is related to the ndk version. The latest version is my ndk R4 version. A major change to the previous version is the change to the source file path and organizational structure of the project. In ndk R3, after the ndk is installed, you need to run Setup. sh to create the compilation environment, you need to create a project with the same name under the <ndk> apps/directory, and then add the application. MK, and then execute make APP = yourproject during compilation. In the new version, you do not need to create an app project with the same name. You can directly use the ndk-build compilation tool. This tool is actually an encapsulation of the build compilation tool. Each compilation will automatically set a compilation environment and then call android in the project. MK to compile the project, the original application. MK is not required either. It is created only when necessary. Compared with the previous version, the androidmanifest. xml file is checked.
How can we solve this problem? There are two methods: one is to manually create an androidmanifest. xml file, and the content is empty, as shown in
<?xml version="1.0" encoding="utf-8"?><manifest/>
Run againndk-build, Successful.
Let's try to run normally:
SeeHello Android!Succeeded.
Although this method solves the problem, it does not understand the essence of the problem. Well, keep the strong momentum and desire for knowledge, and there is a second solution.
Let's take a look at the developer's description of this problem:
"Themanifest is only required to find the top-level of your project path (ndk-build can be invoked in any sub-directory of your project )."
So we only need to specify the project path before compilation. What should we do? Simple!
Ndk-build ndk_project_path =/path/to/Project
Okay. Let's try it.
Ndk compilation executable program