【问题标题】:Webrtc part crashes only on Release Build works fine on Debug buildWebrtc 部分仅在 Release Build 上崩溃,在 Debug build 上工作正常
【发布时间】:2022-01-12 01:26:41
【问题描述】:

[已解决] 我正在开发一个 Webrtc 视频聊天应用程序。它在 Debug 构建上运行良好,不会崩溃,但在 Release Build 上会崩溃。我的 Webrtc 版本是

实现'org.webrtc:google-webrtc:1.0.27771'

每当我调用这个函数时,我都会得到错误

# 致命错误: ../../../../usr/local/google/home/sakal/code/webrtc-aar-release/src/sdk/android/src/jni/jni_generator_helper.cc, 第 59 行

这就是它崩溃的地方,

    public void start() {

        if (Nammu.checkPermission(CAMERA)) {

            //NEW
            PeerConnectionFactory.InitializationOptions initializationOptions =
                    PeerConnectionFactory.InitializationOptions.builder(this)
                            //.setEnableVideoHwAcceleration(true)
                            .setEnableInternalTracer(true)
                            //.setFieldTrials("WebRTC-FlexFEC-03/Enabled/")
                            .createInitializationOptions();
            PeerConnectionFactory.initialize(initializationOptions);


            PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
            DefaultVideoEncoderFactory defaultVideoEncoderFactory = new DefaultVideoEncoderFactory(
                    rootEglBase.getEglBaseContext(),  /* enableIntelVp8Encoder */true,  /* enableH264HighProfile */false);
            DefaultVideoDecoderFactory defaultVideoDecoderFactory = new DefaultVideoDecoderFactory(rootEglBase.getEglBaseContext());


            //NEW
        peerConnectionFactory = PeerConnectionFactory.builder()
                .setOptions(options)
                .setVideoEncoderFactory(defaultVideoEncoderFactory)
                .setVideoDecoderFactory(defaultVideoDecoderFactory)
                .createPeerConnectionFactory();

            VideoCapturer videoCapturerAndroid;
            videoCapturerAndroid = createCameraCapturer(new Camera1Enumerator(false));


            audioConstraints = new MediaConstraints();
            videoConstraints = new MediaConstraints();
            sdpConstraints = new MediaConstraints();

            if (videoCapturerAndroid != null) {

                //NEW
            SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", rootEglBase.getEglBaseContext());
            videoSource = peerConnectionFactory.createVideoSource(videoCapturerAndroid.isScreencast());
            videoCapturerAndroid.initialize(surfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver());

            }
            localVideoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);

            //create an AudioSource instance
            audioSource = peerConnectionFactory.createAudioSource(audioConstraints);

            localAudioTrack = peerConnectionFactory.createAudioTrack("101", audioSource);
            localAudioTrack.setEnabled(true);
            localAudioTrack.setVolume(1);

            if (videoCapturerAndroid != null) {
                videoCapturerAndroid.startCapture(1024, 720, 30);
            }

            localVideoTrack.addSink(localVideoView);

            localVideoView.setMirror(true);
            remoteVideoView.setMirror(true);

            gotUserMedia = true;
            if (SignallingClient.getInstance().isInitiator) {
                onTryToStart();
            }
        }else {
            Nammu.askForPermission(this, CAMERA, permissionCameraCallback);
        }
    }

解决方案

我已经解决了这个问题。这是由于progurd问题而发生的。 简单地把

        release {
            consumerProguardFiles 'proguard-project.txt'
        }

解决了我的问题。 this git repo 也可能会有所帮助。

【问题讨论】:

  • 您是否为您的发布版本设置了程序规则?如果是这样,请同时发布您的 proguard 规则。
  • 谢谢我已经弄清楚了,这是progurd问题。
  • @SadmanSamee 请您也可以将您的解决方案作为答案发布(而不是将其与您的问题混合)然后接受它作为批准的答案吗?谢谢。
  • @SadmanSamee 很高兴知道您已经解决了您的问题。 :)
  • @bruno-leveque 我们应该在哪里包含和放置 proguard 以及它的 txt 文件。请建议。我面临同样的问题。谢谢。

标签: java android webrtc


【解决方案1】:

这是由于 progurd 问题而发生的。简单地说

    release {
        consumerProguardFiles 'proguard-project.txt'
    }

【讨论】:

  • 我们应该在哪里包含和放置proguard,它是txt文件。请建议。我面临同样的问题。谢谢。
  • 你好,上面的链接说:默认情况下,这个文件中的标志附加到/home/renyuzhuo/Android/Sdk/tools/proguard/proguard-android.txt中指定的标志#你可以通过更改 build.gradle 中的 proguardFiles # 指令来编辑包含路径和顺序。 ## 更多详情请看#developer.android.com/guide/developing/tools/proguard.html
【解决方案2】:

我遇到了同样的问题,解决办法是

将文件proguard-rules.pro 添加到app 文件夹

## WebRTC
-keep class com.cloudwebrtc.webrtc.** { *; }
-keep class org.webrtc.** { *; }

在 build.gradle 中,将以下 2 个属性添加到 buildTypes -> release

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

【讨论】:

    猜你喜欢
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    相关资源
    最近更新 更多