uni-app LivePusher勾选后跟腾讯云的trtc插件冲突

发布于 1周前 作者 ionicwang 来自 Uni-App

uni-app LivePusher勾选后跟腾讯云的trtc插件冲突

错误解决方案

错误描述

App原生语言插件/uts插件 依赖的三方库冲突

解决方案

请根据错误信息修改 App原生语言插件/uts插件 依赖的三方库或联系插件作者解决。


FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

  • What went wrong: Execution failed for task ‘:app:checkReleaseDuplicateClasses’.

    • A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
      • Duplicate class com.tencent.liteav.TXLiteAVCode found in modules:
        • jetified-LiteAVSDK_Professional-11.9.0.14445-runtime (com.tencent.liteav:LiteAVSDK_Professional:11.9.0.14445)
        • jetified-weex_livepusher-release-runtime (weex_livepusher-release.aar)
      • Duplicate class com.tencent.liteav.a found in modules:
        • jetified-LiteAVSDK_Professional-11.9.0.14445-runtime (com.tencent.liteav:LiteAVSDK_Professional:11.9.0.14445)
        • jetified-weex_livepusher-release-runtime (weex_livepusher-release.aar)
      • … (many more duplicate classes)
  • Go to the documentation to learn how to Fix dependency resolution errors.

  • Try:

    • Run with --debug option to get more log output.
    • Run with --scan to get full insights.
    • Get more help at https://help.gradle.org.
  • Exception is:

    • org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:app:checkReleaseDuplicateClasses’.
    • Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
    • Caused by: java.lang.RuntimeException: Duplicate class com.tencent.liteav.TXLiteAVCode found in modules…

2: Task failed with an exception.

  • What went wrong: Execution failed for task ‘:app:mergeReleaseNativeLibs’.

    • A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction
      • 2 files found with path ‘lib/arm64-v8a/libliteavsdk.so’ from inputs:
        • /home/[Name]/.gradle/caches/transforms-3/b2cfeaff713771231134b17d87331021/transformed/jetified-weex_livepusher-release/jni/arm64-v8a/libliteavsdk.so
        • /home/[Name]/.gradle/caches/transforms-3/a23f5c1389b94a1616a672a02ccf4092/transformed/jetified-LiteAVSDK_Professional-11.9.0.14445/jni/arm64-v8a/libliteavsdk.so
      • If you are using jniLibs and CMake IMPORTED targets, see JNI Libraries vs Imported Targets
  • Try:

    • Run with --debug option to get more log output.
    • Run with --scan to get full insights.
    • Get more help at https://help.gradle.org.
  • Exception is:

    • org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:app:mergeReleaseNativeLibs’.
    • Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction
    • … (stack trace)

2 回复

在处理uni-app中的LivePusher组件与腾讯云的TRTC插件冲突问题时,通常这类冲突源于对相机、麦克风等硬件资源的竞争,或者是两者使用的SDK版本不兼容。下面提供一个基本的代码案例,展示如何在uni-app中整合LivePusher和腾讯云的TRTC插件,同时尽量避免冲突。请注意,这里假设你已经正确安装了TRTC插件,并且已经获得了相应的SDK配置信息。

步骤一:页面布局

首先,在你的uni-app页面的.vue文件中,定义LivePusher组件。这里使用条件渲染来控制LivePusher的显示,以便在需要时切换至TRTC视图。

<template>
  <view>
    <button @click="switchToTRTC">切换到TRTC</button>
    <view v-if="!inTRTCMode">
      <live-pusher id="livePusher" :url="rtmpUrl" autoplay="true" muted="false"></live-pusher>
    </view>
    <view v-else>
      <!-- TRTC插件的容器,通过JS SDK控制 -->
      <view id="trtcContainer"></view>
    </view>
  </view>
</template>

步骤二:脚本逻辑

在脚本部分,处理组件的切换逻辑,以及TRTC的初始化。

<script>
export default {
  data() {
    return {
      rtmpUrl: 'rtmp://your_rtmp_server/live', // 替换为你的RTMP地址
      inTRTCMode: false
    };
  },
  methods: {
    switchToTRTC() {
      this.inTRTCMode = true;
      this.$nextTick(() => {
        this.initTRTC();
      });
    },
    initTRTC() {
      // 引入TRTC SDK(假设已经通过npm或script标签引入)
      const TRTC = require('tencent-cloud-trtc-sdk');
      const client = new TRTC.Client({ sdkAppId: 'YOUR_SDK_APP_ID' });
      client.init({ mode: 'videoCall' });
      client.join({
        roomId: 'YOUR_ROOM_ID',
        userId: 'YOUR_USER_ID'
      }).then(() => {
        const localStream = client.getLocalStream();
        const container = document.getElementById('trtcContainer');
        localStream.play(container);
      }).catch(err => {
        console.error('TRTC init error:', err);
      });
    }
  }
};
</script>

注意事项

  1. 资源释放:在切换回LivePusher时,确保正确释放TRTC的资源,避免内存泄漏。
  2. 权限管理:确保应用已请求并获得了相机、麦克风的使用权限。
  3. SDK版本兼容性:检查LivePusher组件和TRTC插件所使用的SDK版本是否兼容。
  4. 错误处理:增加更多的错误处理逻辑,以应对初始化失败、网络异常等情况。

上述代码提供了一个基本的框架,你可能需要根据实际情况调整TRTC的初始化参数和错误处理逻辑。

回到顶部