在源码中编译的时候要用mk文件来配置java文件和资源文件才能编译。
就应用来说,通常在src和res文件夹同级的目录有一个mk文件来控制编译,我感觉 eclipse的目录层级和androidstudio相比较起来更“像”是源码里的应用的目录结构。
比如说闹钟系统app的位置 alps/packages/apps/DeskClock/
在这个文件夹下的结构如下图
可以看到这里有Android.mk文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_RESOURCE_DIR := packages/apps/DeskClock/res
LOCAL_RESOURCE_DIR += frameworks/opt/datetimepicker/res
ifeq ($(TARGET_BUILD_APPS),)
LOCAL_RESOURCE_DIR += frameworks/support/design/res
LOCAL_RESOURCE_DIR += frameworks/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += frameworks/support/v7/gridlayout/res
LOCAL_RESOURCE_DIR += frameworks/support/v7/recyclerview/res
else
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/design/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/recyclerview/res
endif
LOCAL_CERTIFICATE := platform
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_MODULE_TAGS := optional
#LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := DeskClock
LOCAL_OVERRIDES_PACKAGES := AlarmClock
LOCAL_SRC_FILES := $(call all-java-files-under, src gen)
LOCAL_STATIC_JAVA_LIBRARIES := android-opt-datetimepicker
LOCAL_STATIC_JAVA_LIBRARIES += messageformat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-design
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-recyclerview
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.design
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.gridlayout
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.recyclerview
LOCAL_AAPT_FLAGS += --extra-packages com.android.datetimepicker
LOCAL_AAPT_FLAGS += --extra-packages com.android.messageformat
LOCAL_PROGUARD_FLAG_FILES := ../../../frameworks/support/design/proguard-rules.pro
include $(BUILD_PACKAGE)
然后 从 include $(CLEAR_VARS) 到 include $(BUILD_PACKAGE) 这就是一个编译模块了。
include $(CLEAR_VARS) :清空参数
include $(BUILD_PACKAGE) :编译模块(类型)include $(BUILD_PACKAGE) ,就是说要编译个App出来,如果是include $(BUILD_STATIC_JAVA_LIBRARY)就是编译个jar包出来。还有其他的。。
剩下的这两行中间的就是这个模块的配置了。
这些配置都是有固定的意义,而且没有先后顺序。
LOCAL_RESOURCE_DIR:res文件夹(资源)用那些资源文件夹就往里+
TARGET_BUILD_APPS:是编App还是编系统什么的,网上查一下,因为mk好像有很多这种固定的变量
LOCAL_CERTIFICATE := platform :表示是平台的,也就是系统应用要系统签名
LOCAL_PACKAGE_NAME := DeskClock :生成的apk的名字还有它的文件夹的名字(位于alps/out/target/product/xxxx/system/app/)
LOCAL_OVERRIDES_PACKAGES := AlarmClock 覆盖的包名,例如一些厂商定制要覆盖掉原生的
LOCAL_SRC_FILES := $(call all-java-files-under, src gen):src,gen 这些文件夹下的java都要参与编译,也可以像res一样+
LOCAL_PROGUARD_ENABLED := disabled :代码要不要混淆
LOCAL_STATIC_JAVA_LIBRARIES:用到的系统中的jar包 也包括第三方的jar但是需要作为一个模块重新编一次
LOCAL_AAPT_FLAGS :R资源生成别名,查了一下为资源设置别名,这样别人也可以用定义的这些包名访问本app资源了
LOCAL_PROGUARD_FLAG_FILES:指定不需要混淆的native方法与变量的proguard.flags文件
还有很多别的配置,记得去搜索
其他的问题:
1)第三方的jar要放在mk里,就要编译模块,就像上边说的
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := pinyin4j:lib/pinyin4j-2.5.0.jar
include $(BUILD_MULTI_PREBUILT)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := pinyin4j:lib/pinyin4j-2.5.0.jar:表示重新编译这个jar ,“:”前面为编后的名字“pinyin4j”,后面为编之前的名字“lib/pinyin4j-2.5.0.jar”。
添加到依赖的jar包
LOCAL_STATIC_JAVA_LIBRARIES += pinyin4j
外层文件夹依次加入如下mk,又来调用main下面的mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include $(call all-makefiles-under,$(LOCAL_PATH))
aidl文件写法:
LOCAL_SRC_FILES += ./aidl/包名/XX.aidl