无法在 ndk 中导入 libpng、libjpeg android

Cannot import libpng, libjpeg in ndk android

我分叉,Ucrop library for cropping,并做了一些修改。现在我必须构建 ndk 来进行更改。但是我一直收到这个错误:

 Android NDK: jni/Android.mk: Cannot find module with tag 'libpng' in import path    
 Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?    
 Android NDK: The following directories were searched:    
 Android NDK: jni/Android.mk:15: *** Android NDK: Aborting.    .  Stop.

该项目使用 Cimg 库。

这是我的 Android.mk 文件:

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

LOCAL_MODULE    := ucrop
LOCAL_SRC_FILES := uCrop.cpp

LOCAL_LDLIBS    := -landroid -llog -lz
LOCAL_STATIC_LIBRARIES := libpng libjpeg_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,libpng)
$(call import-module,libjpeg)

我尝试了网上给出的所有解决方案。但没有任何效果。我尝试了“Adding libpng in android ndk project”和许多答案。

终于成功了。这很难,因为我是 NDK 的初学者。但我会 post 我是怎么做到的,因为它可能会帮助其他初学者。

我先下载libpng and libjpeg,保存在Android/Sdk/ndk-bundle/sources下。我分别将它们保存在名称 libpng 和 libjpeg 下。

然后修改Android.mk如下,

LOCAL_PATH := $(call my-dir)

LOCAL_P := /usr/lib/

include $(CLEAR_VARS)

LOCAL_MODULE    := ucrop
LOCAL_SRC_FILES := uCrop.cpp

LOCAL_LDLIBS    := -landroid -llog -lz
LOCAL_STATIC_LIBRARIES := libpng libjpeg9

include $(BUILD_SHARED_LIBRARY)

$(call import-module,libpng/jni)
$(call import-module,libjpeg/libjpeg9)

然后设置环境路径NDK_MODULE_PATH如下,

export NDK_BUILD_PATH=/home/jerin/Android/Sdk/ndk-bundle/sources

这很重要,因为在 ndk 构建期间,它会在此路径中查找库。

You can compile ndk-build during gradle build by following [this][1]. Right-click on the module you would like to link to your native library, such as the app module, and select Link C++ Project with Gradle from the menu. Then select ndk-build, and give path to Android.mk