Android.mk compilation summary of various files

Posted by bhola on Thu, 03 Feb 2022 15:00:10 +0100

Hello, everyone. Meet again. I'm Jun Quan.

1, Source code compilation

1.1 so precompiling

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libAppArea
LOCAL_SRC_FILES :=libAppArea.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX:=$(HOST_JNILIB_SUFFIX)
LOCAL_CERTIFICATE:=platform
LOCAL_PRELINK_MODULE := false
include $(BUILD_PREBUILT) 

1.2 share lib compilation

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
#LDFLAGS	+=	-ldl
LOCAL_LDLIBS    := -ldl -lm -llog -llibc
LOCAL_MODULE    := libnandFlashReadPage_jni
LOCAL_SRC_FILES := nandFlashReadPage_jni.cpp\

LOCAL_SHARED_LIBRARIES := libdl\
	liblog\
	libpre_NandRecognition\
	libpre_AppArea\
	libc\
	libstdc++
	
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

Upgrade to Android 4.0. It turned out that some of the programs we compiled under version 3.2 could not be compiled.

especially

Copy apk and Android of dynamic library MK file, after research. The solution is as follows.

Error message: The following variables have been changed: PRODUCT_COPY_FILES.  Stop.

Solution: the following examples are for reference. Each is a copy APK; SO; ZIP; db; jpg

Suppose there is another better way.

Please leave a message.

   LOCAL_PATH:= $(call my-dir) 
   
   ###################################### 
   
   #COPY PayMent APK 
   
   include $(CLEAR_VARS) 
   
    
   
   LOCAL_MODULE :=  PayMent 
   
    
   
   #Output payment Apk file folder
   
   LOCAL_MODULE_PATH := $(TARGET_OUT)/app/ 
   
   LOCAL_SRC_FILES :=../3rd-apk/PayMent/PayMent.apk 
   
     
   
   LOCAL_MODULE_TAGS := optional  
   
   LOCAL_MODULE_CLASS := APPS 
   
   #APPS,JAVA_LIBRARIES,SHARED_LIBRARIES,STATIC_LIBRARIES,EXECUTABLES 
   
   LOCAL_MODULE_SUFFIX:=$(COMMON_ANDROID_PACKAGE_SUFFIX) 
   
    
   
   LOCAL_CERTIFICATE:=platform 
   
   LOCAL_SDK_VERSION := current 
   
    
   
   include $(BUILD_PREBUILT) 
   
    
   
   ###################################### 
   
   #COPY SpeechService APK WITH xx.so 
   
   include $(CLEAR_VARS) 
   
    
   
   #need modify here 
   
   LOCAL_MODULE :=  SpeechService 
   
   LOCAL_MODULE_PATH := $(TARGET_OUT)/app/ 
   
   LOCAL_SRC_FILES :=../3rd-apk/IFlyService/SpeechService.apk  
   
   #need modify here 
   
    
   
   #optional if you have .so;need add  COPY so file 
   
   LOCAL_JNI_SHARED_LIBRARIES:=libmsc 
   
    
   
   LOCAL_MODULE_TAGS := optional  
   
   LOCAL_MODULE_CLASS := APPS 
   
   LOCAL_MODULE_SUFFIX:=$(COMMON_ANDROID_PACKAGE_SUFFIX) 
   
    
   
   LOCAL_CERTIFICATE:=platform 
   
   LOCAL_SDK_VERSION := current 
   
    
   
   include $(BUILD_PREBUILT) 
   
    
   
   ###################################### 
   
   #COPY SpeechService so file   
   
   include $(CLEAR_VARS) 
   
   #need modify here 
   
   LOCAL_MODULE :=  libmsc 
   
   LOCAL_SRC_FILES :=../3rd-apk/IFlyService/libmsc.so 
   
   #need modify here 
   
    
   
   LOCAL_MODULE_TAGS := optional  
   
   LOCAL_MODULE_CLASS := SHARED_LIBRARIES 
   
   LOCAL_MODULE_SUFFIX:=$(HOST_JNILIB_SUFFIX) 
   
    
   
   LOCAL_CERTIFICATE:=platform 
   
   LOCAL_PRELINK_MODULE := false 
   
    
   
   include $(BUILD_PREBUILT) 
   
    
   
   ############################################ 
   
   #copy many so files 
   
   #=========================================== 
   
   include $(CLEAR_VARS) 
   
    
   
   LOCAL_MODULE :=  BaiduInput_Pad 
   
   LOCAL_MODULE_PATH := $(TARGET_OUT)/app/ 
   
   LOCAL_SRC_FILES :=../3rd-apk/BaiduIME/BaiduInput_Pad.apk 
   
    
   
   LOCAL_MODULE_TAGS := optional 
   
   LOCAL_MODULE_CLASS := APPS 
   
   LOCAL_MODULE_SUFFIX:=$(COMMON_ANDROID_PACKAGE_SUFFIX) 
   
    
   
   LOCAL_JNI_SHARED_LIBRARIES:= ../3rd-apk/BaiduIME/libkpenoem_api_so.so \ 
   
               ../3rd-apk/BaiduIME/libtmfe30.so \ 
   
               ../3rd-apk/BaiduIME/libinputcoreoem-2.so 
   
    
   
   LOCAL_CERTIFICATE:=platform 
   
   LOCAL_SDK_VERSION := current 
   
    
   
   include $(BUILD_PREBUILT) 
   
    
   
   #========================================== 
   
   #make exe file  
   
   include $(CLEAR_VARS) 
   
   LOCAL_SRC_FILES:= xxx.c 
   
        
   
   LOCAL_MODULE := TestBusy 
   
   LOCAL_MODULE_TAGS := eng 
   
   LOCAL_STATIC_LIBRARIES := libcutils libc 
   
   #EXTRA_LDLIBS := -lpthread # -lrt 
   
   #EXTRA_CFLAGS := -DRUN_IN_TARGET 
   
    
   
   LOCAL_MODULE_CLASS :=EXECUTABLES 
   
   include $(BUILD_EXECUTABLE) 
   
    
   
   #========================================== 
   
   #cp zip file; or other txt jpg db files 
   
   LOCAL_PATH:= $(call my-dir) 
   
   include $(CLEAR_VARS)  
   
    
   
   LOCAL_MODULE := data-bak 
   
   LOCAL_SRC_FILES := data-bak.zip 
   
    
   
   LOCAL_MODULE_PATH := $(TARGET_OUT)/../recovery-bak 
   
    
   
   LOCAL_MODULE_TAGS := optional 
   
   LOCAL_MODULE_CLASS := SHARED_LIBRARIES  
   
   LOCAL_MODULE_SUFFIX:= .zip 
   
   #LOCAL_MODULE_SUFFIX:= .txt  
   
   
LOCAL_CERTIFICATE:= PRESIGNED 
   
   LOCAL_PRELINK_MODULE := false 
   
    
   
   include $(BUILD_PREBUILT)  
   LOCAL_PATH:= $(call my-dir) 
   
   #cp .jpg file  
   
   #===========================================  
   
   include $(CLEAR_VARS)  
   
    
   
   LOCAL_MODULE := bg 
   
   LOCAL_SRC_FILES := overlay/packages/apps/Settings/res/drawable/bg.jpg 
   
    
   
   LOCAL_MODULE_PATH := $(TARGET_OUT)/../data/data/com.lenovo.nebula.settings/files 
   
    
   
   LOCAL_MODULE_TAGS := optional 
   
   LOCAL_MODULE_CLASS := SHARED_LIBRARIES 
   
   LOCAL_MODULE_SUFFIX:= .jpg 
   
    
   
   #platform shared media PRESIGNED 
   
   LOCAL_CERTIFICATE:= PRESIGNED 
   
   LOCAL_PRELINK_MODULE := false 
   
    
   
   include $(BUILD_PREBUILT)  
   
    
   
   #cp .mp4 file  
   
   #===========================================  
   
   include $(CLEAR_VARS)  
   
    
   
   LOCAL_MODULE := oobeletvintroduce 
   
   LOCAL_SRC_FILES := packages/apps/OOBE3D/res/drawable/oobeletvintroduce.mp4 
   
    
   
   LOCAL_MODULE_PATH :=  $(TARGET_OUT)/app 
   
    
   
   LOCAL_MODULE_TAGS := optional 
   
   LOCAL_MODULE_CLASS := SHARED_LIBRARIES 
   
   LOCAL_MODULE_SUFFIX:= .mp4 
   
    
   
   #platform shared media PRESIGNED 
   
   LOCAL_CERTIFICATE:= PRESIGNED 
   
   LOCAL_PRELINK_MODULE := false 
   
    
   
   include $(BUILD_PREBUILT)  

Note: LOCAL_PATH: = $(call my DIR) this variable, in an android There can only be one in the MK file.

Multiple LOCAL_PATH will have an error.

And include $(CLEAR_VARS)

And include $(build_prebuild)

Can be multiple.

In the following, I use a simple practical example to explain how to import static libraries into dynamic libraries.

The source code in the static library has two files: static h, static. c. There is an add method

static.h#include <stdio.h> int add(int x, int y);static.c#include "static.h" int add(int x, int y) {     return x + y; }

Compile it into a static library. Android.mk for example:

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE    := static_add LOCAL_SRC_FILES := static.c include $(BUILD_STATIC_LIBRARY)

Note that when compiling the static library, there must be an application MK file:

APP_MODULES:=static_add

APP_ The value of modules should be the same as Android Local in MK_ The value of module remains the same.

Then call ndk-build to compile and generate libstatic_. add. A static library.

hejinlai_iMac:jni hejinlai$ ndk-build Prebuilt : libstatic_add.a <= jni/

After generating the static library, then write the source code in the dynamic library: share h share. c

share.h
#include <stdio.h> 
int test_add(int x, int y);
share.c
1234567 #include "share.h"
#include "static.h"
int test_add(int x, int y) 
{ 
    // Call the method in static 
    return add(x, y); 
}

Write android.com that imports static libraries mk:

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE    := static_add LOCAL_SRC_FILES := libstatic_add.a include $(PREBUILT_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE    := share_add LOCAL_STATIC_LIBRARIES := static_add LOCAL_SRC_FILES := share.c include $(BUILD_SHARED_LIBRARY)

Note the libstatic generated above_ add. A must follow Android MK in the same folder, otherwise you need to fill in the corresponding path, and then compile:

hejinlai_iMac:jni hejinlai$ ndk-build Compile thumb : share_add <= share.c Prebuilt : libstatic_add.a <= jni/ SharedLibrary : libshare_add.so Install : libshare_add.so => libs/armeabi/libshare_add.so

Prompt that so compilation is successful.

It should be noted that I share C and static C put it in the same folder. If it is placed in different folders, it needs to be specified

LOCAL_C_INCLUDES links to the corresponding path.

1, Eclipse integrates third-party jar packages and so dynamic library

Create the folder libs and libs/armeabi under MyMapsproject, and put Baidu mapapi Jar in the libs / folder of, and put libbmapapiengine_ v1_ 3_ 1. Put so under libs/armeabi /.

In Eclipse, the third-party jar package Baidu map API Steps to package jar into MyMaps:

1. Right click project. Select Properties;

2. Java Build Path, select Libraries.

3. On the Libraries page, click the button "Add Library..." on the right;

4. Select "User Library" and click "Next";

5. Click "User Libraries" button;

6. Click "New..." in the pop-up interface;

7. Enter "User library name". Click "OK" to confirm;

8. After return. Select the User library just created and click "add jars" on the right;

9. Select Baidu mapapi under MyMaps/libs / jar.

10. Confirm and return.

So. After compilation. The jar package will be typed into mymaps In APK, libBMapApiEngine_v1_3_1.so is also packaged in lib/armeabi /.

During program execution, libBMapApiEngine_v1_3_1.so is placed under / data / data / < yourapppackage > / lib /. When loading the dynamic library, the system will look under the Lib / folder of the program so library.

2, Third party integration jar packages and are integrated in the source code so dynamic library

In the Android source code, MyMaps is placed under packages/apps. Create the folder libs and libs/armeabi under MyMaps. And put Baidu map API Jar in libs /, libbmapapiengine_ v1_ 3_ 1. Put so in libs/armeabi.

2.1 change Android MK file

Android.mk file, for example:

[plain] view plaincopy

  1. LOCAL_PATH:= $(call my-dir)  
  2. include $(CLEAR_VARS)  
  3. LOCAL_MODULE_TAGS := optional  
  4. LOCAL_STATIC_JAVA_LIBRARIES := libbaidumapapi  
  5. LOCAL_SRC_FILES := $(call all-subdir-java-files)  
  6. LOCAL_PACKAGE_NAME := MyMaps  
  7. include $(BUILD_PACKAGE)  
  8. ##################################################  
  9. include $(CLEAR_VARS)  
  10. LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES :=libbaidumapapi:libs/baidumapapi.jar  
  11. LOCAL_PREBUILT_LIBS :=libBMapApiEngine_v1_3_1:libs/armeabi/libBMapApiEngine_v1_3_1.so  
  12. LOCAL_MODULE_TAGS := optional  
  13. include $(BUILD_MULTI_PREBUILT)  
  14. # Use the following include to make our testapk.  
  15. include (callall-makefiles-under,(LOCAL_PATH))  

1 integration jar package

LOCAL_STATIC_JAVA_LIBRARIES takes the alias of the jar library. Can take values at will;

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES specifies the rules of prebuiltjar library, format: alias: jar file path.

Note: alias must be the same as local_ STATIC_ JAVA_ The aliases in libraries are consistent. And does not contain jar; The jar file path must be the real path where the third-party jar package is stored.

Build for compilation_ MULTI_ PREBUILT.

2 integration so dynamic library

LOCAL_PREBUILT_LIBS specifies the rule of prebuilt so, format: alias: so file path.

Note: aliases cannot be changed, especially for third-party jar packages So library, and does not contain so; The so file path must be the real path where the third-party so files are stored.

Build for compiling and copying_ MULTI_ PREBUILT.

2.2 added to grandrated_ USER_ MODULES

In file user_tags.mk, put libBMapApiEngine_v1_3_1 added to grandrated_ USER_ In modules

[plain] view plaincopy

  1. GRANDFATHERED_USER_MODULES += \  
  2.     ... \  
  3.     libBMapApiEngine_v1_3_1  

user_tags.mk can be under build/core. It can also be under target_device_dir. Recommended changes (TARGET_DEVICE_DIR).

2.3 compilation results

MyMaps.apk is compiled and generated under out / target / product / < yourproduct > / system / APP /;

libBMapApiEngine_ v1_ 3_ 1. Put so under out / target / product / < yourproduct > / system / lib /. This is also the search path when the system loads the dynamic library.

2.4 precompiled static library in source code

Test passed

LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := libKL15APIA      #LOCAL_SRC_FILES := libKL15APIA.aLOCAL_PREBUILT_LIBS := libKL15APIA.aLOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)LOCAL_CERTIFICATE:=platforminclude $(BUILD_MULTI_PREBUILT)  

Reference blog: http://blog.csdn.net/zhangchiytu/article/details/6424910

Publisher: full stack programmer, stack length, please indicate the source for Reprint: https://javaforall.cn/115545.html Original link: https://javaforall.cn