android12.0(S) Launcher3 导入 AndroidStudio 调试编译
验证环境
aosp 12.0 源码,分支 android-12.0.0_r3 可以参考之前写的 android12.0(S) Pixel 3XL (QCOM 845) 编译刷机
AndroidStudio 版本 Android Studio Arctic Fox | 2020.3.1 Patch 4
gradle 版本 gradle-7.0.2-bin.zip gradle:7.0.4
二手 Pixel 3 XL一台可直接烧写上面编译的 rom(没有真机也可用模拟器)
源码链接
完整的 Launcher3 可直接运行调试源码已经上传 GitHub
分析流程
aosp 中 Launcher3 源码路径为 packages/apps/Launcher3
整体源码结构如下
乍一看还是有些复杂的,万变不离其宗,我们找准切入点即可。源码中的app编译规则都在根目录 Android.bp 或者 Android.mk中,
可以看到 Launcher3 中两个都有,打开 bp 文件查看并未找到编译 apk 的规则,那必定是在 mk 中。
mk 中信息量有点大,定义了编译3个 apk
LOCAL_PACKAGE_NAME := Launcher3Go
LOCAL_PACKAGE_NAME := Launcher3QuickStep
LOCAL_PACKAGE_NAME := Launcher3QuickStepGo
我们首先需要确认当前设备中使用哪一个 apk,可以通过指令 adb shell pm path com.android.launcher3
通过指令确认目前设备中运行 Launcher3 对应apk为 Launcher3QuickStep.apk
再回到 mk 中对应编译规则为
packages\apps\Launcher3\Android.mk
## Build rule for Quickstep app.#include $(CLEAR_VARS)LOCAL_USE_AAPT2 := trueLOCAL_MODULE_TAGS := optional# 依赖静态android类库 Launcher3QuickStepLib 可以理解为AS中 moduleLOCAL_STATIC_ANDROID_LIBRARIES := Launcher3QuickStepLibLOCAL_PROGUARD_ENABLED := disabledifneq (,$(wildcard frameworks/base)) LOCAL_PRIVATE_PLATFORM_APIS := trueelse LOCAL_SDK_VERSION := system_current LOCAL_MIN_SDK_VERSION := 26endif# 指定编译产物 apk 名称LOCAL_PACKAGE_NAME := Launcher3QuickStep# 编译产物路径是否在 priv-app 下LOCAL_PRIVILEGED_MODULE := # 编译产物路径是否在 system_ext 下LOCAL_SYSTEM_EXT_MODULE := true# 覆盖编译,编译 Launcher3QuickStep 就会忽略 Home Launcher2 Launcher3,不生成对应 apkLOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3# 依赖 frameworks/base/data/etc/com.android.launcher3.xml LOCAL_REQUIRED_MODULES := privapp_whitelist_com.android.launcher3# 资源文件源码LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/quickstep/res#网上没找到准确的解释,根据编译得到 apk 中的 xml 查看后猜测最终是将这里定义的两个 xml 和下面 quickstep/AndroidManifest.xml 合并LOCAL_FULL_LIBS_MANIFEST_FILES := \ $(LOCAL_PATH)/quickstep/AndroidManifest-launcher.xml \ $(LOCAL_PATH)/AndroidManifest-common.xmlLOCAL_MANIFEST_FILE := quickstep/AndroidManifest.xmlLOCAL_JACK_COVERAGE_INCLUDE_FILTER := com.android.launcher3.*LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0LOCAL_LICENSE_CONDITIONS := noticeLOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICEinclude $(BUILD_PACKAGE)
小结一下
Launcher3QuickStep.apk||需要android类库 Launcher3QuickStepLib
看完对应 mk 发现仅仅只依赖 Launcher3QuickStepLib 接下来看看这家伙是何方神圣,同样也定义在 Android.mk
packages\apps\Launcher3\Android.mk
## Build rule for Quickstep library.#include $(CLEAR_VARS)LOCAL_USE_AAPT2 := trueLOCAL_AAPT2_ONLY := trueLOCAL_MODULE_TAGS := optional# 依赖静态java库,最终打包到 apk 中 可以理解为AS中 libs 下 jarLOCAL_STATIC_JAVA_LIBRARIES := \ SystemUI-statsd \ SystemUISharedLibifneq (,$(wildcard frameworks/base)) LOCAL_PRIVATE_PLATFORM_APIS := trueelse LOCAL_SDK_VERSION := system_current LOCAL_MIN_SDK_VERSION := 26endifLOCAL_MODULE := Launcher3QuickStepLibLOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0LOCAL_LICENSE_CONDITIONS := noticeLOCAL_NOTICE_FILE := $(LOCAL_PATH)/NOTICELOCAL_PRIVILEGED_MODULE := true# 依赖静态android类库 Launcher3CommonDepsLibLOCAL_STATIC_ANDROID_LIBRARIES := Launcher3CommonDepsLib# java 源代码LOCAL_class="lazy" data-src_FILES := \ $(call all-java-files-under, class="lazy" data-src) \ $(call all-java-files-under, quickstep/class="lazy" data-src) \ $(call all-java-files-under, class="lazy" data-src_shortcuts_overrides)# 资源文件源码LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/quickstep/resLOCAL_PROGUARD_ENABLED := disabledLOCAL_MANIFEST_FILE := quickstep/AndroidManifest.xmlinclude $(BUILD_STATIC_JAVA_LIBRARY)
小结一下
Launcher3QuickStep.apk||android类库-Launcher3QuickStepLib||静态java库-SystemUI-statsd|静态java库-SystemUISharedLib|android类库-Launcher3CommonDepsLib
好嘛,开始套娃了。接下来我们又要看 Launcher3CommonDepsLib 这家伙藏在哪里,在 android.bp 中被发现
packages\apps\Launcher3\Android.bp
//// Build rule for Launcher3 dependencies lib.//android_library { name: "Launcher3CommonDepsLib",//对应Java源码 class="lazy" data-srcs: ["class="lazy" data-src_build_config*.java"],//又依赖 Launcher3ResLib static_libs: ["Launcher3ResLib"], sdk_version: "current", min_sdk_version: min_launcher3_sdk_version,//对应 xml 源码 manifest: "AndroidManifest-common.xml", lint: { baseline_filename: "lint-baseline-common-deps-lib.xml", },}// Library with all the dependencies for building Launcher3android_library { name: "Launcher3ResLib",//没有java源码 class="lazy" data-srcs: [ ],//对应资源文件源码 resource_dirs: ["res"],//依赖静态java库 static_libs: [ "LauncherPluginLib", "launcher_quickstep_log_protos_lite", "androidx-constraintlayout_constraintlayout", "androidx.recyclerview_recyclerview", "androidx.dynamicanimation_dynamicanimation", "androidx.fragment_fragment", "androidx.preference_preference", "androidx.slice_slice-view", "androidx.cardview_cardview", "iconloader_base", ], manifest: "AndroidManifest-common.xml", sdk_version: "current", min_sdk_version: min_launcher3_sdk_version, lint: { baseline_filename: "lint-baseline-res-lib.xml", },}java_library { name: "LauncherPluginLib",//依赖静态java库 static_libs: ["PluginCoreLib"], class="lazy" data-srcs: ["class="lazy" data-src_plugins*.java"], sdk_version: "current", min_sdk_version: min_launcher3_sdk_version,}java_library_static { name: "launcher_quickstep_log_protos_lite", class="lazy" data-srcs: [ "quickstep/protos_overrides}
AS_WorkSpace\Launcher3\Launcher3ResLib\build.gradle
dependencies {// api files('libs\\iconloader_base.jar') api project(path: ':Launcher3IconLoadeBase') api files('libs\\launcher_log_protos_lite.jar')// api files('libs\\launcher_quickstep_log_protos_lite.jar') api files('libs\\LauncherPluginLib.jar') api files('libs\\libprotobuf-java-lite.jar') api files('libs\\PluginCoreLib.jar') api 'androidx.constraintlayout:constraintlayout:2.1.0' api 'androidx.recyclerview:recyclerview:1.2.1' api 'androidx.dynamicanimation:dynamicanimation:1.1.0-alpha03' api 'androidx.fragment:fragment:1.4.1' api 'androidx.preference:preference:1.2.0-alpha01'// api 'androidx.slice:slice-view:1.1.0-alpha02' api 'androidx.slice:slice-core:1.1.0-alpha02' api 'androidx.slice:slice-builders:1.1.0-alpha02' api 'androidx.cardview:cardview:1.0.0-rc02' }
AS_WorkSpace\Launcher3\Launcher3IconLoadeBase\build.gradle
dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.3.0' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'}
来源地址:https://blog.csdn.net/u012932409/article/details/128772883
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341