I've cloned packageInstaller source code from PackageInstaller Source code. The project needs NDK to build but has no Application.mk file. The android.mk file contains these codes:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_USE_AAPT2 := true
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := \
$(call all-java-files-under, src)
LOCAL_STATIC_ANDROID_LIBRARIES += \
android-support-v4 \
android-support-annotations \
android-support-v7-recyclerview \
android-support-v7-preference \
android-support-v7-appcompat \
android-support-v14-preference \
android-support-v17-preference-leanback \
android-support-v17-leanback \
SettingsLib
LOCAL_STATIC_JAVA_LIBRARIES := \
xz-java
LOCAL_PACKAGE_NAME := PackageInstaller
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
# Comment for now unitl all private API dependencies are removed
# LOCAL_SDK_VERSION := system_current
include $(BUILD_PACKAGE)
ifeq (PackageInstaller,$(LOCAL_PACKAGE_NAME))
# Use the following include to make our test apk.
ifeq (,$(ONE_SHOT_MAKEFILE))
include $(call all-makefiles-under,$(LOCAL_PATH))
endif
endif
I had some trouble to build this project, since it has no application.mk files. Now I have two major problem with this project:
How can I add dependencies which are mentioned in the android.mk file?
How can i build the entire project successfully?
Related
I have made a aar library and added path: framework/base/packages/MyLib/MyLib.aar in AOSP.
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyLib
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_PREBUILT_MODULE_FILE := $(LOCAL_PATH)/MyLib.aar
include $(BUILD_PREBUILT)
When I add this lib in other application like Settings and it's working fine. But I want to use in framework/base/service/ in some java file. I am getting unable to import class file of that library.
I have added it in other apps Andropid.mk like LOCAL_STATIC_ANDROID_LIBRARIES := MyLib
This is my method to convert prebuilt aar to static android lib. It worked fine for me. You can refer this method for your situation.
include $(BUILD_PACKAGE)
######################## TuanPM13 #####################################
# add config to convert prebuilt aar to static android lib
#######################################################################
define aar-to-android-lib
$(foreach t,$(1), \
$(eval include $(CLEAR_VARS)) \
$(eval tw := $(subst :, ,$(strip $(t)))) \
$(eval LOCAL_MODULE := $(word 1,$(tw))) \
$(eval LOCAL_MODULE_TAGS := optional) \
$(eval LOCAL_SRC_FILES := $(word 2,$(tw))) \
$(eval LOCAL_RESOURCE_DIR := $(call intermediates-dir-for,JAVA_LIBRARIES,$(LOCAL_MODULE),,COMMON)/aar/res) \
$(eval LOCAL_USE_AAPT2 := true) \
$(eval LOCAL_RENDERSCRIPT_TARGET_API := $(2)) \
$(eval LOCAL_MODULE_CLASS := JAVA_LIBRARIES) \
$(eval LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)) \
$(eval LOCAL_BUILT_MODULE_STEM := javalib.jar) \
$(eval LOCAL_UNINSTALLABLE_MODULE := true) \
$(eval include $(BUILD_PREBUILT)) \
)
endef
prebuilt_aar_libraries := exoplayer-core:libs/exoplayer-core-2.10.8.aar \
exoplayer-ui:libs/exoplayer-ui-2.10.8.aar \
exoplayer-extension-mediasession:libs/extension-mediasession-2.10.8.aar
$(call aar-to-android-lib, $(prebuilt_aar_libraries), 28) # API level 28
prebuilt_aar_libraries :=
Noted that in my case, all *.arr were placed in libs directory.
Then in Android.mk of other applications, I link to them like below
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
...
LOCAL_STATIC_ANDROID_LIBRARIES += \
exoplayer-extension-mediasession \
exoplayer-ui \
exoplayer-core
include $(BUILD_PACKAGE)
Trying to use WorkManager in my SystemApp. I haven't been able to integrate it.
Android.mk :
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := MySystemApp
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_JNI_SHARED_LIBRARIES := libloguploaderclient
LOCAL_SRC_FILES := $(call all-java-files-under, android/src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/android/res
LOCAL_STATIC_ANDROID_LIBRARIES := \
androidx.core_core \
androidx.annotation_annotation \
androidx.work_work # This line doesn't work
LOCAL_PROGUARD_FLAG_FILES := android/proguard.cfg
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_SDK_VERSION := current
ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28 && echo OK),OK)
# Build as a vendor module
LOCAL_PROPRIETARY_MODULE := true
endif
# Build as an Android app
include $(BUILD_PACKAGE)
The below part of the mk file doesn't work and giving bunch of compile error:
LOCAL_STATIC_ANDROID_LIBRARIES := \
androidx.core_core \
androidx.annotation_annotation \
androidx.work_work # This line doesn't work
So, how can I use WorkManager in AOSP?
I'm trying to build an Android app through makefile (the app works perfectly when build by Android Studio).
I'm having problems with an .aar module that is used. the make completes successfully, but the .apk size is ridiculously small (500kb instead of 80mb).
The .aar has multiple .so files in ./libs, as well as ./assets, but both seem not to be included.
Android.mk:
LOCAL_SHARED_LIBRARIES := libnativelib
LOCAL_STATIC_JAVA_LIBRARIES:= aarmodulename
...
...
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES:=aarmodulename:libs/aarmodulename.aar
include $(BUILD_MULTI_PREBUILT)
I've also tried forcing the .so files to be packaged, but I dpn't even know if this is the proper way to do so:
include $(CLEAR_VARS)
LOCAL_MODULE := libnativelib
LOCAL_SRC_FILES := libs/so/libnativelib.so
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_SUFFIX := .so
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
include $(BUILD_PREBUILT)
Why don't the *.so files and the aar's assets get packaged? How do I fix it?
Same problem has been meetted, after read the static_java_library.mk in AOSP, The answer is basically found.
To resolve this problem, you should define LOCAL_USE_AAPT2 := true in your project Android.mk file.
The following is a part of the code in static_java_library.mk:
# Hack to build static Java library with Android resource
# See bug 5714516
all_resources :=
need_compile_res :=
# A static Java library needs to explicily set LOCAL_RESOURCE_DIR.
ifdef LOCAL_RESOURCE_DIR
need_compile_res := true
LOCAL_RESOURCE_DIR := $(foreach d,$(LOCAL_RESOURCE_DIR),$(call clean-path,$(d)))
endif
ifdef LOCAL_USE_AAPT2
ifneq ($(LOCAL_STATIC_ANDROID_LIBRARIES),)
need_compile_res := true
endif
endif
ifeq ($(need_compile_res),true)
all_resources := $(strip \
$(foreach dir, $(LOCAL_RESOURCE_DIR), \
$(addprefix $(dir)/, \
$(patsubst res/%,%, \
$(call find-subdir-assets,$(dir)) \
) \
) \
))
Follow is a sample:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
ifeq ($(TARGET_BUILD_APPS),)
# Use AAPT2 only when TARGET_BUILD_APPS is empty because AAPT2 is not compatible with the current
# setup of prebuilt support libs used in unbundled builds. b/29836407
LOCAL_USE_AAPT2 := true
endif
# SRC files
LOCAL_SRC_FILES := \
$(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := \
res
# JAR
LOCAL_STATIC_JAVA_LIBRARIES := \
ifdef LOCAL_USE_AAPT2
LOCAL_SHARED_ANDROID_LIBRARIES := \
android-support-annotations \
android-support-compat \
android-support-core-ui \
android-support-v7-appcompat \
android-support-v7-recyclerview
else
LOCAL_AAPT_FLAGS := --auto-add-overlay \
--extra-packages android.support.compat \
--extra-packages android.support.v7.appcompat \
--extra-packages android.support.v7.recyclerview
LOCAL_RESOURCE_DIR += \
frameworks/support/compat/res \
frameworks/support/v7/appcompat/res \
frameworks/support/v7/recyclerview/res
LOCAL_JAVA_LIBRARIES := \
android-support-annotations \
android-support-compat \
android-support-core-ui \
android-support-v7-appcompat \
android-support-v7-recyclerview
# OR define
LOCAL_STATIC_ANDROID_LIBRARIES := \
endif
LOCAL_MANIFEST_FILE := main/AndroidManifest.xml
LOCAL_PACKAGE_NAME := PACKAGE_NAME
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
# Comment for now unitl all private API dependencies are removed
# LOCAL_SDK_VERSION := system_current
include $(BUILD_PACKAGE)
I need to compile a android project with make file, but it seems that cannot find aidl files.
here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_OVERRIDE_SRC_FILES := $(call all-java-files-under, devices/$(TARGET_DEVICE))
LOCAL_SRC_FILES := $(call all-java-files-under, SDK src) \
src/com/skyworth/skyappstore/aidl/AppStoreCallBackAIDL \
src/com/skyworth/skyappstore/aidl/AppStoreServiceAIDL \
LOCAL_SRC_FILES := $(foreach f,$(LOCAL_SRC_FILES), \
$(if $(findstring $(f),$(LOCAL_OVERRIDE_SRC_FILES)),,$(f)))
# This is the target being built.
LOCAL_PACKAGE_NAME := APPStore
LOCAL_CERTIFICATE := shared
LOCAL_STATIC_JAVA_LIBRARIES := android fastjson jackson ksoap2 layoutlib tdcode
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := android:android.jar \
fastjson:fastjson-1.1.32.jar \
jackson:jackson-all-1.9.8.jar \
ksoap2:ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar \
layoutlib:layoutlib.jar \
tdcode:tdcode.jar
include $(BUILD_MULTI_PREBUILT)
include $(call all-makefiles-under,$(LOCAL_PATH))
this returns that package com.skyworth.skyappstore.aidl does not exist, com.skyworth.skyappstore.aidlis the place where I place my aidl file.
So how to change the make file to compile this project right
Are AppStoreCallBackAIDL and AppStoreServiceAIDL aild files? Maybe you can change
LOCAL_SRC_FILES := $(call all-java-files-under, SDK src) \
src/com/skyworth/skyappstore/aidl/AppStoreCallBackAIDL \
src/com/skyworth/skyappstore/aidl/AppStoreServiceAIDL \
to this:
LOCAL_SRC_FILES := $(call all-java-files-under, SDK src) \
src/com/skyworth/skyappstore/aidl/AppStoreCallBackAIDL.aidl \
src/com/skyworth/skyappstore/aidl/AppStoreServiceAIDL.aidl \
Now i export one native library and my folder is like this :
JNI\ANN*.cpp.
android.mk file is like this:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../
LOCAL_MODULE := libann
LOCAL_LDLIBS := -llog
NDK_TOOLCHAIN_VERSION := clang
LOCAL_CPPFLAGS += -std=c++11
LOCAL_SRC_FILES := \
ANN.cpp \
bd_pr_search.cpp \
bd_tree.cpp \
kd_pr_search.cpp \
kd_split.cpp \
kd_util.cpp \
bd_fix_rad_search.cpp \
bd_search.cpp \
brute.cpp \
kd_fix_rad_search.cpp \
kd_search.cpp \
kd_tree.cpp \
kd_dump.cpp \
perf.cpp\
sample.cpp
include $(BUILD_SHARED_LIBRARY)
Now i want to add some other cpp files and export another native lib.
for example, i add two files: graph.h,dijkstra,cpp
how should i config the android.mk file?
project/
liba/
srca.cpp
libb/
srcb.cpp
# TOP_PATH refers to the project root dir (project)
TOP_PATH := $(call my-dir)/.
# Build library a
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/liba
LOCAL_MODULE := liba
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := srca.cpp
include $(BUILD_SHARED_LIBRARY)
# Build library b
include $(CLEAR_VARS)
LOCAL_PATH := $(TOP_PATH)/libb
LOCAL_MODULE := libb
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := srcb.cpp
include $(BUILD_SHARED_LIBRARY)