2

I am making application to broadcast phone video to youtube channel. I found this link https://github.com/youtube/yt-watchme.

While compiling my code I get error

libavutil not found in file avecode.h at code #include "libavutil/samplefmt.h

I also changed to #include "../libavutil/samplefmt.h" still same error.

Perhaps suggest any good rtmp library to broadcast phone video to youtube channel.

Error:FAILURE: Build failed with an exception. * What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
Build command failed.
Error while executing process

/Users/nomankhan/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Clients/Ankur/JniDemo/app/.externalNativeBuild/cmake/debug/mips64 --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
FAILED: /Users/nomankhan/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=mips64el-none-linux-android --gcc-toolchain=/Users/nomankhan/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/nomankhan/Library/Android/sdk/ndk-bundle/sysroot -Dnative_lib_EXPORTS -I../../../../src/main/cpp/include/libavcodec -I../../../../src/main/cpp/include/libavformat -I../../../../src/main/cpp/include/libavutil -isystem /Users/nomankhan/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /Users/nomankhan/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/mips64/include -isystem /Users/nomankhan/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -isystem /Users/nomankhan/Library/Android/sdk/ndk-bundle/sysroot/usr/include/mips64el-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fintegrated-as -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -MF CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o.d -o CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -c /Clients/Ankur/JniDemo/app/src/main/cpp/native-lib.cpp

In file included from /Clients/Ankur/JniDemo/app/src/main/cpp/native-lib.cpp:4: /Clients/Ankur/JniDemo/app/src/main/cpp/libavcodec/avcodec.h:31:10: fatal error: 'libavutil/samplefmt.h' file not found #include "libavutil/samplefmt.h" ^~~~~~~~~~~~~~~~~~~~~~~

My CMakeLists.txt

 cmake_minimum_required(VERSION 3.4.1)

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp )

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )


target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

include_directories(src/main/cpp/include/libavcodec)

include_directories(src/main/cpp/include/libavformat)

include_directories(src/main/cpp/include/libavutil)
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Noman Ahmed Khan
  • 131
  • 1
  • 14
  • I believe you need `include_directories(src/main/cpp)` instead of the three last statements. In **native-lib.cpp** you should have `#include "libavcodec/avcodec.h"`. – Alex Cohn Sep 18 '17 at 08:31
  • @Noman I am also getting same errors what you got. I am building simple cpp file but I am not able to build it. you can see my code https://stackoverflow.com/questions/51100111/how-to-resolve-android-ndk-build-command-faild. – Nitish Patel Jul 02 '18 at 10:23
  • @AlexCohn I have also mention headers in my native-lib.cpp file but still why I am not able to build my code successfully. you can also look code https://stackoverflow.com/questions/51100111/how-to-resolve-android-ndk-build-command-faild – Nitish Patel Jul 02 '18 at 10:26

1 Answers1

2

The answer below is assuming that the folders within cpp contains C++ code/src files. If not, then you likely have a code and libraries structuring problem.

Simply calling include_directories will not get CMake to compile them, I believe it'll just help the IDE in certain "syntax highlighting" and coding related things but it is important.

Instead you'll need to include the code files within the add_library call. Since it is quite obvious that you have a lot of files, a traversal code as such will help:

cmake_minimum_required(VERSION 3.4.1)

include_directories(src/main/cpp/include/libavcodec)        

# Traverses through the directories recursively 
# and append matching files to variable my_lib_SRC
file(GLOB_RECURSE my_lib_SRC
    "src/main/cpp/*.h"
    "src/main/cpp/*.cpp"
)

add_library( # Sets the name of the library.
         native-lib

         # Sets the library as a shared library.
         SHARED

         # Provides a relative path to your source file(s).
         ${my_lib_SRC})

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

NOTE: Every time you add a new source/code file, you'll need to clean and build again the project for the binaries to be built properly. Further explanations could be found here: https://stackoverflow.com/a/17655165/2949966

ahasbini
  • 6,761
  • 2
  • 29
  • 45
  • It worked. Can you give some links about cmake in android or tutorial example. Thanks – Noman Ahmed Khan Sep 19 '17 at 07:35
  • To be honest, most of my knowledge are from posts/questions on different issues, there wasn't a really good tutorial that I have found beneficial, it depended on what I was looking for or getting to work but I am sure that there are some out there that I haven't seen. However I could provide you with an implementation that I have made for OpenCV that uses cmake to build the OpenCV modules and allow developers to write native C/C++ code and benefit from cross compiling: https://github.com/ahasbini/Android-OpenCV. Kindly consider choosing the answer as a solution to mark the question complete. – ahasbini Sep 19 '17 at 07:52
  • I am attaching project link https://github.com/nomi2013/JniCompileWithCmake From where i can get these folders and necessary files libavcodec ibavformat libavutil libavcodec Actually when i compile some file missing. Thanks – Noman Ahmed Khan Sep 20 '17 at 03:49