This is how my Android.mk file looks like. What is the equivalent CMakeLists.txt? I am struggling to find libhardware in CMake. Any ideas?
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libtestLed
LOCAL_SRC_FILES := testled.cpp
LOCAL_C_INCLUDES := $(call include-path-for, libhardware)/hardware
LOCAL_SHARED_LIBRARIES += \
libandroid_runtime \
libcutils \
liblog \
libhardware \
LOCAL_MODULE_TAGS := optional
LOCAL_VENDOR_MODULE := true
include $(BUILD_SHARED_LIBRARY)
the line you mentioned would be
target_link_libraries(testLed hardware)
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.
While building the AOSP (Oreo)source tree, The following error occurs
build/core/dynamic_binary.mk:17: error: packages/apps/TerminalTest/jni:
LOCAL_MODULE not defined before call to local-intermediates-dir.
18:25:16 ckati failed with: exit status 1
#### failed to build some targets (26 seconds) ####
Application Source tree
jni
Android.mk
src
res
Android.mk
Main Android.mk
LOCAL_PATH:= $(call my-dir)
include $(call all-subdir-makefiles)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := TerminalTest
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := libjni_terminal
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4
LOCAL_JNI_SHARED_LIBRARIES := libjni_terminalTest
# TODO: enable proguard once development has settled down
#LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)
jni/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
jni_init.cpp \
com_android_terminal_Terminal.cpp \
LOCAL_C_INCLUDES += \
external/libvterm/include \
libcore/include \
frameworks/base/include
LOCAL_SHARED_LIBRARIES := \
libandroidfw \
libandroid_runtime \
liblog \
libnativehelper \
libutils
LOCAL_STATIC_LIBRARIES := \
libvterm
LOCAL_CFLAGS := \
-Wno-unused-parameter \
LOCAL_MODULE := libjni_terminal
LOCAL_MODULE_TAGS := optional
include $(BUILD_SHARED_LIBRARY)
Any help will appreciate
If you use LOCAL_MODULE := libjni_terminal in any other project this error will happen.
When using the same LOCAL_MODULE name in different places lead to problems while creating and accessing intermediate files.
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)
I have three static libraries from a framework that I want to use in my project. These libraries are called libtinySAK_armv7-a.a, libtinyNET_armv7-a.a and libtinyHTTP_armv7-a.a. I have placed them in the same folder as the Android.mkandApplication.mk.
My native code is dependent on them so I want to include them in my shared library.
From what I've read on stackoverflow and google'd I believe the android.mk is supposed to look something like this:
# TINYSAK
include $(CLEAR_VARS)
LOCAL_MODULE := tinySAK
LOCAL_SRC_FILES := libtinySAK_armv7-a.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../doubango/tinySAK/src/
include $(PREBUILT_STATIC_LIBRARY)
# TINYNET
include $(CLEAR_VARS)
LOCAL_MODULE := tinyNET
LOCAL_SRC_FILES := libtinyNET_armv7-a.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../doubango/tinyNET/src/
include $(PREBUILT_STATIC_LIBRARY)
# TINYHTTP
include $(CLEAR_VARS)
LOCAL_MODULE := tinyHTTP
LOCAL_SRC_FILES := libtinyHTTP_armv7-a.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../doubango/tinyHTTP/include/
include $(PREBUILT_STATIC_LIBRARY)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libtest
LOCAL_SRC_FILES := \
../../test/stack.cpp \
../../test/main.cpp
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../../test/include/ \
$(LOCAL_PATH)/../../../doubango/tinyHTTP/include/ \
$(LOCAL_PATH)/../../../doubango/tinySAK/src/ \
$(LOCAL_PATH)/../../../doubango/tinyNET/src/
LOCAL_STATIC_LIBRARIES := \
tinySAK \
tinyNET \
tinyHTTP
include $(BUILD_SHARED_LIBRARY)
My Application.mk:
APP_STL := stlport_static
APP_ABI := armeabi-v7a
The error I get upon compilation("ndk-build" from project dir) is
jni/Android.mk:tinySAK: LOCAL_SRC_FILES points to a missing file
And I suppose the other 2 libraries also fail. Why cannot it find them?
Besides that, is there any other errors I've made in the makefile?
Thanks
Nevermind, I solved it.
I declared the "LOCAL_PATH" in the beginning of the make-file only. Otherwise it would look for the libs in the ndk-folders.
Try LOCAL_LDLIBS instead of LOCAL_SRC_FILES.