前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >LiteAVSDK商业版6.6+,安卓集成动态加载so

LiteAVSDK商业版6.6+,安卓集成动态加载so

原创
作者头像
腾讯云-chaoli
修改2019-12-25 17:18:56
3.3K0
修改2019-12-25 17:18:56
举报

一、简介

本篇文章主要介绍集成LiteAVSDK商业版、6.6以上的版本,安卓端采用动态加载so的方式时的写法。

版本

部分so必需在本地

P图的so必需按顺序加载

assets资源文件可否动态加载

6.5-

Y

Y

N

6.6+

N

N

Y

二、动态加载so

1、下载sdk

以LiteAVSDK_Enterprise_Android_6.8.7959版本为示例,下载解压sdk如下图:(左6.8、右6.5)

代码语言:javascript
复制
1、商业版6.4之前的版本只支持armeabi架构。2019-05-15
2、商业版6.5增加支持armeabi-v7a架构。2019-06-12
3、商业版6.6增加支持arm64-v8a架构。2019-08-06
4、从商业版6.6开始,assets进行了分包,其中assets-static需要放到工程本地,assets-dynamic资源可以远程加载。

2、本地集成jar、assets-static

如下图,导入jar,把assets-static里面的资源文件,复制到工程默认的assets静态资源文件里面。

3、复制so、assets-dynamic到应用根目录

下载、解压、校验完整性的过程,由客户自己灵活完成,demo就不给出演示了。我们直接从复制动效so和P图资源到内部存储开始。

示例demo需要把armeabi-v7a下的so文件、assets-dynamic里面的资源文件,都复制到手机sd卡下的一个文件夹里面。

代码语言:javascript
复制
//FileUtils类
public static boolean copyFolder (String oldPath , String newPath){

    File newFile = new File(newPath);

    if(!newFile.exists()){
        if(!newFile.mkdirs()){
            Log.e("TAG","无法创建路径");
            return  false;
        }
    }

    File oldFile = new File(oldPath);

    String[] files = oldFile.list();

    Log.i("TAG", "files.length: "+files.length);

    File temp;

    for(String file : files){
        if(oldPath.endsWith(File.separator)){
            temp = new File(oldFile + file);
        }else{
            temp = new File(oldPath + File.separator + file);
        }
        if(temp.isDirectory()){
            copyFolder(oldPath + "/"+file , newPath + "/" + file);
        }else if(!temp.exists()){
            Log.e("TAG", "copyFolder: oldFile not exist");
            return  false;
        }else if(!temp.isFile()){
            Log.e("TAG", "copyFolder: oldFile not file");
            return  false;
        }else if(!temp.canRead()){
            Log.e("TAG", "copyFolder: oldFile cannot read");
            return false;
        }else{
            try {
                FileInputStream fileInputStream = new FileInputStream(temp);
                FileOutputStream fileOutputStream = new FileOutputStream(newPath + "/" +temp.getName());
                byte[] buffer = new byte[1024];
                int byteRead;
                while ((byteRead = fileInputStream.read(buffer))!=-1){
                    fileOutputStream.write(buffer,0,byteRead);
                }
                fileInputStream.close();
                fileOutputStream.flush();
                fileOutputStream.close();

            } catch (Exception e) {
                e.printStackTrace();
            }

            File fileile = new File(newPath + "/" +temp.getName());
            fileile.setWritable(true);
            fileile.setReadable(true);
            fileile.setExecutable(true);
        }

    }
    return  true ;
}

4、动态加载so

以demo为操作示例,如下图ListView,操作步骤:

  • 点击copyFolder条目,复制粘贴so、assets-dynamic,从sd卡下复制到工程包名下的文件夹。复制成功返回true。
  • 点击setLibraryPath条目,调用sdk接口动态加载so。
  • 点击setLicence条目,设置动效Licence。这一步会下载校验licence,请保持网络通畅、给读写权限。
  • 点击getSDKVersionStr条目,获取sdk版本号、获取licence信息,能正常获取,代表前3步都正常,接下来可以体验动效了。

核心代码如下:

代码语言:javascript
复制
//MainActivity

//下载so的外部存储目录,比如sd卡下的armeabi-v7a文件夹
oldFilePath = Environment.getExternalStorageDirectory().getPath()+"/armeabi-v7a";

//应用的根目录file文件下新建armeabi-v7a文件夹
newFilePath = getFilesDir().getAbsolutePath()+"/armeabi-v7a";

//复制到内存存储
FileUtils.copyFolder(oldFilePath, newFilePath)

//sdk接口动态加载so
TXLiveBase.setLibraryPath(newFilePath);

//初始化sdk,设置直播、短视频licence
TXLiveBase.setConsoleEnabled(true);
TXLiveBase.getInstance().setLicence(getApplicationContext(), licenceUrl, licenseKey);
TXUGCBase.getInstance().setLicence(getApplicationContext(), licenceUrl, licenseKey);


//获取sdk版本号
String sdkVersionStr = TXLiveBase.getSDKVersionStr();
//获取licence信息
String licenceInfo = TXUGCBase.getInstance().getLicenceInfo(getApplication());

5、验证

点击ListView的摄像头推流,进入推流页面,开启推流,体验高级美颜。

  • 安卓PituDemo直接引入集成视频云终端团队封装的module,module里面的直播、短视频等功能点、api写法,可以参考官方文档
  • 建议把高级美颜都体验一遍,尤其是人脸识别的大眼、瘦脸、头部挂件等特效,正常都ok的。如果动效crash,请对比PituDemo,重新集成。

至此算是全部完成了。

三、本地集成

如果不想用aar集成,也不需要远程加载so,只需要在工程本地集成jar,导入商业版资源文件时,有个地方需要注意:

  • 6.6之后的版本,assets资源包被分包了,所以集成时不能简单的把assets-static、assets-dynamic里面的资源文件复制到工程的默认assets文件下,动效会无法识别资源。
  • 正确的做法是把aar包改成zip后缀,然后解压,里面有一个完整的assets资源包,把里面文件全复制到工程assets文件夹下,就可以正常集成了

四、包增量对比

两种集成方式,不同架构的apk体积对比如下图:

五、新版本打包参数

6.6之后的版本,要配置 App 打包参数;

6.6之后的版本,要配置 App 打包参数;

6.6之后的版本,要配置 App 打包参数:如下图文所示

代码语言:javascript
复制
packagingOptions {
    pickFirst '**/libc++_shared.so'
    doNotStrip "*/armeabi/libYTCommon.so"
    doNotStrip "*/armeabi-v7a/libYTCommon.so"
    doNotStrip "*/x86/libYTCommon.so"
    doNotStrip "*/arm64-v8a/libYTCommon.so"
}
代码语言:java
复制
//so没有加载成功,运行会报这个crash,请校验so完整性、检查加载流程,如果只部分特殊机型出现,请收集机型反馈给我们。
//极少数海外团队开发手机系统rom,自带的C++shared库有缺陷,导致无法正确加载so
java.lang.UnsatisfiedLinkError: No implementation found for void com.tencent.liteav.basic.datareport.TXCDRApi.nativeInitDataReport() 
(tried Java_com_tencent_liteav_basic_datareport_TXCDRApi_nativeInitDataReport and Java_com_tencent_liteav_basic_datareport_TXCDRApi_nativeInitDataReport__)
    at com.tencent.liteav.basic.datareport.TXCDRApi.nativeInitDataReport(Native Method)
    at com.tencent.liteav.basic.datareport.TXCDRApi.<clinit>(SourceFile:418)
    at com.tencent.liteav.basic.datareport.TXCDRApi.txReportDAU(SourceFile:73)
    at com.tencent.liteav.basic.b.e.a(SourceFile:560)
    at com.tencent.liteav.basic.b.e.d(SourceFile:465)
    at com.tencent.liteav.basic.b.e.b(SourceFile:51)
    at com.tencent.liteav.basic.b.e$1.a(SourceFile:203)
    at com.tencent.liteav.basic.b.c.run(SourceFile:127)
    at java.lang.Thread.run(Thread.java:784)
代码语言:java
复制
 //P图so找不到,会报这个crash。加上上面的打包参数,就可以解决,doNotStrip动效的so
 java.lang.UnsatisfiedLinkError: No implementation found for void com.tencent.ttpic.util.youtu.YTFaceDetectorBase.nativeSetRefine(boolean) 
 (tried Java_com_tencent_ttpic_util_youtu_YTFaceDetectorBase_nativeSetRefine and Java_com_tencent_ttpic_util_youtu_YTFaceDetectorBase_nativeSetRefine__Z)
        at com.tencent.ttpic.util.youtu.YTFaceDetectorBase.nativeSetRefine(Native Method)
        at com.tencent.ttpic.openapi.util.youtu.VideoPreviewFaceOutlineDetector.setRefine(SourceFile:428)
        at com.tencent.aekit.api.standard.filter.AESticker.construct(SourceFile:110)
        at com.tencent.aekit.api.standard.filter.AESticker.<init>(SourceFile:101)
        at com.tencent.rtmp.a.a.a(SourceFile:544)
        at com.tencent.liteav.beauty.b.d(SourceFile:1146)
        at com.tencent.liteav.beauty.b.c(SourceFile:1124)
        at com.tencent.liteav.beauty.b.k(SourceFile:51)
        at com.tencent.liteav.beauty.b$14.run(SourceFile:1340)
        at com.tencent.liteav.beauty.b.a(SourceFile:1995)
        at com.tencent.liteav.beauty.b.a(SourceFile:252)
        at com.tencent.liteav.beauty.d.a(SourceFile:295)
        at com.tencent.liteav.beauty.d.a(SourceFile:312)
        at com.tencent.liteav.c.b(SourceFile:1259)
        at com.tencent.liteav.b.a(SourceFile:410)
        at com.tencent.liteav.b.onTextureProcess(SourceFile:370)
        at com.tencent.liteav.renderer.TXCGLSurfaceView.onDrawFrame(SourceFile:491)
        at com.tencent.liteav.renderer.TXCGLSurfaceViewBase$i.i(SourceFile:532)
        at com.tencent.liteav.renderer.TXCGLSurfaceViewBase$i.run(SourceFile:277)

六、资源

相关文章:LiteAVSDK集成,动态加载so库

PituDemo下载(需要商业SDK解压密码)

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、简介
  • 二、动态加载so
    • 1、下载sdk
      • 2、本地集成jar、assets-static
        • 3、复制so、assets-dynamic到应用根目录
          • 4、动态加载so
            • 5、验证
            • 三、本地集成
            • 四、包增量对比
            • 五、新版本打包参数
            • 六、资源
            相关产品与服务
            云直播
            云直播(Cloud Streaming Services,CSS)为您提供极速、稳定、专业的云端直播处理服务,根据业务的不同直播场景需求,云直播提供了标准直播、快直播、云导播台三种服务,分别针对大规模实时观看、超低延时直播、便捷云端导播的场景,配合腾讯云视立方·直播 SDK,为您提供一站式的音视频直播解决方案。
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档