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
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 trying to add external JAR files (e.g., gson or eventbus) to my AOSP build. I tried it in two different ways:
Adding them to prebuilts/misc/common/mylibs/ and creating a Android.mk file for the dir. Then, I merely include the symbolic name of the lib in my app's Android.mk file.
Adding them in a subdir libs in my custom app source code and add it via the app's Android.mk file directly.
However, both approaches are yielding me similar errors, the following for the second method:
ninja: error: 'packages/apps/Car/MyApp/packages/apps/Car/Myapp/libs/gson-2.6.2.jar', needed by 'out/target/common/obj/JAVA_LIBRARIES/gson_intermediate/classes.jack', missing and no known rule to make it.
I noticed the weird repeating path in the error message. Does anybody have an idea what I am doing wrong?
Here is my Android.mk file for the second way:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_PACKAGE_NAME := MyApp
LOCAL_CERTIFICATE := platform
LOCAL_MODULE_TAGS := optional
LOCAL_PRIVILEGED_MODULE := true
LOCAL_STATIC_JAVA_LIBRARIES += jsr305 gson
LOCAL_STATIC_ANDROID_LIBRARIES := android-support-v4
LOCAL_USE_AAPT2 := true
include packages/apps/Car/libs/car-stream-ui-lib/car-stream-ui-lib.mk
include packages/services/Car/car-support-lib/car-support.mk
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := gson:$(LOCAL_PATH)/libs/gson-2.6.2.jar
include $(BUILD_MULTI_PREBUILT)
Removing $(LOCAL_PATH) from the path fixed it.
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?
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 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