欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android基础知识学习

程序员文章站 2022-03-15 11:41:06
一. ./build/envsetup.sh分析加载编译命令;加载平台信息;...

一.Android编译过程

  • 初始化参数设置
  • 检查环境变量与目标环境
  • 选择lunch并读取目标配置和平台信息
  • 清空输出目录
  • 编译
  • 生成升级包

二. ./build/envsetup.sh分析

  • 加载编译命令:source ./build/envsetup.sh
  • 加载平台信息:lunch平台信息;export查看环境变量

三.Android.mk

  • native层(可执行文件、动态库、静态库);Java层(Jar包、Apk);组成android编译基本语法规则
Android.mk简例

LOCAL_PATH := $(call my-dir)  #LOCAL_PATH定义在build/core/definitons.mk,定义当前模块相对路径
include $(CLEAR_VARS)  #CLEAR_VAR定义在build/core/cler_vars.mk,表示清空除loal_path外的环境变量
LOCAL_MODULE := test   #编译生成名称
LOCAL_SRC_FILES := test.c  #源文件
LOCAL_MODULE_PATH := $(LOCAL_PATH)  #指定输出路径
include $(BUILD_EXECUTABLE)  #生成格式,这里是编程生成二进制文件
  • Android.mk深度学习1:多源码文件编译、一个.mk中编译多个目标文件、编译动态库、编译静态库
Android.mk 简例:增加源文件__将每个文件添加到.mk中

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := test   
LOCAL_SRC_FILES := src/main.c \    #增加多源文件,将每个文件添加到.mk中
                   src/test1.c \
                   src/test2.c
  
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_EXECUTABLE)

Android.mk 简例:增加源文件__使用系统提供的函数处理

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := test   
LOCAL_C_ALL_FILES := $(call all-c-files-under)  #取所有.c文件
LOCAL_SRC_FILES := $(LOCAL_C_ALL_FILES)
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_EXECUTABLE)

Android.mk 简例:一个mk文件编译多个目标文件

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := test   #目标文件test
LOCAL_C_ALL_FILES := $(call all-c-files-under)  #取所有.c文件
LOCAL_SRC_FILES := $(LOCAL_C_ALL_FILES)
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)  
LOCAL_MODULE := test1   #目标文件test1
LOCAL_C_ALL_FILES := $(call all-c-files-under)  #取所有.c文件
LOCAL_SRC_FILES := $(LOCAL_C_ALL_FILES)
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_EXECUTABLE)

Android.mk 简例:编译生成动态库

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := libtest  
LOCAL_C_ALL_FILES := src/test1.c \
                     src/test2.c
LOCAL_SRC_FILES := $(LOCAL_C_ALL_FILES)
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_SHARED_LIBRARY)    #编译生成动态库

Android.mk 简例:编译生成静态库

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := libtest  
LOCAL_C_ALL_FILES := src/test1.c \
                     src/test2.c
LOCAL_SRC_FILES := $(LOCAL_C_ALL_FILES)
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_STATIC_LIBRARY)    #编译生成静态库
  • Android.mk深度学习2:如何引入系统库、如何引入第三方库、如何引入静态库、如何进入头文件
Android.mk 简例:项目中引入系统库

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := test  
LOCAL_SRC_FILES := src/main.cpp
LOCAL_SHARED_LIBRARIES += liblog   #链入系统log库
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_EXECUTABLE)    

Android.mk 简例:加载第三方库

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := libtest  
LOCAL_SRC_FILES := src/test.cpp
LOCAL_MODULE_PATH := $(LOCAL_PATH)/lib 
include $(BUILD_SHARED_LIBRARY)  

include $(CLEAR_VARS)  
LOCAL_MODULE := test 
LOCAL_LDFLAGS :=-L./lib -ltest  #加载当前目录下的第三方库
LOCAL_SRC_FILES := src/main.cpp   #调用了test.cpp接口 
LOCAL_SHARED_LIBRARIES += liblog   
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_EXECUTABLE)  

Android.mk 简例:引入第三方头文件

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := libtest  
LOCAL_SRC_FILES := src/test.cpp
LOCAL_MODULE_PATH := $(LOCAL_PATH)/lib 
include $(BUILD_SHARED_LIBRARY)  

include $(CLEAR_VARS)  
LOCAL_MODULE := test 
LOCAL_C_INCLUDES :=$(LOCAL_PATH)/inc
LOCAL_LDFLAGS :=-L./lib -ltest  #加载当前目录下的第三方库
LOCAL_SRC_FILES := src/main.cpp   #调用了test.cpp接口 
LOCAL_SHARED_LIBRARIES += liblog   
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_EXECUTABLE) 

Android.mk 简例:引入静态库

LOCAL_PATH := $(call my-dir) 
include $(CLEAR_VARS)  
LOCAL_MODULE := libtest  
LOCAL_SRC_FILES := src/test.cpp
LOCAL_MODULE_PATH := $(LOCAL_PATH)/lib 
include $(BUILD_SHARED_LIBRARY)  

include $(CLEAR_VARS)  
LOCAL_MODULE := test 
LOCAL_C_INCLUDES :=$(LOCAL_PATH)/inc
LOCAL_LDFLAGS := $(LOCAL_PATH)/lib/libtest1.a
LOCAL_SRC_FILES := src/main.cpp   #调用了test.cpp接口 
LOCAL_SHARED_LIBRARIES += liblog   
LOCAL_MODULE_PATH := $(LOCAL_PATH)/bin 
include $(BUILD_EXECUTABLE) 
  • Android.mk深度学习3:如何编译jar包、如何编译Apk、Apk中导入jar包和库文件、mk中如何加判断语句
Android.mk编译生成Apk

LOCAL_PATH := $(call my-dir)  
include $(CLEAR_VARS) 
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_JAVA_LIBRARIES := libarity android-support-v4 guava
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := Calculator   #编译生成apk名字
include $(BUILD_PACKAGE)   #编译生成apk

Android.mk编译生成jar

LOCAL_PATH := $(call my-dir)  
include $(CLEAR_VARS) 
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_MODULE := com.test.myjar
include $(BUILD_STATIC_JAVA_LIBRARY)   #编译生成静态jar包
若是-》include $(BUILD_JAVA_LIBRARY)   #编译生成共享jar包

判断
ifeq/ifneq:根据判断条件执行相关编译

四.Android启动过程

 

学习视频路径:https://www.bilibili.com/video/BV1mb411872F?from=search&seid=13706101650228050770

本文地址:https://blog.csdn.net/qq_39481566/article/details/110294004

相关标签: 充电桩