zoukankan      html  css  js  c++  java
  • Android源码分析(十一)-----Android源码中如何引用aar文件

    一: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 argetproductmsm8909objJAVA_LIBRARIES


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

  • 相关阅读:
    HDU 4296 Buildings(贪心)
    HDU 4288 Coder(线段树)
    hdu 5073 Galaxy
    ZOJ 3905 Cake(贪心+dp)
    ZOJ 3903 Ant(公式推导)
    除法求逆元(扩展欧几里德和费马小定理)
    HDU 4442 Physical Examination(关于贪心排序)
    ACM vim配置
    2015 南阳ccpc The Battle of Chibi (uestc 1217)
    次小生成树(入门)
  • 原文地址:https://www.cnblogs.com/ljx646566715/p/10893929.html
Copyright © 2011-2022 走看看