一个安卓Cmake增加项目对C++的支持的配置问题

zq910515 2018-12-26 06:12:28
我项目需要添加依赖库。 ndk16

我的项目信息大致如下,一直build过不去
但是,我去掉CMakeLists.txt 文件中的
set_target_properties(libavcodec-56 ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libavcodec-56.so)
就可顺利通过。
我想知道,我这需要怎么配置?

************************************************************************************************


*********************build.gradle 文件*********************************************

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.cloud.bs.ffmpegtest01"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
ndk {
abiFilters "armeabi"
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}





*********************CMakeLists.txt 文件*********************************************


cmake_minimum_required(VERSION 3.4.1)

include_directories(
src/main/cpp/include
)

set(LIBS ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI})

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

# Sets the library as a shared library.
SHARED

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

add_library(libavcodec-56 SHARED IMPORTED)
set_target_properties(libavcodec-56 ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libavcodec-56.so)

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.
ffmpeg-lib

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






Build command failed.


Error while executing process D:\Android\SDK\cmake\3.6.4111459\bin\cmake.exe with arguments {-HD:\Android\MyApplications\FFMpegTest01\app -BD:\Android\MyApplications\FFMpegTest01\app\.externalNativeBuild\cmake\debug\armeabi -DANDROID_ABI=armeabi -DANDROID_PLATFORM=android-15 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\Android\MyApplications\FFMpegTest01\app\build\intermediates\cmake\debug\obj\armeabi -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=D:\Android\SDK\android-ndk-r16b_x64 -DCMAKE_CXX_FLAGS= -DCMAKE_TOOLCHAIN_FILE=D:\Android\SDK\android-ndk-r16b_x64\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=D:\Android\SDK\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja}


(include) CMakeLists.txt


(include) CMakeLists.txt


CMake Error at CMakeLists.txt:20 (set_target_properties):


-- Configuring incomplete, errors occurred!

*********************************Build信息********************************************
See also "D:/Android/MyApplications/FFMpegTest01/app/.externalNativeBuild/cmake/debug/armeabi/CMakeFiles/CMakeOutput.log".


Build command failed.


Error while executing process D:\Android\SDK\cmake\3.6.4111459\bin\cmake.exe with arguments {-HD:\Android\MyApplications\FFMpegTest01\app -BD:\Android\MyApplications\FFMpegTest01\app\.externalNativeBuild\cmake\release\armeabi -DANDROID_ABI=armeabi -DANDROID_PLATFORM=android-15 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=D:\Android\MyApplications\FFMpegTest01\app\build\intermediates\cmake\release\obj\armeabi -DCMAKE_BUILD_TYPE=Release -DANDROID_NDK=D:\Android\SDK\android-ndk-r16b_x64 -DCMAKE_CXX_FLAGS= -DCMAKE_TOOLCHAIN_FILE=D:\Android\SDK\android-ndk-r16b_x64\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=D:\Android\SDK\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja}


(include) CMakeLists.txt


(include) CMakeLists.txt


CMake Error at CMakeLists.txt:20 (set_target_properties):


-- Configuring incomplete, errors occurred!


See also "D:/Android/MyApplications/FFMpegTest01/app/.externalNativeBuild/cmake/release/armeabi/CMakeFiles/CMakeOutput.log".
...全文
284 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jklwan 2018-12-28
  • 打赏
  • 举报
回复
set_target_properties应该是少了PROPERTIES
jzp12 2018-12-28
  • 打赏
  • 举报
回复
SET_TARGET_PROPERTIES的输入参数缺少:PROPERTIES IMPORTED_LOCATION
->
set_target_properties(libavcodec-56 PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libavcodec-56.so)

说明
set_target_properties( libavcodec-56 #指定目标库名称
PROPERTIES IMPORTED_LOCATION #指明要设置的参数
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libavcodec-56.so #设定导入库的路径)
zq910515 2018-12-26
  • 打赏
  • 举报
回复
找到了,少了个参数!!!!!

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧