I want my app to be built with Android Source code. How to include appcompat_v7 in Android.mk file and where to place the appcompat_v7 folder in source code. I am using the following code,
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := \appcompat_v7
# Include all java files.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := MyPackage
include $(BUILD_PACKAGE)
I am getting error
make: No rule to make target 'out/target/common/obj/JAVA_LIBRARIES/\appcompat_v7_intermediates/javalib.jar', needed by 'out/target/common/obj/APPS/MyPackage_intermediates/classes-full-debug.jar'. Stop.
Anyone Please help. Thanks in advance.
I was able to build a package that includes appcompat using the following Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := MySuperAwesomeApp
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout
include $(BUILD_PACKAGE)
Source: https://android.googlesource.com/platform/packages/apps/UnifiedEmail/+/android-5.0.1_r1/Android.mk
This code works for me, and I hope it can help! Copy the jar files in the libs of appcompat_v7 project to the libs directory of your project.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_STATIC_JAVA_LIBRARIES := \
android-support-v4 \
android-support-v7-appcompat
<more jar could be added here>
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := <The name of your App project>
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += <The absolute path to your appcompat_v7 project>/res
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v4:android.support.v7.appcompat <replace the _ with . for your all jar files>
include $(BUILD_PACKAGE)
I built my package in command line along with Android source code and had hard time to include the v7 appcompat. To me, copying android-support-v7-appcompat.jar to libs and changing Android.mk as others posted above did not solve my problem. I finally figured out that I need build that v7 appcompat first.
Go to PATH/TO/frameworks/support/v7/appcompat and build it first.
No need to copy appcompat.jar to libs. Make your Android.mk like two posts above and it should work.
Related
I'm trying to build my java based android app through building as a module inside AOSP source. My app uses android.support.constraint.ConstraintLayout. But, I didn't find a direct way to include constraint-layout dependency in my Android.mk.
I've put my project under AOSP_ROOT/packages/apps and tried with this Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PACKAGE_NAME := MyApp
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_MANIFEST_FILE := AndroidManifest.xml
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.constraint
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
android-support-v4 \
android-support-constraint-layout-solver
LOCAL_STATIC_JAVA_AAR_LIBRARIES := \
android-support-constraint-layout
include $(BUILD_PACKAGE)
But, this comes up with build error:
ninja: error: 'out/target/common/obj/JAVA_LIBRARIES/android-support-constraint-layout_intermediates/aar/classes.jar', needed by 'out/target/common/obj/APPS/MyApp_intermediates/AndroidManifest.xml', missing and no known rule to make it
20:57:54 ninja failed with: exit status 1
What I understand - it is searching for classes.jar which could be built from .aar file, but it is missing. However, the answer here solves the issue: How to include constraint layout library in an AOSP project
But, the problem is, that answer suggests to add external constraint-layout.aar and constraint-layout-solver.jar within my project libs directory.
My question, is it possible to add constraint-layout support in my project using built-in library inside AOSP without adding external .aar and .jar to my project?
Anyways, I've found the solution. There is no need to include the constraint-layout in the project libs as extra library.
To solve the issue, in Android.mk we need to add one extra line:
LOCAL_USE_AAPT2 := true
And also use LOCAL_STATIC_ANDROID_LIBRARIES instead of LOCAL_STATIC_JAVA_AAR_LIBRARIES.
This is the working Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_PACKAGE_NAME := MyApp
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_USE_AAPT2 := true
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_MANIFEST_FILE := AndroidManifest.xml
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.constraint
LOCAL_STATIC_ANDROID_LIBRARIES:= \
android-support-constraint-layout
LOCAL_STATIC_JAVA_LIBRARIES := \
android-common \
android-support-v4 \
android-support-constraint-layout-solver
include $(BUILD_PACKAGE)
I'm building a custom ROM and would like to include a simple launcher I built as a system app. Here is my Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# General
LOCAL_PACKAGE_NAME := Tott
LOCAL_SDK_VERSION := current
LOCAL_MODULE_TAGS := optional
LOCAL_PROGUARD_ENABLED := disabled
# To make system app
LOCAL_CERTIFICATE := platform
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_PRIVILEGED_MODULE := true
LOCAL_OVERRIDES_PACKAGES := Home Launcher2 Launcher3
# src/res files
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
# libraries
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v7-appcompat
#flags
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
--extra-packages android.support.v7.appcompat
include $(BUILD_PACKAGE)
I have placed the Android.mk, AndroidManifest.xml, res folder, and src (containing java) in a directory called Tott which has been placed in [source]/packages/apps. I've also added Tott to PRODUCT_PACKAGES at [source]/build/target/product/core.mk
When I build the android system.img, it says that that it is including [source]/packages/apps/Tott/Android.mk in terminal but my app never shows in [source]/out/target/product/vender/system/app or priv-app. I'm also able to build my app successfully by simply running make Tott at [source].
What am I doing wrong here????
Thanks
Comment out LOCAL_SDK_VERSION and LOCAL_UNINSTALLABLE_MODULE. I don't use those in my Android.mk files and I never have a problem.
I'm trying to learn how to compile an app in android source. The app is just a simple hello world application. I followed instructions from Making an app in the Android Source compile into system/app instead of data/app? and a couple of other sources. But when I make the application the apk file is written to obj/APPS with suffix intermediates instead of system/app and fails to show up in the emulator when I boot up. Please find below the Android.mk file.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_PATH := system/app
LOCAL_UNINSTALLABLE_MODULE := true
LOCAL_SDK_VERSION := current
LOCAL_PACKAGE_NAME := MyApplication
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-appcompat
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v7-gridlayout
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES += android-support-design
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/appcompat/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/v7/gridlayout/res
LOCAL_RESOURCE_DIR += prebuilts/sdk/current/support/design/res
LOCAL_CERTIFICATE := platform
LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages android.support.v7.appcompat:android.support.v7.gridlayout
include $(BUILD_PACKAGE)
##################################################
include $(CLEAR_VARS)
include $(BUILD_MULTI_PREBUILT)
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
I make the application by going to the application directory in packages/apps and doing 'mm'. Is there anything I'm missing here?
Find out the BoardConfig.mk and add this :
PRODUCT_PACKAGES += MyApplication
AOSP build system will build every Android.mk, but only packages defined in BoardConfig will be put into the final product path.
you have to add the app module into the PRODUCT_PACKAGE from the devices/"your preferred vendor"/"device_name"/aosp_"device Name".mk file
It should look something like the following
$(call inherit-product, device/lge/hammerhead/full_hammerhead.mk)
PRODUCT_NAME := aosp_hammerhead
PRODUCT_PACKAGES += \
Launcher3 \
MyApplication \
It has little bit changed. Aosp checks /device/"vendor"/"your_device"/"your_platform"/base.mk file for compiling and /device/"vendor"/"your_device"/common/base.mk for installing apk to /out/target/product/"your_device/system/app/"
You should add your app name to both files.
In my case; aosp/device/qcom/qssi/base.mk to compile,
aosp/device/qcom/common/base.mk to install output(apk) to /out/target/product/msm8953/system/app/
so I'm relatively new to Android-NDK and trying to add an uncompiled c-library to android.
I've downloaded the library's source from here and followed these instructions to create a static library (.a-File) from the downloaded files using ndk-build.
So now I have a folder-structure that looks like this:
-srtp
--include (srtp.h, crypto.h)
--srtp (srtp.c...)
--obj
---local
----armeabi
-----libsrtp_static.a
In my Android-project I want to include srtp.h in a c-file inside my /jni/ folder. I've tried to just add the .a-file to the /jni folder but than it says "srtp.h no such file or direcotry". If I add the entire srtp-folder to the project and include the header with "srtp/include/srtp.h" it compiles but fails to link the source as I get the error "Undefined reference to srtp-function-call"
Here's my Android.mk (parts of it copied from Android.mk within the downloaded source):
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ndk1 #name of my project
LOCAL_SRC_FILES := native.c #name of the c-source file
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH:= /home/dev/programing/srtp
common_SRC_FILES := \
srtp/srtp.c \
srtp/ekt.c \
crypto/cipher/cipher.c \
#...more files like that
common_CFLAGS := \
-DPOSIX -iquote$(LOCAL_PATH)/crypto/include \
-Werror \
-Wno-ignored-qualifiers \
-Wno-sign-compare \
-Wno-missing-field-initializers
common_C_INCLUDES = $(LOCAL_PATH)/include
# For the device
# =====================================================
# Device static library
include $(CLEAR_VARS)
ifneq ($(TARGET_ARCH),x86)
LOCAL_NDK_VERSION := 5
LOCAL_SDK_VERSION := 9
endif
LOCAL_SRC_FILES := libsrtp_static.a
LOCAL_CFLAGS += $(common_CFLAGS)
LOCAL_C_INCLUDES += /home/dev/programing/srtp/include
LOCAL_MODULE:= libsrtp_static
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
Any help is greatly appreciated! Thank you very much.
You need to add the reference to libsrtp_static from your lib (ndk1) declaration :
LOCAL_STATIC_LIBRARIES := libsrtp_static
Also, you don't need to copy all the strp sources to your project, only add this to your static prebuilt library definition
LOCAL_EXPORT_C_INCLUDES += /home/dev/programing/srtp/include
This path will then be automatically added to the LOCAL_C_INCLUDES of your library that is using the library.
Are you building libsrtp or just using a prebuilt static library ? If you're using a prebuilt (lib*.a), replace BUILD_STATIC_LIBRARY with PREBUILT_STATIC_LIBRARY and set only the .a as SRC_FILE:
In summary, once libstrp_static.a is built, this should work:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ndk1 #name of my project
LOCAL_SRC_FILES := native.c #name of the c-source file
LOCAL_STATIC_LIBRARIES := libsrtp_static
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := /home/dev/programing/srtp/libsrtp_static.a #check path to libsrtp_static.a
LOCAL_EXPORT_C_INCLUDES += /home/dev/programing/srtp/include
LOCAL_MODULE:= libsrtp_static
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
I need to change Settings app by adding some custom library to it but I am having problems with configuration. When I try to call System.loadLibrary("mylibrary") i get libraryPath=/data/app-lib/com.settings-1: find library returned null. I know that app will look inside /data/app-lib/.. folder for specific library but my library is in system/lib
I know that my .mk files are not OK but I don't know what am I missing, please take look at them.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_JAVA_LIBRARIES := bouncycastle telephony-common
LOCAL_STATIC_JAVA_LIBRARIES := guava android-support-v4 jsr305
ifdef DOLBY_DAP
LOCAL_JAVA_LIBRARIES += framework_ext
else
LOCAL_STATIC_JAVA_LIBRARIES += libsds
endif #DOLBY_DAP
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := Settings
LOCAL_CERTIFICATE := platform
# If this is an unbundled build (to install seprately) then include
# the libraries in the APK, otherwise just put them in /system/lib and
# leave them out of the APK
ifneq (,$(TARGET_BUILD_APPS))
LOCAL_JNI_SHARED_LIBRARIES := efuse_tool
else
LOCAL_REQUIRED_MODULES := efuse_tool
endif
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
include $(BUILD_PACKAGE)
include $(call all-makefiles-under, jni)
ifndef DOLBY_DAP
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libsds:ds.jar
include $(BUILD_MULTI_PREBUILT)
endif
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
And .mk file inside jni folder
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_SRC_FILES := efuse_tool.c
LOCAL_MODULE := efuse_tool
include $(BUILD_SHARED_LIBRARY)
I realized that I have to add prefix "lib" to my library so it will be called from system/lib location. So it should look like this
ifneq (,$(TARGET_BUILD_APPS))
LOCAL_JNI_SHARED_LIBRARIES := libefuse_tool
else
LOCAL_REQUIRED_MODULES := libefuse_tool
endif
LOCAL_MODULE := libefuse_tool
I can also remove LOCAL_JNI_SHARED_LIBRARIES := libefuse_tool because it will never be used.