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)
Related
I have this problem: I have to build my app using the Android.mk file and I have to insert the library "libcom_google_ase_Exec.so" inside the final apk, but I can't do it. What I get is an APK that doesn't contain the library and therefore the app doesn't work.
The code for the Android.mk I'm currently using is:
#ifneq ($(TARGET_BUILD_PDK), true)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := com_google_ase_Exec
LOCAL_SRC_FILES := app/src/main/jniLibs/armeabi/libcom_google_ase_Exec.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := Sshd
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_MODULE_TAGS := samples
LOCAL_USE_AAPT2 := true
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/app/src/main/res/
LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml
# LOCAL_ASSETS_DIR := $(LOCAL_PATH)/assets
LOCAL_STATIC_ANDROID_LIBRARIES += \
android-support-v13 \
android-support-v7-cardview \
android-support-v7-recyclerview \
android-support-annotations
LOCAL_STATIC_JAVA_LIBRARIES := \
libsshd-core \
libsshd-common \
libsshd-scp \
libsshd-sftp \
libslf4j \
libbcpkix \
libbcprov
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_DEX_PREOPT := false
LOCAL_SHARED_LIBRARIES := libcom_google_ase_Exec
#LOCAL_PREBUILTS := com_google_ase_Exec
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
libsshd-core:app/libs/sshd-core-2.8.0.jar \
libsshd-common:app/libs/sshd-common-2.8.0.jar \
libsshd-scp:app/libs/sshd-scp-2.8.0.jar \
libsshd-sftp:app/libs/sshd-sftp-2.8.0.jar \
libslf4j:app/libs/slf4j-api-1.7.35.jar \
libbcpkix:app/libs/bcpkix-jdk15on-1.70.jar \
libbcprov:app/libs/bcprov-jdk15on-1.70.jar
include $(BUILD_MULTI_PREBUILT)
#include $(call all-makefiles-under, $(LOCAL_PATH))
#endif
The folder structure within my project is as follows:
In the root i have:
--> /app and Android.mk
In the app folder i have:
--> app/src/main/jniLibs/armeabi/libcom_google_ase_Exec.so
How can i change the Android.mk file to import the .so library in the final APK?
#ifneq ($(TARGET_BUILD_PDK), true)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := Sshd
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_MODULE_TAGS := samples
LOCAL_USE_AAPT2 := true
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/app/src/main/res/
LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml
# LOCAL_ASSETS_DIR := $(LOCAL_PATH)/assets
LOCAL_STATIC_ANDROID_LIBRARIES += \
android-support-v13 \
android-support-v7-cardview \
android-support-v7-recyclerview \
android-support-annotations
LOCAL_STATIC_JAVA_LIBRARIES := \
libsshd-core \
libsshd-common \
libsshd-scp \
libsshd-sftp \
libslf4j \
libbcpkix \
libbcprov
LOCAL_JNI_SHARED_LIBRARIES := libcom_google_ase_Exec
#LOCAL_MULTILIB = 32
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PROGUARD_ENABLED := disabled
#LOCAL_UNINSTALLABLE_MODULE := true
#LOCAL_DEX_PREOPT := false
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_CERTIFICATE := platform
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
libsshd-core:app/libs/sshd-core-2.8.0.jar \
libsshd-common:app/libs/sshd-common-2.8.0.jar \
libsshd-scp:app/libs/sshd-scp-2.8.0.jar \
libsshd-sftp:app/libs/sshd-sftp-2.8.0.jar \
libslf4j:app/libs/slf4j-api-1.7.35.jar \
libbcpkix:app/libs/bcpkix-jdk15on-1.70.jar \
libbcprov:app/libs/bcprov-jdk15on-1.70.jar
include $(BUILD_MULTI_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE := libcom_google_ase_Exec
LOCAL_MODULE_TAGS := samples
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := app/src/main/jniLibs/armeabi/libcom_google_ase_Exec.so
#LOCAL_MULTILIB = 32
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_MODULE_SUFFIX = .so
include $(BUILD_PREBUILT)
#include $(call all-makefiles-under, $(LOCAL_PATH))
#endif
I solved in this way, i build a 64bit version.
If u need a 32bit version u can uncomment all LOCAL_MULTILIB = 32.
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'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?
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 \