android runtime linking issue with interface - android

I am trying to build an application and an interface jar using he 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.
We 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 our Android.mk files? Please review and give your suggestions

Related

AOSP include Maven JAR file in android.mk

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?

Package build with Android.mk misses many classes from local JAVA static libraries

I'm writing an android service that depends on 2 static java libraries: protobuf and jzmq.
Here is my Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under,src)
LOCAL_PACKAGE_NAME := appmonitor
LOCAL_STATIC_JAVA_LIBRARIES := libprotobuf libJZMQ
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libprotobuf:libs/protobuf.jar libJZMQ:libs/zmq.jar
include $(BUILD_MULTI_PREBUILT)
The shared library files (.so) are available system wide.
Unfortunately the resulting package misses many classes from the zmq.jar which in turn leads to crashes within the service.
In other hand, package built with SDK in IntelliJ has all classes from the zmq.jar.
It looks like I'm missing some important options in my Android.mk, but which?

how to process android ndk project dependency

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

What is the simplest working example of the Android NDK's module importation?

I am unable to locate a working example of the Android NDK's module importation feature. The following Android.mk files seem correct, and the inner module builds and executes without error. However, building the outer module fails with the following error messages:
Android NDK: jni/inner/Android.mk:inner: LOCAL_MODULE_FILENAME should not include file extensions
Android NDK: jni/inner/Android.mk:inner: LOCAL_MODULE_FILENAME must not contain a file extension
/home/caleb/dev/android-ndk-r8e/build/core/build-shared-library.mk:30: * Android NDK: Aborting . Stop.
The inner, contained Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := inner
LOCAL_MODULE_FILENAME := libinner
LOCAL_SRC_FILES := inner-module.c
include $(BUILD_SHARED_LIBRARY)
The outer, containing Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := outer
$(call import-module,inner)
LOCAL_SHARED_LIBRARIES += inner
include $(BUILD_SHARED_LIBRARY)
Try placing the call to import-module at the end of your outer file. It is not a must to place it before referencing 'inner', and the NDK documentation actually advice you to place it at the end.
There's a few problems with what you are doing so here is how things should look.
The inner, contained Android.mk file:
# save away the previous local path
INNER_SAVED_LOCAL_PATH := $(LOCAL_PATH)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := inner
LOCAL_MODULE_FILENAME := libinner
LOCAL_SRC_FILES := inner-module.c
include $(BUILD_SHARED_LIBRARY)
# at this point LOCAL_MODULE_FILENAME will have been auto
# set to libinner.so or similar by the call to BUILD_SHARED_LIBRARY
# restore previous local path
LOCAL_PATH := $(INNER_SAVED_LOCAL_PATH)
The outer, containing Android.mk file:
LOCAL_PATH := $(call my-dir)
$(call import-module,inner)
# at this point
# a) we've still got the correct LOCAL_PATH as we didn't trash it in
# the included Android.mk file
# b) LOCAL_MODULE_FILENAME is still set to libinner.so which if not
# unset will cause BUILD_SHARED_LIBRARY to complain
include $(CLEAR_VARS)
# we've now got a clean slate
LOCAL_MODULE := outer
# the build system has 'remembered' the inner module
LOCAL_SHARED_LIBRARIES += inner
include $(BUILD_SHARED_LIBRARY)
I'm not sure if this is the way to do it but it works for me :)

Android runtime linking issue

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

Categories

Resources