The writing of various Android.mk under Android source code

Original address: https://blog.csdn.net/tkwxty/article/details/43341217

The writing of various Android.mk under Android source code
The new year is coming, the company is in recession, so there are not many things to be busy. Just take the time to summarize the writing of various modules Android.mk under Android source code! I won't describe Android.mk's syntax and details in detail here, because there is a lot of knowledge about this on the Internet. I'm listing several frequently used module writing examples here. I hope it can help the new Android people who are developing under the Android source code. There is no more nonsense and it goes straight to the example.
1. Write and generate a common APK. The APK does not contain the. so file or reference the third-party jar package
  1. # Copyright 2011 The Android Open Source Project  
  2.   
  3. LOCAL_PATH:= $(call my-dir)  
  4. include $(CLEAR_VARS)  
  5.   
  6. LOCAL_MODULE_TAGS := optional  
  7.   
  8. LOCAL_SRC_FILES := $(call all-java-files-under, src)  
  9.   
  10. LOCAL_PACKAGE_NAME := CoshipUpgrade  
  11.   
  12. LOCAL_CERTIFICATE := platform  
  13.   
  14. include $(BUILD_PACKAGE)  
  15.   
  16. # This finds and builds the test apk as well, so a single make does both.  
  17. include $(call all-makefiles-under,$(LOCAL_PATH))  

2. Write APK to generate and reference the third-party jar package
  1. LOCAL_PATH:= $(call my-dir)  
  2. include $(CLEAR_VARS)  
  3.   
  4. LOCAL_MODULE_TAGS := optional   
  5. LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)/apk  
  6.   
  7. LOCAL_SRC_FILES := $(call all-subdir-java-files)  
  8.   
  9. LOCAL_STATIC_JAVA_LIBRARIES := cling-core-1.0.5     \  
  10.                                cling-support-1.0.5  \  
  11.                                teleal-common-1.0.13 \  
  12.                                universal-image-loader \  
  13.                                core-zxing  
  14.                                  
  15.   
  16. LOCAL_PACKAGE_NAME := coshareservice  
  17. LOCAL_CERTIFICATE := platform  
  18. #LOCAL_JNI_SHARED_LIBRARIES := libmouse_cmd  
  19.   
  20. include $(BUILD_PACKAGE)  
  21.   
  22. MY_PATH := $(LOCAL_PATH)  
  23. LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := cling-core-1.0.5:libs/cling-core-1.0.5.jar \  
  24.                                         cling-support-1.0.5:libs/cling-support-1.0.5.jar \  
  25.                                         teleal-common-1.0.13:libs/teleal-common-1.0.13.jar \  
  26.                                         universal-image-loader:libs/universal-image-loader-1.9.2-SNAPSHOT-with-sources.jar \  
  27.                                         core-zxing:libs/core.jar  
  28.   
  29. include $(BUILD_MULTI_PREBUILT)  
  30. #include $(call all-makefiles-under,$(LOCAL_PATH))  


3. Precompiled translation only provides APK without source code, and does not contain. so files
    
  1. LOCAL_PATH := $(call my-dir)  
  2.   
  3.   
  4. ###############################################  
  5. include $(CLEAR_VARS)  
  6. LOCAL_MODULE_TAGS := optional  
  7. LOCAL_MODULE := FlyUI_Wallpaper_mtk  
  8. LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)/apk  
  9. LOCAL_SRC_FILES := $(LOCAL_MODULE).apk  
  10. LOCAL_MODULE_CLASS := APPS  
  11. LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)  
  12. LOCAL_CERTIFICATE := platform  
  13. include $(BUILD_PREBUILT)  

4. Precompiled translation only provides APK without source code, and does not contain. so files
    
  1. LOCAL_PATH:= $(call my-dir)  
  2.   
  3. ###############################################  
  4. include $(CLEAR_VARS)  
  5. LOCAL_MODULE_TAGS := optional  
  6. LOCAL_MODULE := YOUKU  
  7. LOCAL_MODULE_PATH := $(TARGET_OUT_APPS)  
  8. LOCAL_SRC_FILES := $(LOCAL_MODULE).apk  
  9. LOCAL_MODULE_CLASS := APPS  
  10. LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)  
  11. LOCAL_CERTIFICATE := platform  
  12. include $(BUILD_PREBUILT)  
  13.   
  14. include $(CLEAR_VARS)  
  15. LOCAL_PREBUILT_LIBS := libhello-jni.so  
  16. LOCAL_MODULE := libhello-jni      
  17. LOCAL_MODULE_TAGS := optional  
  18. include $(BUILD_MULTI_PREBUILT)  
  19.   
  20.   
  21. include $(CLEAR_VARS)  
  22. LOCAL_PREBUILT_LIBS := libalgmsyoukutv.so  
  23. LOCAL_MODULE := libalgmsyoukutv  
  24. LOCAL_MODULE_TAGS := optional  
  25. include $(BUILD_MULTI_PREBUILT)  
  26.   
  27.   
  28. include $(CLEAR_VARS)  
  29. LOCAL_PREBUILT_LIBS := libluajavayoukutv.so  
  30. LOCAL_MODULE := libluajavayoukutv  
  31. LOCAL_MODULE_TAGS := optional  
  32. include $(BUILD_MULTI_PREBUILT)  

4. Compile and generate executable files
    
  1. LOCAL_PATH:= $(call my-dir)  
  2.   
  3. include $(CLEAR_VARS)  
  4.   
  5. LOCAL_MODULE_TAGS := optional  
  6.   
  7. LOCAL_C_INCLUDES += \  
  8.      $(LOCAL_PATH)  
  9.        
  10. LOCAL_SRC_FILES:= \  
  11.         gpio-server.c  
  12.   
  13. LOCAL_SHARED_LIBRARIES := \  
  14.     libcurl \  
  15.     libcutils  
  16.   
  17. LOCAL_MODULE:= gpio-server  
  18.   
  19. include $(BUILD_EXECUTABLE)  
  20.   
  21. include $(call all-makefiles-under,$(LOCAL_PATH))  

5. Compile and generate the shared library. Here, libandroid_servers.so is generated. Because there are too many files involved, the screenshot will not be taken here
    
  1. LOCAL_PATH:= $(call my-dir)  
  2. include $(CLEAR_VARS)  
  3.   
  4. LOCAL_SRC_FILES:= \  
  5.     com_android_server_AlarmManagerService.cpp \  
  6.     com_android_server_BatteryService.cpp \  
  7.     com_android_server_InputApplicationHandle.cpp \  
  8.     com_android_server_InputManager.cpp \  
  9.     com_android_server_InputWindowHandle.cpp \  
  10.     com_android_server_LightsService.cpp \  
  11.     com_android_server_PowerManagerService.cpp \  
  12.     com_android_server_SystemServer.cpp \  
  13.     com_android_server_UsbDeviceManager.cpp \  
  14.     com_android_server_UsbHostManager.cpp \  
  15.     com_android_server_VibratorService.cpp \  
  16.     com_android_server_location_GpsLocationProvider.cpp \  
  17.     com_android_server_connectivity_Vpn.cpp \  
  18.     com_android_server_ConnectivityService.cpp \  
  19.     onload.cpp  
  20.   
  21. LOCAL_C_INCLUDES += \  
  22.     $(JNI_H_INCLUDE) \  
  23.     frameworks/base/services \  
  24.     frameworks/base/core/jni \  
  25.     external/skia/include/core  
  26.   
  27. LOCAL_SHARED_LIBRARIES := \  
  28.     libandroid_runtime \  
  29.     libcutils \  
  30.     libhardware \  
  31.     libhardware_legacy \  
  32.     libnativehelper \  
  33.     libsystem_server \  
  34.     libutils \  
  35.     libui \  
  36.     libinput \  
  37.     libskia \  
  38.     libgui \  
  39.     libusbhost  
  40.   
  41. ifeq ($(WITH_MALLOC_LEAK_CHECK),true)  
  42.     LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK  
  43. endif  
  44.   
  45. LOCAL_MODULE:= libandroid_servers  
  46.   
  47. include $(BUILD_SHARED_LIBRARY)  

6. Compile and generate jar static library
    
  1. LOCAL_PATH := $(call my-dir)   
  2. include $(CLEAR_VARS)   
  3.    
  4. #Get Java files in all subdirectories  
  5. LOCAL_SRC_FILES := $(call all-subdir-java-files)   
  6.    
  7. #The name of the dynamic Java library on which the current module depends  
  8. LOCAL_JAVA_LIBRARIES := android.test.runner   
  9.    
  10. #Name of the current module  
  11. LOCAL_MODULE := sample   
  12.    
  13. #Compile the current module into a static Java library  
  14. include $(BUILD_STATIC_JAVA_LIBRARY)  
Read the whole passage

Keywords: Android Java snapshot

Added by arbelo on Sat, 04 Apr 2020 01:30:04 +0300