android studio引入ijkplayer二次开发

我们命令行打出的包是so库,无法直接debug,对于阅读代码已经修改不是很容易。

我们今天把代码引入android studio。

本文参考了如何将ijkplayer引入AS工程中进行二次开发_音视频开发进阶-CSDN博客

编译成功ijk后

我们打开ijk目录

选择我们需要的cpu架构

我们以ijkplayer-arm64为例

1、修改android/ijkplayer/ijkplayer-arm64/build.gradle

android {
    defaultConfig {
        //增加下面内容
    externalNativeBuild {
        ndkBuild {
            arguments "NDK_APPLICATION:=src/main/jni/Application.mk"
            abiFilters "arm64-v8a"
        }
    }
    }
    
//    删除掉下面的内容
    // sourceSets.main {
//     jniLibs.srcDirs 'src/main/libs'
//     jni.srcDirs = [] // This prevents the auto generation of Android.mk
// }
    
    //增加下面内容
    externalNativeBuild {
        ndkBuild {
            path "src/main/jni/Android.mk"

        }
    }
    
    //增加debug模式    
    buildTypes {
    debug {
        debuggable true
        jniDebuggable true
        ndk {
            debuggable true
        }
    }
}
}

2、将ijkplayer-arm64作为module引入android studio,不要直接从硬盘目录里面copy因为里面有些文件是链接。可以在androidStudio当中copy。

3、我们知道ijk的底层调用ffmpeg,所以我们还要引入ffmpeg。

我们在ijkplayer的源码中,可以看到android/contrib/build有编译成功的ffmpeg各种架构的动态库

我们把android/contrib/build/ffmpeg-arm64/output复制到我们android工程的主目录下

4、我们打开引入模块的Android.mk

可以看到里面是

# Copyright (c) 2013 Bilibili
# copyright (c) 2013 Zhang Rui <[email protected]>
#
# This file is part of ijkPlayer.
#
# ijkPlayer is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# ijkPlayer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with ijkPlayer; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

LOCAL_PATH := $(call my-dir)

MY_APP_JNI_ROOT := $(realpath $(LOCAL_PATH))
MY_APP_PRJ_ROOT := $(realpath $(MY_APP_JNI_ROOT)/..)
MY_APP_ANDROID_ROOT := $(realpath $(MY_APP_PRJ_ROOT)/../../../..)

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
MY_APP_FFMPEG_OUTPUT_PATH := $(realpath $(MY_APP_ANDROID_ROOT)/contrib/build/ffmpeg-armv7a/output)
MY_APP_FFMPEG_INCLUDE_PATH := $(realpath $(MY_APP_FFMPEG_OUTPUT_PATH)/include)
endif
ifeq ($(TARGET_ARCH_ABI),armeabi)
MY_APP_FFMPEG_OUTPUT_PATH := $(realpath $(MY_APP_ANDROID_ROOT)/contrib/build/ffmpeg-armv5/output)
MY_APP_FFMPEG_INCLUDE_PATH := $(realpath $(MY_APP_FFMPEG_OUTPUT_PATH)/include)
endif
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
MY_APP_FFMPEG_OUTPUT_PATH := $(realpath $(MY_APP_ANDROID_ROOT)/contrib/build/ffmpeg-arm64/output)
MY_APP_FFMPEG_INCLUDE_PATH := $(realpath $(MY_APP_FFMPEG_OUTPUT_PATH)/include)
endif
ifeq ($(TARGET_ARCH_ABI),x86)
MY_APP_FFMPEG_OUTPUT_PATH := $(realpath $(MY_APP_ANDROID_ROOT)/contrib/build/ffmpeg-x86/output)
MY_APP_FFMPEG_INCLUDE_PATH := $(realpath $(MY_APP_FFMPEG_OUTPUT_PATH)/include)
endif
ifeq ($(TARGET_ARCH_ABI),x86_64)
MY_APP_FFMPEG_OUTPUT_PATH := $(realpath $(MY_APP_ANDROID_ROOT)/contrib/build/ffmpeg-x86_64/output)
MY_APP_FFMPEG_INCLUDE_PATH := $(realpath $(MY_APP_FFMPEG_OUTPUT_PATH)/include)
endif

include $(call all-subdir-makefiles)

设置ffmpeg的路径

这里如果相对路径搞不明白,完全可以写成绝对路径

我这里就是下面这样写的

MY_APP_FFMPEG_OUTPUT_PATH := $(realpath  /Users/user/code/yuanxuzhen/ijkplayer-demo/android/contrib/build/ffmpeg-arm64/output)
MY_APP_FFMPEG_INCLUDE_PATH := $(realpath $(MY_APP_FFMPEG_OUTPUT_PATH)/include)

5、加入ndk的路径

local.properties

sdk.dir=/Users/user/Library/Android/sdk
ndk.dir=/Users/user/Library/Android/sdk/ndk/android-ndk-r12b

6 、在使用ijk的module引入ijkplayer-arm64

implementation project(path: ':ijkplayer-arm64')

通过上面的代码我们就可以正常使用了与调试了

猜你喜欢

转载自blog.csdn.net/qq_15255121/article/details/123144691