构建 APK 时如何在 Android.mk 中导入 .so 库

问题描述 投票:0回答:2

我有这个问题:我必须使用 Android.mk 文件构建我的应用程序,我必须在最终的 apk 中插入库“libcom_google_ase_Exec.so”,但我做不到。我得到的是一个不包含该库的 APK,因此该应用程序无法运行。

我目前使用的Android.mk的代码是:

#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

我项目中的文件夹结构如下: 在根目录中我有: --> /app 和 Android.mk 在应用程序文件夹中,我有: --> app/src/main/jniLibs/armeabi/libcom_google_ase_Exec.so

如何更改 Android.mk 文件以在最终 APK 中导入 .so 库?

android makefile ndk-build .so android.mk
2个回答
0
投票
#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

我是这样解决的,我构建了一个64位版本。 如果您需要 32 位版本,您可以取消注释所有 LOCAL_MULTILIB = 32.


0
投票
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := AndroidMediaShell
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := APPS
LOCAL_SRC_FILES := app/$(LOCAL_MODULE).apk
LOCAL_PREBUILT_JNI_LIBS := lib/example.so
LOCAL_MODULE_TARGET_ARCH := arm or arm64 or x86
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_OVERRIDES_PACKAGES :=
include $(BUILD_PREBUILT)

LOCAL_MULTILIB

© www.soinside.com 2019 - 2024. All rights reserved.