使用Android.mk构建.Jar文件

时间:2018-07-23 22:56:51

标签: android makefile android-ndk android.mk

试图从我的文件夹“ java”中的java文件生成.jar存档,该文件夹与Android.mk构建文件位于同一目录中。我知道Android.mk文件正在运行,但没有生成.jar

这是我到目前为止所拥有的:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := Test
Test:libs/Test.jar
include $(BUILD_MULTI_PREBUILT)
include $(CLEAR_VARS)

LOCAL_MODULE_OWNER := owner
LOCAL_SRC_FILES := $(call all-java-files-under,java)
LOCAL_PACKAGE_NAME := TEST-JAR
LOCAL_STATIC_JAVA_LIBRARIES := Test
include $(BUILD_PACKAGE)

我也尝试过:

include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-java-files-under,java)
LOCAL_MODULE := TEST-JAR
LOCAL_STATIC_JAVA_LIBRARIES := libTest
include $(BUILD_STATIC_JAVA_LIBRARY)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := libTest:libs/Test.jar
include $(BUILD_MULTI_PREBUILT)

2 个答案:

答案 0 :(得分:0)

您无法从 Android.mk 生成JAR文件。

应该从Gradle构建脚本中调用Android NDK构建,然后根据配置选项负责生成jar,aar,apk。

使用ndk-build来查看较旧的Android NDK示例。

https://github.com/googlesamples/android-ndk/tree/master/other-builds/ndkbuild

答案 1 :(得分:0)

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := Test:libs/Test.jar
include $(BUILD_HOST_PREBUILT)

include $(CLEAR_VARS)
LOCAL_MODULE := Test-JAR
LOCAL_SRC_FILES := $(call all-java-files-under, java)
LOCAL_STATIC_JAVA_LIBRARIES += Test 
include $(BUILD_HOST_JAVA_LIBRARY)

这将构建一个宿主Java库Test-JAR.jar