2017-09-16 161 views
1

在Android Studio上的JNI編譯錯誤2.3.2

我正在向YouTube頻道播放手機視頻。我發現這個鏈接https://github.com/youtube/yt-watchme

在編寫我的代碼,我得到錯誤

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

我也改變#包括「../libavutil/samplefmt.h」還是同樣的錯誤。

也許建議任何一個好的rtmp庫來向youtube頻道播放手機視頻。

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" ^~~~~~~~~~~~~~~~~~~~~~~

我的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) 
+0

我相信你需要'include_directories(src/main/cpp)'而不是最後三條語句。在** native-lib.cpp **中,你應該有'#include「libavcodec/avcodec.h」'。 –

回答

1

答案下面是假定內cpp的文件夾中包含C++代碼/ src目錄文件。如果沒有,那麼你可能有代碼和庫結構問題。

簡單地調用include_directories得到CMake編譯它們,我相信這隻會幫助IDE在某些「語法高亮」和編碼相關的東西,但它是非常重要的。

相反,您需要在add_library調用中包含代碼文件。由於這是很明顯的,你有很多的文件,遍歷代碼,這樣將有助於:

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}) 

注意:每次添加一個新的源/代碼文件,你需要清潔和再次構建適當構建二進制文件的項目。進一步的解釋可以在這裏找到:https://stackoverflow.com/a/17655165/2949966

+0

它工作。你可以在android或教程示例中給出一些關於cmake的鏈接。謝謝 –

+0

說實話,我的大部分知識都來自不同問題上的帖子/問題,沒有一個非常好的教程,我發現它很有用,它取決於我尋找或開始工作的內容,但我相信有一些我沒有見過。不過,我可以爲您提供一個我爲OpenCV製作的實現,它使用cmake構建OpenCV模塊,並允許開發人員編寫本機C/C++代碼,並從交叉編譯中受益:https://github.com/ahasbini/Android- OpenCV的。請考慮選擇答案作爲標記問題完整性的解決方案。 – ahasbini

+0

我附上項目鏈接https://github.com/nomi2013/JniCompileWithCmake我從哪裏可以得到這些文件夾和必要的文件 libavcodec的 ibavformat libavutil libavcodec的 其實當我編譯某些文件丟失。 謝謝 –