I'm build a custom framework for Android device. Here is the makefile:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-java-files-under, src) src/com/my_company/my_api/IMyService.aidl
LOCAL_AIDL_INCLUDES := src/com/my_company/my_api/IMyService.aidl
LOCAL_MODULE := com.my_company.mymanager
include $(BUILD_JAVA_LIBRARY)
"com.my_company.mymanager.jar" is getting generated. But it has no classes.dex, and it only has "META_INF" directory.
Note: This works well with Android 7.1.1. The issue started to happen after building this with latest Android 7.1.1 changes. Please suggest the reason for this strange behaviour.
Related
I found similar posts but often the answer are not really correct and anyways seems to be not working for me.
I have an Android application created with Android Studio which includes java-websocket library. Now, I want to build this application inside AOSP thus I created a folder for the jar library with its own Android.mk and another folder which contains the application (with Android Studio structure) which contains its own Android.mk (modified in order to find AndroidManifest, res, java, AIDL files)
At first I had some troubles due to some incorrect parameter in the Android.mk for the jar file. Now the jar file seems to be correctly recognized and the intermediates are exported to out/ folder.
The problem now is during the build of the application since the classes exposed by the jar seems to be not available ending up in:
error: cannot find symbol WebSocket
and similar errors for any reference to the jar content.
The JAR folder contains: Android.mk Java-WebSocket-1.3.0.jar
And this is the Android.mk content
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := JavaWebSocket
LOCAL_MODULE_TAGS := optional
$(warning Going to build $(LOCAL_MODULE))
LOCAL_SRC_FILES := Java-WebSocket-1.3.0.jar
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_MODULE_SUFFIX := $(COMMON_JAVA_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
The application folder contains: Android.mk aidl_files app gradle build.gradle ..
(basically the Android Studio project plus the Android.mk and a folder containing AIDL (which I'll move outside later)
And this is the Android.mk file content:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := MyApplication
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := JavaWebSocket
LOCAL_PROGUARD_ENABLED := disabled
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := platform
LOCAL_SRC_FILES := $(call all-java-files-under, app/src/main/java) \
aidl_files/my_aidl_file.aidl
LOCAL_AIDL_INCLUDES := $(LOCAL_PATH)/aidl_files
LOCAL_RESOURCE_DIR += $(LOCAL_PATH)/app/src/main/res
LOCAL_MANIFEST_FILE := app/src/main/AndroidManifest.xml
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_STATIC_ANDROID_LIBRARIES += \
androidx.appcompat_appcompat
include $(BUILD_PACKAGE)
I tried to merge all the informations I found in StackOverflow so far without success.
Is there any other LOCAL_something that I should set?
I am using Android NDK to compile a shared library. I am using the latest build of Android Studio (Android Studio 15- #AI-141.2422023 ). In my cpp code, I am using a thirdparty shared library. When writing the Android.mk file, I have first created a PREBUILT_SHARED_LIBRARY with the following code.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := essentia
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../../essentia-shared/lib/libessentia.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../essentia-shared/include/essentia
include $(PREBUILT_SHARED_LIBRARY)
The problem I am facing is that $(LOCAL_PATH) is behaving a bit weirdly. The path it is returning is
jni/jni/../../../essentia-shared/lib/libessentia.so
I have the following questions:
I am not sure, why there are two jni's appended at the front of the path. Also when I tried to print the value of LOCAL_PATH by using $(warning $(LOCAL_PATH)), it prints jni.
Shouldn't $(LOCAL_PATH) return the absolute path? This is even more confusing because at times I got the absolute path using $(LOCAL_PATH).
PS: I am using the terminal internal to Android Studio to run ndk-build
Edit 1: I run the ndk-build from src/main
$(call my-dir) from src/main for src/main/jni/Android.mk results in "jni". On the other hand, LOCAL_SRC_FILES are always treated relative to the LOCAL_PATH, which is "jni". That's how jni/jni appears for your .so.
On the other hand, all …_INCLUDES are treated relative to working directory, which in your case is src/main from where you launched ndk-build. Due to the delicate nature of current directory, it is a good practice to use absolute paths for all include paths.
So, this is the suggested rewrite of this part of your Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := app-lib
LOCAL_SRC_FILES := a.cpp b.cpp
LOCAL_SHARED_LIBRARIES := essentia
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH += /../../../essentia-shared
include $(CLEAR_VARS)
LOCAL_MODULE := essentia
LOCAL_SRC_FILES := lib/libessentia.so
LOCAL_EXPORT_C_INCLUDES := $(abspath $(LOCAL_PATH)/include/essentia)
include $(PREBUILT_SHARED_LIBRARY)
I have two android projects with native support, that's to say, they're both android project and c++ project. One is android library(app-lib), another(std-pos-app) is android app who depends app-lib.
The Android.mk file in app-lib like bellow:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := app-lib
LOCAL_SRC_FILES := ...
include $(BUILD_SHARED_LIBRARY)
When it's builded, it will produce libapp-lib.so in libs/armeabi fiolder.
std-pos-app want to call the native code in app-lib.so. So the Android.mk file in std-pos-app like bellow:
LOCAL_PATH := $(call my-dir)
#------------------
include $(CLEAR_VARS)
LOCAL_MODULE := app-lib1
LOCAL_SRC_FILES := path-to-libapp-lib/libapp-lib.so
include $(PREBUILT_SHARED_LIBRARY)
#------------------
include $(CLEAR_VARS)
LOCAL_MODULE := std-pos-app
LOCAL_SRC_FILES := ...
include $(BUILD_SHARED_LIBRARY)
Use PREBUILT_SHARED_LIBRARY to prebuild libapp-lib.so, when std-pos-app is builded, libapp-lib.so and libstd-pos-app.so will appear in libs/armeapi. But when I want to run the std-pos-app, the error occured:
Error generating final archive: Found duplicate file for APK: lib/armeabi/libapp-lib.so
I konw the reason why it happen, because the android project dependency. But how to solve it? Thx.
I've found an alike thread that describes the same question. And I've solved the problem with the solution in the thread. How to use a library project with both c and java apis on Android
I am trying to build an application and an interface jar using the android build system in Linux
My application has a dependency with my interface, hence I have to make interface jar ready before application make.
But we faced build/run time issues while using our newly built interface jar.
I have tried to make the application in two different sequence.
Case 1. Building the interface as local module and linking it with apk as LOCAL_JAVA_LIBRARIES.
Case 2. Building the interface as local module and linking it with apk as LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES.
Following are the Android.mk files for main and interface.
1.Main Andriod.mk file:
/source/Android.mk
=======================================
STACK_PATH:= $(call my-dir)
LOCAL_PATH := $(STACK_PATH)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/interface/Android.mk
include $(CLEAR_VARS)
LOCAL_PATH := $(STACK_PATH)
include $(LOCAL_PATH)/application/Android.mk
=======================================
2.Interface Android.mk :
/source/interface/Android.mk
=======================================
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files, src)
LOCAL_MODULE := MyInterface
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_JAVA_RESOURCE_DIRS := src
include $(BUILD_JAVA_LIBRARY)
$(call dist-for-goals, droidcore, $(full_classes_jar):MyInterface.jar)
=======================================
Following are the Android.mk files for application in CASE 1.
Application Android.mk:
/source/application/Android.mk
=======================================
TOP_LOCAL_PATH:= $(call my-dir)
LOCAL_PATH:= $(TOP_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := MyApplication
LOCAL_JAVA_LIBRARIES := MyInterface
include $(BUILD_PACKAGE)
include $(BUILD_MULTI_PREBUILT)
=======================================
Build completed successfully .But when trying to run this application, it shows this error.
I/dalvikvm( XXXX): Failed resolving Lcom/test/example/application; interface XXX 'Lcom/test/example/interface;'
W/dalvikvm( XXXX): Link of class 'Lcom/test/example/application;' failed
Following are the Android.mk files for application in CASE 2.
Application Android.mk
/source/application/Android.mk
=======================================
TOP_LOCAL_PATH:= $(call my-dir)
LOCAL_PATH:= $(TOP_LOCAL_PATH)
include $(CLEAR_VARS)
$(shell (cp $(LOCAL_PATH)/../out/target/common/obj/JAVA_LIBRARIES/Interface_intermediates/classes-jarjar.jar $(LOCAL_PATH)/applications/libs/MyInterface.jar ))
LOCAL_STATIC_JAVA_LIBRARIES += MyInterface
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := MyApplicationss
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES += MyInterface:libs/MyInterface.jar
include $(BUILD_PACKAGE)
include $(BUILD_MULTI_PREBUILT)
=======================================
This resulted in a build error as follows.
build/core/base_rules.mk:166: * source/applications: MODULE.TARGET.JAVA_LIBRARIES.MyInterface already defined by source/interface. Stop.
But when they are built seperately without using the build system, this problem is not there.Also the application runs without error.
When the interface was built to Myinterface.jar using the eclipse, and build the application-apk using this
interface jar(by linking statically) in Linux, the application ran smoothly.
Is there any issue in my Android.mk files? Please help
I think you should have LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES between include $(BUILD_PACKAGE) and include $(BUILD_MULTI_PREBUILT)
See another answer .
Follow the link for Android Build System Details
http://www.kandroid.org/online-pdk/guide/build_system.html
I am trying to add my app in Android_source/Development/apps/ folder. I confirmed that my code is compiled, as if i add syntax error compiler stopped there.
But the thing is that my app is not getting shown in apps menu. should i add my app package somewhere else too.
Android.Mk file content(i copied these contents from Bluetooth App in packages/apps/Bluetooth)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := \
$(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := Bluetooth_LE
LOCAL_CERTIFICATE := platform
#LOCAL_JNI_SHARED_LIBRARIES := libbluetooth_jni
LOCAL_JAVA_LIBRARIES := javax.obex
LOCAL_STATIC_JAVA_LIBRARIES := com.android.vcard
LOCAL_REQUIRED_MODULES := libbluetooth_jni bluetooth.default
LOCAL_PROGUARD_ENABLED := disabled
include $(BUILD_PACKAGE)
include $(call all-makefiles-under,$(LOCAL_PATH))
It seems that you've forgot to include your package into the build. Put the name of your module (Bluetooth_LE) into appropriate build file (for instance, into build/target/product/core.mk) into section PRODUCT_PACKAGES.