java - Webrtc 部分仅在发布版本上崩溃在调试版本上工作正常

标签 java android webrtc

我正在开发一个Webrtc视频聊天应用程序。它在调试版本上运行良好,不会崩溃,但在发布版本上会崩溃。我的Webrtc版本是

implementation 'org.webrtc:google-webrtc:1.0.27771'

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

Fatal error in:

../../../../usr/local/google/home/sakal/code/webrtc-aar-release/src/sdk/android/src/jni/jni_generator_helper.cc, line 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);
        }
    }

最佳答案

我也遇到了同样的问题,解决方案是

将文件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'
    }
}

关于java - Webrtc 部分仅在发布版本上崩溃在调试版本上工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56064641/

相关文章:

java - 通过日期字符串获取其他TimeZone的时间,结果错误

java - 无限的TimerTask方法调用

java - 主应用程序下载另一个应用程序然后使用它

java - Android 数据绑定(bind)将参数传递给 onClick 方法

java - 在 Play 上强制执行 SSL!框架

java - 'Stock stock = new Stock("HR.S")' 如何导致输出?

android - SimpleDateFormat 日期错误

node.js - 使用 Node js 在 LAN 上进行点对点连接

WebRTC - 重用连接

javascript - 如何将 signalmaster 集成到现有的expressjs 服务器