Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in libavutil.so when using latest NDK version 23.1.7779620 to build ffmpeg #242

Closed
juha-h opened this issue Nov 13, 2021 · 12 comments
Closed

Comments

@juha-h
Copy link

juha-h commented Nov 13, 2021

Description
Crash in libavutil.so when using latest NDK version 23.1.7779620 to build ffmpeg

Expected behavior
Should not crash

Current behavior
When I build ffmpeg libraries for my baresip app using ffmpeg-kit master and NDK 23.0.7599858, the app starts and works fine. Without changing anything else except using latest NDK 23.1.7779620 to build ffmpeg libs, the app crashes at start with this log message:

11-13 11:18:09.442 23890 23890 E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__emutls_get_address" referenced by "/data/app/~~VV5up2PFDWp5FVE4Nd4CIA==/com.tutpro.baresip.plus-OoB1CvZdgkOqYxE_nLSsvQ==/base.apk!/lib/arm64-v8a/libavutil.so"...

To Reproduce
See above.

Screenshots
If applicable, add screenshots to help explain your problem.

Logs
Post logs here or paste them to Ghostbin and insert the link here.

Environment

  • Platform: Android
  • Architecture:arm64-v8a
  • Version
  • Source branch: master
  • Xcode version:
  • Cocoapods version:
  • Android Studio version: 2020.3.1
  • Android NDK version: 23.1.7779620

Other
I searched the web and found same kind of errors reported earlier, but not very recently, Could be a bug in NDK 23.1.7779620.

@juha-h
Copy link
Author

juha-h commented Nov 13, 2021

This could be it: android/ndk#1551.

@tanersener
Copy link
Collaborator

tanersener commented Jan 2, 2022

@juha-h Mate, I've seen your posts. But I don't know what the problem is.

When someone reports an issue, as maintainer, the first thing I do is reproduce the issue and see if there is a general error. I did that as much as I can for your issue but didn't see any problems (I tested r23b and added it to github actions in this commit, test android build scripts on ndk r23b).

Why I'm saying I did as much as I can? Because I don't know what you're doing in your app, how you're loading the binaries, which ones you're using. You have --skip-ffmpeg-kit and --no-archive in your command. Which shows you're not using .aar files created by build scripts and you're not using ffmpeg-kit either. But your post doesn't say anything about this. So, how a developer can help you if they don't have all the information they need to reproduce this issue.

@juha-h
Copy link
Author

juha-h commented Jan 2, 2022

No problems. You have done as much you could. I'm not using the kit, but only the libs as shown in the CMakeLists.txt below. Most like this is an issue in ndk, not in ffmpeg-kit.

cmake_minimum_required(VERSION 3.4.1)

set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../distribution.video)

add_library(lib_crypto STATIC IMPORTED)
set_target_properties(lib_crypto PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/openssl/lib/${ANDROID_ABI}/libcrypto.a)

add_library(lib_ssl STATIC IMPORTED)
set_target_properties(lib_ssl PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/openssl/lib/${ANDROID_ABI}/libssl.a)

add_library(lib_re STATIC IMPORTED)
set_target_properties(lib_re PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/re/lib/${ANDROID_ABI}/libre.a)

add_library(lib_rem STATIC IMPORTED)
set_target_properties(lib_rem PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/rem/lib/${ANDROID_ABI}/librem.a)

add_library(lib_opus STATIC IMPORTED)
set_target_properties(lib_opus PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/opus/lib/${ANDROID_ABI}/libopus.a)

add_library(lib_vpx STATIC IMPORTED)
set_target_properties(lib_vpx PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/vpx/lib/${ANDROID_ABI}/libvpx.a)

add_library(lib_x264 STATIC IMPORTED)
set_target_properties(lib_x264 PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/x264/lib/${ANDROID_ABI}/libx264.a)

add_library(lib_aom STATIC IMPORTED)
set_target_properties(lib_aom PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/aom/lib/${ANDROID_ABI}/libaom.a)

add_library(lib_png STATIC IMPORTED)
set_target_properties(lib_png PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/png/lib/${ANDROID_ABI}/libpng.a)

add_library(lib_cpu_features STATIC IMPORTED)
set_target_properties(lib_cpu_features PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/cpu_features/lib/${ANDROID_ABI}/libcpu_features.a)

add_library(lib_ndk_compat STATIC IMPORTED)
set_target_properties(lib_ndk_compat PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/cpu_features/lib/${ANDROID_ABI}/libndk_compat.a)

add_library(lib_x265 STATIC IMPORTED)
set_target_properties(lib_x265 PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/x265/lib/${ANDROID_ABI}/libx265.a)

add_library(lib_avcodec SHARED IMPORTED)
set_target_properties(lib_avcodec PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/ffmpeg/lib/${ANDROID_ABI}/libavcodec.so)

add_library(lib_avutil SHARED IMPORTED)
set_target_properties(lib_avutil PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/ffmpeg/lib/${ANDROID_ABI}/libavutil.so)

add_library(lib_swresample SHARED IMPORTED)
set_target_properties(lib_swresample PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/ffmpeg/lib/${ANDROID_ABI}/libswresample.so)

add_library(lib_avdevice SHARED IMPORTED)
set_target_properties(lib_avdevice PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/ffmpeg/lib/${ANDROID_ABI}/libavdevice.so)

add_library(lib_avfilter SHARED IMPORTED)
set_target_properties(lib_avfilter PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/ffmpeg/lib/${ANDROID_ABI}/libavfilter.so)

add_library(lib_postproc SHARED IMPORTED)
set_target_properties(lib_postproc PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/ffmpeg/lib/${ANDROID_ABI}/libpostproc.so)

add_library(lib_swscale SHARED IMPORTED)
set_target_properties(lib_swscale PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/ffmpeg/lib/${ANDROID_ABI}/libswscale.so)

add_library(lib_avformat SHARED IMPORTED)
set_target_properties(lib_avformat PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/ffmpeg/lib/${ANDROID_ABI}/libavformat.so)

add_library(lib_spandsp STATIC IMPORTED)
set_target_properties(lib_spandsp PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/spandsp/lib/${ANDROID_ABI}/libspandsp.a)

add_library(lib_g722_1 STATIC IMPORTED)
set_target_properties(lib_g722_1 PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/g7221/lib/${ANDROID_ABI}/libg722_1.a)

add_library(lib_g729 STATIC IMPORTED)
set_target_properties(lib_g729 PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/g729/lib/${ANDROID_ABI}/libbcg729.a)

add_library(lib_amrnb STATIC IMPORTED)
set_target_properties(lib_amrnb PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/amr/lib/${ANDROID_ABI}/libamrnb.a)

add_library(lib_amrwb STATIC IMPORTED)
set_target_properties(lib_amrwb PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/amr/lib/${ANDROID_ABI}/libamrwb.a)

add_library(lib_amrwbenc STATIC IMPORTED)
set_target_properties(lib_amrwbenc PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/amr/lib/${ANDROID_ABI}/libamrwbenc.a)

add_library(lib_webrtc STATIC IMPORTED)
set_target_properties(lib_webrtc PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/webrtc/lib/${ANDROID_ABI}/libwebrtc.a)

add_library(lib_bn STATIC IMPORTED)
set_target_properties(lib_bn PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/bn/lib/${ANDROID_ABI}/libbn.a)

add_library(lib_zrtp STATIC IMPORTED)
set_target_properties(lib_zrtp PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/zrtp/lib/${ANDROID_ABI}/libzrtp.a)

add_library(lib_baresip STATIC IMPORTED)
set_target_properties(lib_baresip PROPERTIES IMPORTED_LOCATION
        ${distribution_DIR}/baresip/lib/${ANDROID_ABI}/libbaresip.a)

add_library(baresip SHARED baresip.c vidisp.c)

#set(CMAKE_SHARED_LINKER_FLAGS
#        "${CMAKE_SHARED_LINKER_FLAGS} -u AImageReader_new")

target_include_directories(baresip PRIVATE
        ${distribution_DIR}/openssl/include
        ${distribution_DIR}/ffmpeg/include
        ${distribution_DIR}/re/include
        ${distribution_DIR}/rem/include
        ${distribution_DIR}/baresip/include)

target_link_libraries(baresip
        android
        EGL
        GLESv2
        GLESv1_CM
        OpenSLES
        lib_baresip
        lib_rem
        lib_re
        lib_ssl
        lib_crypto
        lib_opus
        lib_avdevice
        lib_avfilter
        lib_swscale
        lib_avformat
        lib_avcodec
        lib_x264
        lib_x265
        lib_aom
        lib_png
        lib_vpx
        lib_avutil
        lib_swresample
        lib_postproc
        lib_spandsp
        lib_g722_1
        lib_g729
        lib_amrnb
        lib_amrwb
        lib_amrwbenc
        lib_webrtc
        lib_zrtp
        lib_bn
        z
        log
        camera2ndk
        lib_cpu_features
        lib_ndk_compat
        mediandk)

@tanersener
Copy link
Collaborator

Some of the libraries you're enabling depends on libc++ (See Android Cpp Dependency) but I don't see a libc++_shared.so included there. Do you have it in your .apk, is it automatically added by cmake?

@juha-h
Copy link
Author

juha-h commented Jan 2, 2022

I have this in build.gradle of the app:

        externalNativeBuild {
            cmake {
                cFlags '-DHAVE_INTTYPES_H -lstdc++'
                arguments "-DANDROID_STL=c++_shared"
            }
        }

@tanersener
Copy link
Collaborator

So, you have libc++_shared.so inside your .apk, right?

How do you define ndk version for your build, is it defined inside CMakeLists.txt or build.gradle?

@juha-h
Copy link
Author

juha-h commented Jan 2, 2022

I build all libs separately using a Makefile and then include the libs to the Android Studio project using the above CMakeLists.txt.

ffmpeg entry of the Makefile looks like this:

.PHONY: ffmpeg
ffmpeg:
	rm -rf $(FFMPEG_LIB) && \
	cd ffmpeg-kit && \
	ANDROID_SDK_ROOT=/foo/bar \
	ANDROID_NDK_ROOT=$(NDK_PATH) \
	./android.sh --enable-gpl --no-archive \
		$(FFMPEG_DIS) --disable-arm-v7a-neon --disable-x86 \
		--disable-x86-64 \
		--enable-libvpx --enable-x264 --enable-x265 --enable-libaom \
		--enable-libpng --skip-ffmpeg-kit

@juha-h
Copy link
Author

juha-h commented Jan 2, 2022

Just wondering if static ffmeg libraries would help. Now ffmpeg/lib contains only dynamic ones:

ffmpeg/lib:
libavcodec.so*	 libavfilter.so*  libavutil.so*    libswresample.so* 
libavdevice.so*  libavformat.so*  libpostproc.so*  libswscale.so*

but the rest are static:

cpu-features/lib:
libcpu_features.a  libndk_compat.a

libaom/lib:
libaom.a

libpng/lib:
libpng16.a  libpng16.la*  libpng.a@  libpng.la@

libvpx/lib:
libvpx.a

x264/lib:
libx264.a

x265/lib:
libx265.a

@tanersener
Copy link
Collaborator

Well, I don't know what you're doing with some of those .a files. But ffmpeg produced by ffmpeg-kit doesn't need them. If you open one of the .aar files of ffmpeg-kit you won't see any static libraries inside. And normally they'll cause duplicate symbol problems for you. We also don't create libpostproc.so, I don't know where that is coming from.

Anyway, your -DANDROID_STL=c++_shared flag tells cmake to add a c++ runtime to your app. You need to check if there is a libc++_shared.so file added to your apk. And find from which NDK it is added from. If you're not specifying the NDK version in your CMakeLists.txt or build.gradle then it should be set in Android Studio.

@juha-h
Copy link
Author

juha-h commented Jan 2, 2022

Thanks for your help. The crash with 23.1.7779620 was gone after I added NDK version to app's build.gradle:

android {
    compileSdkVersion = 31
    ndkVersion '23.1.7779620'
    ...

I'll try next if ndkVersion is needed when I remove other NDK (Side by side) versions from Android Studio SDK Tools.

Edit: Was not able to remove other NDK versions. For some reason they were automatically added again after I removed them.

@juha-h
Copy link
Author

juha-h commented Jan 2, 2022

Regarding libpostproc.so, it is needed to build my app. So I have patched ffmpeg.sh by removing the corresponding --disable line:

***************
*** 391,397 ****
    ${DEBUG_OPTIONS} \
    --disable-neon-clobber-test \
    --disable-programs \
-   --disable-postproc \
    --disable-doc \
    --disable-htmlpages \
    --disable-manpages \

@tanersener
Copy link
Collaborator

Okay.

@juha-h juha-h closed this as completed Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants