AgoraIO-Community / Agora-Flutter-Quickstart

Quickstart guide for the Agora Flutter SDK(Android/iOS)
MIT License
509 stars 192 forks source link

black screen for video stream in release only #209

Closed khaled720 closed 3 years ago

khaled720 commented 3 years ago

Hi i have cloned agora quickstart it is working fine debug and release But when i migrate to my own project video stream works fine in debug mode only and in release it is not working and giving exceptions in log and black screen

here is my pubspec : name: Stremo description: Stremo Mobile application.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.2.0+2

environment: sdk: ">=2.7.0 <3.0.0"

dependencies: flutter: sdk: flutter

cupertino_icons: ^1.0.0 flutter_statusbarcolor: ^0.2.3 rive: keyboard_attachable: ^1.0.3 carousel_slider: ^2.3.1 http: toast: ^0.1.5 date_time_picker: "^1.1.0" dio: provider: ^3.1.0 video_player: better_player: git: url: https://github.com/khaled720/betterplayer.git shared_preferences: ^0.5.6 flutter_animated_dialog: ^1.2.0 shimmer: font_awesome_flutter: share_extend: ^1.1.9 audioplayers: ^0.13.2

permission_handler: ^5.0.1+1 agora_rtc_engine: ^3.2.1

firebase_core: ^0.5.3 cloud_firestore: ^0.14.4 timeago: google_sign_in: flutter_facebook_auth: flutter_login_facebook: flutter_twitter_login: git: git://github.com/eudangeld/flutter_twitter_login.git apple_sign_in:

dev_dependencies: flutter_test: sdk: flutter flutter:

uses-material-design: true

assets:

--------------------and here is my app/gradle

def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } }

def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { // throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")

}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' }

def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' }

apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" / def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) } / android { compileSdkVersion 29

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
    disable 'InvalidPackage'
    checkReleaseBuilds false
   // abortOnError false
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.stremo.stremo_mobile"
    minSdkVersion 23
    targetSdkVersion 29
    versionCode flutterVersionCode.toInteger()
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

            ndk {
        abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86'
                 }
    multiDexEnabled true

}

/ signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } }/ buildTypes { release { signingConfig signingConfigs.debug

        shrinkResources true
        minifyEnabled true
        useProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
         'proguard-rules.pro' 

   }

}

}

flutter { source '../..' }

dependencies { implementation 'io.agora.rtc:full-sdk:3.0.1' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'com.facebook.android:facebook-android-sdk:[5,6)' implementation "com.android.support:multidex:1.0.3" implementation 'com.google.firebase:firebase-core:16.0.7' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'

} apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services'

------------------------here is proguard rules

Flutter Wrapper

-keep class io.flutter.app. { *; } -keep class io.flutter.plugin.* { ; } -keep class io.flutter.util. { *; } -keep class io.flutter.view. { *; } -keep class io.flutter.* { ; } -keep class io.flutter.plugins. { *; } -keep class io.agora.{;} -keepattributes Annotation* -keep class kotlin.* { ; } -keep class org.jetbrains. { *; } -dontwarn io.flutter.embedding.**

and this is the Exception in log when i try to start Video :

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, Incomplete hierarchy for class RtcEngineManager, unresolved classes [io.agora.rtc.base.IRtcEngine$RtcEngineInterface], null, java.lang.IllegalStateException: Incomplete hierarchy for class RtcEngineManager, unresolved classes [io.agora.rtc.base.IRtcEngine$RtcEngineInterface] E/flutter (15341): at kotlin.reflect.jvm.internal.components.RuntimeErrorReporter.reportIncompleteHierarchy(Unknown Source:41) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassTypeConstructor.computeSupertypes(Unknown Source:211) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.types.AbstractTypeConstructor$supertypes$1.invoke(Unknown Source:4) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.types.AbstractTypeConstructor$supertypes$1.invoke(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(Unknown Source:86)
E/flutter (15341): at kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.types.AbstractTypeConstructor.getSupertypes(Unknown Source:2) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope.getNonDeclaredVariableNames(Unknown Source:8) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedMemberScope$variableNamesLazy$2.invoke(Unknown Source:12) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedMemberScope$variableNamesLazy$2.invoke(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(Unknown Source:86)
E/flutter (15341): at kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.storage.StorageKt.getValue(Unknown Source:10) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedMemberScope.getVariableNamesLazy(Unknown Source:7) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedMemberScope.getVariableNames(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedMemberScope.addFunctionsAndProperties(Unknown Source:14) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedMemberScope.computeDescriptors(Unknown Source:36) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope$allDescriptors$1.invoke(Unknown Source:12) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope$allDescriptors$1.invoke(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedLazyValue.invoke(Unknown Source:86)
E/flutter (15341): at kotlin.reflect.jvm.internal.impl.storage.LockBasedStorageManager$LockBasedNotNullLazyValue.invoke(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassMemberScope.getContributedDescriptors(Unknown Source:12) E/flutter (15341): at kotlin.reflect.jvm.internal.impl.resolve.scopes.ResolutionScope$DefaultImpls.getContributedDescriptors$default(Unknown Source:18) E/flutter (15341): at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.getMembers(Unknown Source:17) E/flutter (15341): at kotlin.reflect.jvm.internal.KClassImpl$Data$declaredNonStaticMembers$2.invoke(Unknown Source:10) E/flutter (15341): at kotlin.reflect.jvm.internal.KClassImpl$Data$declaredNonStaticMembers$2.invoke(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(Unknown Source:17) E/flutter (15341): at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(Unknown Source:0) E/flutter (15341): at kotlin.reflect.jvm.internal.KClassImpl$Data.getDeclaredNonStaticMembers(Unknown Source:8) E/flutter (15341): at kotlin.reflect.full.KClasses.getDe E/flutter (15341): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, Please init RtcEngine first!, null, java.lang.RuntimeException: Please init RtcEngine first! E/flutter (15341): at io.agora.rtc.base.RtcSurfaceView.(Unknown Source:36) E/flutter (15341): at io.agora.agora_rtc_engine.AgoraSurfaceView.(Unknown Source:29) E/flutter (15341): at io.agora.agora_rtc_engine.AgoraSurfaceViewFactory.create(Unknown Source:32) E/flutter (15341): at io.flutter.plugin.platform.SingleViewPresentation.onCreate(Unknown Source:116) E/flutter (15341): at android.app.Dialog.dispatchOnCreate(Dialog.java:579) E/flutter (15341): at android.app.Dialog.show(Dialog.java:397) E/flutter (15341): at android.app.Presentation.show(Presentation.java:250) E/flutter (15341): at io.flutter.plugin.platform.VirtualDisplayController.(Unknown Source:55) E/flutter (15341): at io.flutter.plugin.platform.VirtualDisplayController.create(Unknown Source:65) E/flutter (15341): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(Unknown Source:110)
E/flutter (15341): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(Unknown Source:152) E/flutter (15341): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(Unknown Source:149) E/flutter (15341): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(Unknown Source:17) E/flutter (15341): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(Unknown Source:57) E/flutter (15341): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(Unknown Source:4) E/flutter (15341): at android.os.MessageQueue.nativePollOnce(Native Method) E/flutter (15341): at android.os.MessageQueue.next(MessageQueue.java:363) E/flutter (15341): at android.os.Looper.loop(Looper.java:173) E/flutter (15341): at android.app.ActivityThread.main(ActivityThread.java:8178) E/flutter (15341): at java.lang.reflect.Method.invoke(Native Method) E/flutter (15341): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) E/flutter (15341): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) E/flutter (15341): ) E/flutter (15341): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582) E/flutter (15341): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159) E/flutter (15341): E/flutter (15341): #2 TextureAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1039) E/flutter (15341): E/flutter (15341): #3 AndroidViewController.create (package:flutter/src/services/platform_views.dart:749) E/flutter (15341): E/flutter (15341): #4 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:174) E/flutter (15341): E/flutter (15341):

please help me to fix this @plutoless

plutoless commented 3 years ago

could you pls provide a minimal reproducible project so that we can check what might go wrong?

gathodeharrkirat commented 3 years ago

hi... Have you found a solution yet ?

LichKing-2234 commented 3 years ago

pls make sure the RtcEngine has been initializated.

Unhandled Exception: PlatformException(error, Please init RtcEngine first!, null, java.lang.RuntimeException: Please init RtcEngine first!
LichKing-2234 commented 3 years ago

you can set minifyEnabled to false to confirm is the error from proguard?

gathodeharrkirat commented 3 years ago

I am also facing the same black screen issue and this the code could you help me with this

import 'package:agora_rtc_engine/rtc_engine.dart'; import 'package:agora_rtc_engine/rtc_local_view.dart' as RtcLocalView; import 'package:agora_rtc_engine/rtc_remote_view.dart' as RtcRemoteView; import 'package:flutter/material.dart'; import 'package:newsimarnkapp/home/model_home_screen/live_streaming/settings.dart';

class CallPage extends StatefulWidget { final String channelName; final ClientRole role; const CallPage({Key key, this.channelName, this.role}) : super(key: key);

@override _CallPageState createState() => _CallPageState(); }

class _CallPageState extends State { final _users = []; final _infoStrings = []; bool muted = false; RtcEngine _engine;

@override void dispose() { _users.clear(); _engine.leaveChannel(); _engine.destroy(); super.dispose(); }

@override void initState() { super.initState(); initialize(); }

Future initialize() async { if (APP_ID.isEmpty) { setState(() { _infoStrings.add( 'APP_ID missing, please provide your APP_ID in settings.dart', ); _infoStrings.add('Agora Engine is not starting'); }); return; }

await _initAgoraRtcEngine();
_addAgoraEventHandlers();

await _engine.enableWebSdkInteroperability(true);
VideoEncoderConfiguration configuration = VideoEncoderConfiguration();
configuration.dimensions = VideoDimensions(1920, 1080);
await _engine.setVideoEncoderConfiguration(configuration);

/// Join channel
///
await _engine.joinChannel(Token, widget.channelName, null, 0);

}

Future _initAgoraRtcEngine() async { _engine = await RtcEngine.create(APP_ID); await _engine.enableVideo(); await _engine.setChannelProfile(ChannelProfile.LiveBroadcasting); await _engine.setClientRole(widget.role); }

void _addAgoraEventHandlers() { _engine.setEventHandler(RtcEngineEventHandler(error: (code) { setState(() { final info = 'onError: $code'; _infoStrings.add(info); }); }, joinChannelSuccess: (channel, uid, elapsed) { setState(() { final info = 'onJoinChannel: $channel, uid: $uid'; _infoStrings.add(info); }); }, leaveChannel: (stats) { setState(() { _infoStrings.add('onLeaveChannel'); _users.clear(); }); }, userJoined: (uid, elapsed) { setState(() { final info = 'userJoined: $uid'; _infoStrings.add(info); _users.add(uid); }); }, userOffline: (uid, elapsed) { setState(() { final info = 'userOffline: $uid'; _infoStrings.add(info); _users.remove(uid); }); })); }

/// Toolbar layout Widget _toolbar() { if (widget.role == ClientRole.Audience) return Container(); return Container( alignment: Alignment.bottomCenter, padding: const EdgeInsets.symmetric(vertical: 48), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ RawMaterialButton( onPressed: _onToggleMute, child: Icon( muted ? Icons.mic_off : Icons.mic, color: muted ? Colors.white : Colors.blueAccent, size: 20.0, ), shape: CircleBorder(), elevation: 2.0, fillColor: muted ? Colors.blueAccent : Colors.white, padding: const EdgeInsets.all(12.0), ), RawMaterialButton( onPressed: () => _onCallEnd(context), child: Icon( Icons.call_end, color: Colors.white, size: 35.0, ), shape: CircleBorder(), elevation: 2.0, fillColor: Colors.redAccent, padding: const EdgeInsets.all(15.0), ), RawMaterialButton( onPressed: _onSwitchCamera, child: Icon( Icons.switch_camera, color: Colors.blueAccent, size: 20.0, ), shape: CircleBorder(), elevation: 2.0, fillColor: Colors.white, padding: const EdgeInsets.all(12.0), ) ], ), ); }

void _onSwitchCamera() { _engine.switchCamera(); }

// Information panel to display logs Widget _panel() { return Container( padding: const EdgeInsets.symmetric(vertical: 48), alignment: Alignment.bottomCenter, child: FractionallySizedBox( heightFactor: 0.5, child: Container( padding: const EdgeInsets.symmetric(vertical: 48), child: ListView.builder( reverse: true, itemCount: _infoStrings.length, itemBuilder: (BuildContext context, int index) { if (_infoStrings.isEmpty) { return null; } return Padding( padding: const EdgeInsets.symmetric( vertical: 3, horizontal: 10, ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Flexible( child: Container( padding: const EdgeInsets.symmetric( vertical: 2, horizontal: 5, ), decoration: BoxDecoration( color: Colors.yellowAccent, borderRadius: BorderRadius.circular(5), ), child: Text( _infoStrings[index], style: TextStyle(color: Colors.blueGrey), ), ), ) ], ), ); }, ), ), ), ); }

/// Stop live streaming void _onCallEnd(BuildContext context) { Navigator.pop(context); }

/// Mute void _onToggleMute() { setState(() { muted = !muted; }); _engine.muteLocalAudioStream(muted); }

@override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.black, body: Center( child: Stack( children: [ _panel(), _toolbar(), ], ), ), );

gathodeharrkirat commented 3 years ago

this is the pubspec.yaml

name: newsimarnkapp description: A new Flutter project.

The following line prevents the package from being accidentally published to

pub.dev using pub publish. This is preferred for private packages.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

The following defines the version and build number for your application.

A version number is three numbers separated by dots, like 1.2.43

followed by an optional build number separated by a +.

Both the version and the builder number may be overridden in flutter

build by specifying --build-name and --build-number, respectively.

In Android, build-name is used as versionName while build-number used as versionCode.

Read more about Android versioning at https://developer.android.com/studio/publish/versioning

In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.

Read more about iOS versioning at

https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html

version: 1.0.0+1

environment: sdk: ">=2.7.0 <3.0.0"

dependencies: flutter: sdk: flutter firebase_auth: firebase_core: cloud_firestore: image_picker: provider: firebase_storage: flutter_neumorphic: flutter_spinkit: video_player: ^0.11.1+2 agora_rtc_engine: ^3.1.2 permission_handler: ^3.0.0 wakelock: ^0.1.4+1 shared_preferences: ^2.0.3 flutter_swiper: ^1.1.6 intl: ^0.17.0 blur: ^1.0.1

The following adds the Cupertino Icons font to your application.

Use with the CupertinoIcons class for iOS style icons.

cupertino_icons: ^1.0.2

dev_dependencies: flutter_test: sdk: flutter

For information on the generic Dart part of this file, see the

following page: https://dart.dev/tools/pub/pubspec

The following section is specific to Flutter.

flutter:

The following line ensures that the Material Icons font is

included with your application, so that you can use the icons in

the material Icons class.

uses-material-design: true

To add assets to your application, add an assets section, like this:

assets:

gathodeharrkirat commented 3 years ago

I tried minifyEnabled false but it caused error in gradle

gathodeharrkirat commented 3 years ago

This the DEBUG CONSOLE response when trying to go live

I/ExtendedACodec(20659): setupVideoEncoder() W/ACodec (20659): do not know color format 0x7fa30c04 = 2141391876 W/ACodec (20659): do not know color format 0x7f000789 = 2130708361 I/ACodec (20659): setupAVCEncoderParameters with [profile: Baseline] [level: Level1] I/ACodec (20659): [OMX.qcom.video.encoder.avc] cannot encode HDR static metadata. Ignoring. I/ACodec (20659): setupVideoEncoder succeeded I/ExtendedACodec(20659): [OMX.qcom.video.encoder.avc] configure, AMessage : AMessage(what = 'conf', target = 1) = { I/ExtendedACodec(20659): int32_t width = 1280 I/ExtendedACodec(20659): int32_t height = 720 I/ExtendedACodec(20659): int32_t bitrate = 1074450 I/ExtendedACodec(20659): string mime = "video/avc" I/ExtendedACodec(20659): int32_t frame-rate = 15 I/ExtendedACodec(20659): int32_t i-frame-interval = 301 I/ExtendedACodec(20659): int32_t bitrate-mode = 1 I/ExtendedACodec(20659): int32_t color-format = 21 I/ExtendedACodec(20659): int32_t encoder = 1 I/ExtendedACodec(20659): } 60 I/GDPAndroid(20659): getCpuTemperature valid path:/sys/class/thermal/thermal_zone0/temp

LichKing-2234 commented 3 years ago

I tried minifyEnabled false but it caused error in gradle

what error?

LichKing-2234 commented 3 years ago

I will close this issue, you can reopen it if it still exists.

Khatri7yash commented 2 years ago

Mostly the problem is with resolution, Resolution more then 720p will result into black screen in some devices so decrease the resolution to 720p because in my case that helps me a lot... like now that black screen issue is solved.... Hoping my answer become helpful to you guys :)