Android源码分析(十一)-----Android源码中如何引用aar文件

2018年8月3日 3点热度 0条评论 来源: 一莫言一
一:aar文件如何引用

系统Settings中引用bidehelper-1.1.12.aar 文件为例
源码地址:packages/apps/Settings/Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
        $(call all-logtags-files-under, src)

LOCAL_MODULE := settings-logtags

include $(BUILD_STATIC_JAVA_LIBRARY)

# Build the Settings APK
include $(CLEAR_VARS)

LOCAL_PACKAGE_NAME := Settings
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_USE_AAPT2 := true

LOCAL_SRC_FILES := $(call all-java-files-under, src)

LOCAL_STATIC_ANDROID_LIBRARIES := \
    android-support-v4 \
    android-support-v13 \
    android-support-v7-appcompat \
    android-support-v7-cardview \
    android-support-v7-preference \
    android-support-v7-recyclerview \
    android-support-v14-preference

LOCAL_JAVA_LIBRARIES := \
    bouncycastle \
    core-oj \
    telephony-common \
    ims-common \
    telephony-ext

LOCAL_STATIC_JAVA_LIBRARIES := \
    jsr305 \
    settings-logtags

+	LOCAL_STATIC_JAVA_AAR_LIBRARIES := bide_helper

+	LOCAL_AAPT_FLAGS := \
+      --auto-add-overlay \
+      --extra-packages com.blackberry.bidehelper

LOCAL_PROGUARD_FLAG_FILES := proguard.flags

ifneq ($(INCREMENTAL_BUILDS),)
    LOCAL_PROGUARD_ENABLED := disabled
    LOCAL_JACK_ENABLED := incremental
    LOCAL_JACK_FLAGS := --multi-dex native
endif

include frameworks/opt/setupwizard/library/common-gingerbread.mk
include frameworks/base/packages/SettingsLib/common.mk

include $(BUILD_PACKAGE)

+	include $(CLEAR_VARS)

+	LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
+          bide_helper:libs/bidehelper-1.1.12.aar

+	include $(BUILD_MULTI_PREBUILT)

# Use the following include to make our test apk.
ifeq (,$(ONE_SHOT_MAKEFILE))
include $(call all-makefiles-under,$(LOCAL_PATH))
endif

主要代码如下:

#名称可以随便写
LOCAL_STATIC_JAVA_AAR_LIBRARIES := bide_helper

#写入aar文件中的包名
LOCAL_AAPT_FLAGS := \
  --auto-add-overlay \
  --extra-packages com.blackberry.bidehelper

aar文件中的包名可以用压缩工具直接打开,查看AndroidManifest.xml文件

  <?xml version="1.0" encoding="utf-8" ?> 
- <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.blackberry.bidehelper" android:versionCode="1" android:versionName="1.0.0.219">
  <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="26" /> 
  <application android:allowBackup="false" android:label="@string/app_name" android:supportsRtl="true" /> 
  </manifest>
include $(CLEAR_VARS)

#构建静态java库
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
    bide_helper:libs/bidehelper-1.1.12.aar

include $(BUILD_MULTI_PREBUILT)

编译后文件生成路径:out\target\product\msm8909\obj\JAVA_LIBRARIES

喜欢源码分析系列可参考其他文章:
Android源码分析(一)-----如何快速掌握Android编译文件
Android源码分析(二)-----如何编译修改后的framework资源文件
Android源码分析(三)-----系统框架设计思想
Android源码分析(四)-----Android源码编译及刷机步骤
Android源码分析(五)-----如何从架构师的角度去设计Framework框架

    原文作者:一莫言一
    原文地址: https://blog.csdn.net/LJX646566715/article/details/81393421
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。