记录----编译libyuv、迁移至Android studio的操作和遇到的问题

操作说明:

ubuntu18.04

ndk---r14b(后面改为r10e)

1.下载libyuv: 

git clone http://git.chromium.org/external/libyuv.git    

2.编辑下载的libyuv里有一个Android.mk

       后面问题中会贴上全部Android.mk内容。这里不重复

3.将libyuv文件夹名改为jni

4.在jni的父目录执行ndk-build命令,在jni同目录下生成obj,libs两个新的文件夹

5.拷贝libs/armeabi下的libyuv.so文件到Android studio的libs中,且拷贝jni/include下的libyuv和libyuv.h到Android studio 的libs/include的新建文件夹libyuv中(也有可能在src/main/java中https://mp.csdn.net/postedit/97930398)

记录----编译libyuv、迁移至Android studio的操作和遇到的问题_第1张图片

6.在CMakeList等中,增加库

记录----编译libyuv、迁移至Android studio的操作和遇到的问题_第2张图片

记录----编译libyuv、迁移至Android studio的操作和遇到的问题_第3张图片

记录----编译libyuv、迁移至Android studio的操作和遇到的问题_第4张图片

 

问题集锦:

问题一: 

jni/source/mjpeg_decoder.cc:35:21: fatal error: jpeglib.h: No such file or directory
 #include 
                     ^
compilation terminated.
make: *** [obj/local/armeabi/objs/yuv_static/source/mjpeg_decoder.o] Error 1

 按下面模板-----注释下面几处代码:

# This is the Android makefile for libyuv for NDK.
LOCAL_PATH:= $(call my-dir)
 
include $(CLEAR_VARS)
 
LOCAL_CPP_EXTENSION := .cc
 
LOCAL_SRC_FILES := \
    source/compare.cc           \
    source/compare_common.cc    \
    source/compare_gcc.cc       \
    source/compare_mmi.cc       \
    source/compare_msa.cc       \
    source/compare_neon.cc      \
    source/compare_neon64.cc    \
    source/convert.cc           \
    source/convert_argb.cc      \
    source/convert_from.cc      \
    source/convert_from_argb.cc \
    source/convert_to_argb.cc   \
    source/convert_to_i420.cc   \
    source/cpu_id.cc            \
    source/planar_functions.cc  \
    source/rotate.cc            \
    source/rotate_any.cc        \
    source/rotate_argb.cc       \
    source/rotate_common.cc     \
    source/rotate_gcc.cc        \
    source/rotate_mmi.cc        \
    source/rotate_msa.cc        \
    source/rotate_neon.cc       \
    source/rotate_neon64.cc     \
    source/row_any.cc           \
    source/row_common.cc        \
    source/row_gcc.cc           \
    source/row_mmi.cc           \
    source/row_msa.cc           \
    source/row_neon.cc          \
    source/row_neon64.cc        \
    source/scale.cc             \
    source/scale_any.cc         \
    source/scale_argb.cc        \
    source/scale_common.cc      \
    source/scale_gcc.cc         \
    source/scale_mmi.cc         \
    source/scale_msa.cc         \
    source/scale_neon.cc        \
    source/scale_neon64.cc      \
    source/video_common.cc
 
common_CFLAGS := -Wall -fexceptions
 
# 这里注释
# ifneq ($(LIBYUV_DISABLE_JPEG), "yes")
# LOCAL_SRC_FILES += \
#     source/convert_jpeg.cc      \
#     source/mjpeg_decoder.cc     \
#     source/mjpeg_validate.cc
# common_CFLAGS += -DHAVE_JPEG
# LOCAL_SHARED_LIBRARIES := libjpeg
# endif
 
LOCAL_CFLAGS += $(common_CFLAGS)
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
 
LOCAL_MODULE := libyuv_static
LOCAL_MODULE_TAGS := optional
 
include $(BUILD_STATIC_LIBRARY)
 
include $(CLEAR_VARS)
 
LOCAL_WHOLE_STATIC_LIBRARIES := libyuv_static
LOCAL_MODULE := libyuv
 
# 这里注释
# ifneq ($(LIBYUV_DISABLE_JPEG), "yes")
# LOCAL_SHARED_LIBRARIES := libjpeg
# endif
 
include $(BUILD_SHARED_LIBRARY)
 
include $(CLEAR_VARS)
LOCAL_STATIC_LIBRARIES := libyuv_static
LOCAL_SHARED_LIBRARIES := libjpeg
LOCAL_MODULE_TAGS := tests
LOCAL_CPP_EXTENSION := .cc
LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
LOCAL_SRC_FILES := \
    unit_test/unit_test.cc        \
    unit_test/basictypes_test.cc  \
    unit_test/color_test.cc       \
    unit_test/compare_test.cc     \
    unit_test/convert_test.cc     \
    unit_test/cpu_test.cc         \
    unit_test/cpu_thread_test.cc  \
    unit_test/math_test.cc        \
    unit_test/planar_test.cc      \
    unit_test/rotate_argb_test.cc \
    unit_test/rotate_test.cc      \
    unit_test/scale_argb_test.cc  \
    unit_test/scale_test.cc       \
    unit_test/video_common_test.cc
 
LOCAL_MODULE := libyuv_unittest
include $(BUILD_NATIVE_TEST)

 

 

问题二:

Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/Users/cfanr/Library/Android/sdk/ndk-bundle/build/core/build-local.mk:151: *** Android NDK: Aborting    .  Stop.

需要在Android.mk同目录下创建application.mk 然后编辑它:

APP_ABI := armeabi-v7a 
APP_PLATFORM := android-14 

 

问题三:

/Users/cfanr/Library/Android/sdk/ndk-bundle/build/core/build-binary.mk:687: Android NDK: Module jpeg depends on undefined modules: cutils
/Users/cfanr/Library/Android/sdk/ndk-bundle/build/core/build-binary.mk:700: *** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.

版本ndk r14b 去编译导致,其原因版本太高了。于是我换成了ndk r10e

问题四:

Error:error: '../../../../libs/libavdevice-57.so', needed by '../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so', missing and no known rule to make it

CMakeList.txt 库地址没配对。

问题五:

Error:(138) undefined reference to 'ANativeWindow_unlockAndPost'
Error:(123) undefined reference to 'ANativeWindow_lock'
Error:(122) undefined reference to 'ANativeWindow_setBuffersGeometry'
Error:(102) undefined reference to 'ANativeWindow_fromSurface'

这是Android共享库没添加,在CMakeList.txt中加入android,${android}

记录----编译libyuv、迁移至Android studio的操作和遇到的问题_第5张图片

记录----编译libyuv、迁移至Android studio的操作和遇到的问题_第6张图片

问题六:

java.lang.UnsatisfiedLinkError: No implementation found

有一个可能是,如果调用的是C++的代码或是用的.cpp,必须加extern "C"

记录----编译libyuv、迁移至Android studio的操作和遇到的问题_第7张图片

你可能感兴趣的:(Android)