【音视频安卓开发 (一)】AndroidStudio项目配置权限、jni库路径、ABI、Cmake

cmake项目配置 

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

#设置头文件路径,头文件路径相对Cmake文件来确定
include_directories(src/main/cpp/include)


set(FF ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI})

add_library(avcodec SHARED IMPORTED)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${FF}/libavcodec.so)


add_library(avformat SHARED IMPORTED)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${FF}/libavformat.so)


add_library(avutil SHARED IMPORTED)
set_target_properties(avcodec PROPERTIES IMPORTED_LOCATION ${FF}/libavutil.so)

add_library(swscale SHARED IMPORTED)
set_target_properties(swscale PROPERTIES IMPORTED_LOCATION ${FF}/libswscale.so)

add_library(swresample SHARED IMPORTED)
set_target_properties(swresample PROPERTIES IMPORTED_LOCATION ${FF}/libswresample.so)

add_library(avfilter SHARED IMPORTED)
set_target_properties(avfilter PROPERTIES IMPORTED_LOCATION ${FF}/libavfilter.so)



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


target_link_libraries( # Specifies the target library.
                       native-lib
                       android
                       ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libavcodec.so
                       ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libavfilter.so
                       ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libavformat.so
                       ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libavutil.so
                       ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libswresample.so
                       ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libswscale.so
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

build.gradle

添加jni用到库所在的路径  

 

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.ffmpegplayer"
        minSdkVersion 19
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11"
            }
            ndk{
                abiFilters"armeabi-v7a"
            }
        }
        sourceSets{
            main{
                jniLibs.srcDirs=['libs']
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.10.2"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

读写权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

 

权限(版本) 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
CMake是一个跨平台的构建工具,它可以帮助开发者管理和构建项目Android Studio是一个集成开发环境(IDE),用于开发Android应用程序。在Android Studio中使用CMake可以方便地构建和管理C++代码。 在Android Studio中使用CMake,你需要在项目CMakeLists.txt文件中配置相关信息。CMakeLists.txt文件位于项目的根目录下,它定义了项目的构建规则和依赖关系。 以下是一个使用CMake构建Android项目的示例: 1. 在项目的根目录下创建一个CMakeLists.txt文件。 2. 在CMakeLists.txt文件中,你可以使用CMAKE_SOURCE_DIR变量来表示工程的根目录,使用CMAKE_CURRENT_SOURCE_DIR变量来表示当前处理的CMakeLists.txt所在的目录。 ```cmake # 设置CMake的最低版本要求 cmake_minimum_required(VERSION 3.10.2) # 设置项目名称 project(MyAndroidApp) # 添加C++源文件 add_library(mylib SHARED ${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/mylib.cpp) # 设置头文件搜索路径 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/include) # 链接 target_link_libraries(mylib log) # 设置生成的的输出路径 set_target_properties(mylib PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}) ``` 在上述示例中,我们使用了CMAKE_CURRENT_SOURCE_DIR变量来指定C++源文件和头文件的路径,并使用了CMAKE_SOURCE_DIR变量来指定生成的的输出路径。 请注意,上述示例仅为演示目的,实际的CMakeLists.txt文件可能会更加复杂,具体的配置取决于你的项目需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

༄yi笑奈何

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值