[英]Compile error for a simple library in Android using latest FFmpeg library with NDK
I'm trying to get FFmpeg working in Android , and after successfuly compiled it on Ubuntu 64bit , and created the Android.mk under source/ffmpeg-3.4.2/android/arm folder and also the Android.mk in my own Android project ! 我正在尝试让FFmpeg在Android中工作,并在Ubuntu 64bit上成功编译后,在source / ffmpeg-3.4.2 / android / arm文件夹下创建了Android.mk,并在我自己的Android项目中创建了Android.mk ! i'm unable to compile a simple program and create the .so file !
我无法编译一个简单的程序并创建.so文件! By the way i've searched over the net and in Stackoverflow for 2 days now without luck !
顺便说一句,我已经在网上搜索了2天,但是在Stackoverflow中却没有运气! here is the code Android.mk
这是代码Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyLibrary
LOCAL_SRC_FILES := MyNativeFunctions.c
LOCAL_LDLIBS := -lz -llog
LOCAL_STATIC_LIBRARIES := libavformat_static libavcodec_static libavutil_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,ffmpeg-3.2.4/android/arm)
The native functions 本机功能
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include <android/log.h>
#define LOG_TAG "mylib"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
jint Java_com_example_home_hellondk_MyNativeFunctions_TestNdk(JNIEnv * env, jobject this, jstring filename)
{
av_register_all();
return 0;
}
when i use NDK-BUILD here is the error i got : 当我使用NDK-BUILD时,这是我得到的错误:
/home/home/Android/Sdk/ndk-bundle/sources/ffmpeg-3.2.4/android/arm/lib/libavformat.a: error adding symbols: File in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [obj/local/arm64-v8a/libMyLibrary.so] Error 1
[EDIT] Build_android.sh [编辑] Build_android.sh
#!/bin/bash
NDK=/home/home/Android/Sdk/ndk-bundle
SYSROOT=$NDK/platforms/android-24/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
function build_one
{
./configure \
--prefix=$PREFIX \
--disable-shared \
--enable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
[EDIT] The problem has been solved by adding the missing library in LOCAL_STATIC_LIBRARIES := libavformat_static libavcodec_static libswscale_static libavutil_static libswresample_static and for all users of Android Studio do not forget to add this line to your gradle otherwise it won't work. [编辑]已通过在LOCAL_STATIC_LIBRARIES中添加缺少的库来解决此问题:= libavformat_static libavcodec_static libswscale_static libavutil_static libswresample_static ,对于Android Studio的所有用户,请不要忘记将此行添加到gradle中,否则将无法正常工作。
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/libs'
}
Best regards 最好的祝福
You're only building ffmpeg for arm32 but you're building your app for all ABIs. 您只为arm32构建ffmpeg,但为所有ABI构建应用。
Here in your ffmpeg build script you're targeting arm specifically: 在您的ffmpeg构建脚本中,您专门针对arm:
SYSROOT=$NDK/platforms/android-24/arch-arm/
And from the error output you can see it was building arm64: 从错误输出中,您可以看到它正在构建arm64:
make: *** [obj/local/arm64-v8a/libMyLibrary.so] Error 1
Either limit your ndk-build to building only arm32 ( APP_ABI := armeabi-v7a
in your Application.mk
) or build ffmpeg for the other architectures as well. 将ndk-build限制为仅构建arm32(在
Application.mk
为APP_ABI := armeabi-v7a
),或者也为其他体系结构构建ffmpeg。
By the way, you'll have an easier time building autoconf projects with the NDK if you use https://developer.android.com/ndk/guides/standalone_toolchain.html 顺便说一句,如果您使用https://developer.android.com/ndk/guides/standalone_toolchain.html,则使用NDK构建autoconf项目会更轻松。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.