Skip to content

Instantly share code, notes, and snippets.

@Gopinathp
Created October 25, 2017 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gopinathp/4fc523ec922117f2f3928eef2fb2e4fa to your computer and use it in GitHub Desktop.
Save Gopinathp/4fc523ec922117f2f3928eef2fb2e4fa to your computer and use it in GitHub Desktop.
Transient dependencies are bundled into the APK but not linked in the jni wrapper
#
# Copyright (C) The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_SYSROOT "/Users/gopinath/Library/Android/sdk/ndk-bundle/platforms/android-16/arch-arm")
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed,-v")
# configure import libs
set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../sharedlibs)
add_library(lib_ffmpeg SHARED IMPORTED)
set_target_properties(lib_ffmpeg PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/ffmpeg/lib/armeabi/libavcodec.so)
# build application's shared lib
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
add_library(ffmpeg-jni SHARED
tutorial02.c)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(ffmpeg-jni Threads::Threads)
target_include_directories(ffmpeg-jni PRIVATE
${distribution_DIR}/ffmpeg/include
)
target_link_libraries(ffmpeg-jni
android
-ljnigraphics
lib_ffmpeg
log)
@alexcohn
Copy link

Two problems with your gist:

  • you should not override CMAKE_SHARED_LINKER_FLAGS for Android. If you badly need to, you can extend it:

    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--whatever-you-need")
    
  • If you want to see verbose linker output, use -v without -Wl,:

    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed -v"")
    

If you keep the CMAKE_SHARED_LINKER_FLAGS that Android toolchain prepares for you, you get -Wl,--no-undefined which will complain when it doesn't find 'av_register_all', and it will set the path to platforms/android-16/arch-arm for you, so you don't need to set CMAKE_SYSROOT.

@Gopinathp
Copy link
Author

Thanks Alex for taking time and identifying the newbie problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment