【问题标题】:Add System application(Through App source code/working AS project) in AOSP source code在 AOSP 源代码中添加系统应用程序(通过 App 源代码/工作 AS 项目)
【发布时间】:2021-01-22 06:15:09
【问题描述】:

我正在尝试通过应用程序源代码而不是 apk 在 AOSP 源代码中添加应用程序。我的应用程序是我在 Android Studio 中开发的简单的 hello world 应用程序。我写了它的Android.mk,放在packages/app/myapplication/Android.mk。在aosp_source_code/build/target/product/handheld_system.mk注册的应用包名 我在Android.mk 文件中犯了什么错误吗?还是我错过了任何步骤。

这是我Android.mk的代码

include $(CLEAR_VARS)

LOCAL_PACKAGE_NAME := Myapplication
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_CERTIFICATE := platform

LOCAL_PRIVATE_PLATFORM_APIS := true

LOCAL_SRC_FILES := $(call all-java-files-under, src/main/java)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/src/main/res
LOCAL_MANIFEST_FILE := src/main/AndroidManifest.xml

LOCAL_DEX_PREOPT := false
LOCAL_PROGUARD_ENABLED := disabled

LOCAL_USE_AAPT2 := true

LOCAL_STATIC_ANDROID_LIBRARIES := \
    android-arch-lifecycle-extensions \
    android-support-v7-recyclerview \
    android-support-v7-appcompat \
    android-support-constraint-layout
include $(BUILD_PACKAGE) 

错误

packages/apps/Myapplication/src/main/res/layout/content_main.xml:8: error: attribute defaultNavHost (aka com.myapplication:defaultNavHost) not found.
packages/apps/Myapplication/src/main/res/layout/content_main.xml:8: error: attribute navGraph (aka com.myapplication:navGraph) not found.
packages/apps/Myapplication/src/main/res/navigation/nav_graph.xml:2: error: attribute startDestination (aka com.myapplication:startDestination) not found.
packages/apps/Myapplication/src/main/res/navigation/nav_graph.xml:14: error: attribute destination (aka com.myapplication:destination) not found.
packages/apps/Myapplication/src/main/res/navigation/nav_graph.xml:24: error: attribute destination (aka com.myapplication:destination) not found.
error: failed linking file resources.
11:57:34 ninja failed with: exit status 1

#### failed to build some targets (4 seconds)

【问题讨论】:

  • 能否在应用的 build.gradle 中显示依赖关系?
  • @TuanPM, dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'androidx.navigation:navigation-fragment:2.3.0' implementation 'androidx.navigation:navigation-ui:2.3.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' }
  • 错误是不言自明的。构建系统在您的应用程序源代码以及您在Android.mk 中列出的依赖项中找不到app:defaultNavHost 和其他人。似乎这些属性是在 androidx.navigation 库中定义的,但您尚未将其添加到 Android.mk 文件中。
  • @frogatto 如何将它们添加到 AOSP 中?以前我使用 PRODUCT_COPY_FILES 向 AOSP 添加了一些库。我需要遵循类似的过程还是不同的东西

标签: android operating-system embedded android-source


【解决方案1】:

正如我在您的 build.gradle 文件中看到的,您可能需要在 Android.mk 中链接 androidx.appcompat:appcompatandroidx.constraintlayout:constraintlayoutandroidx.navigation:navigation-uiandroidx.navigation:navigation-fragment

例子

LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.appcompat_appcompat \
    androidx-constraintlayout_constraintlayout \
    androidx-navigation_navigation-ui \
    androidx-navigation_navigation-fragment \
    ...

androidx-navigation_navigation-uiandroidx-navigation_navigation-fragment 可能可用或不可用取决于您的 AOSP 构建系统。您应该自己检查以确保这些库可用(通常位于prebuilts 目录中)。如果这些库不可用,您需要手动下载它们,然后手动将它们添加到 AOSP 构建系统。

【讨论】:

  • @semw 我认为您应该尝试将您的包添加到文件 //build/target/product/core.mk 中的 PRODUCT_PACKAGES
  • 谢谢,它成功了,如果我的应用程序依赖项不包含在 aosp 中,我该如何手动将它们添加到 aosp 中?
猜你喜欢
  • 1970-01-01
  • 2020-06-14
  • 1970-01-01
  • 2013-01-31
  • 1970-01-01
  • 1970-01-01
  • 2010-11-24
  • 2016-01-05
  • 1970-01-01
相关资源
最近更新 更多