Flutter vlc player : App crashes on launch

552

Hye For me it worked when I added the following ones in my android/app/build.gradle

minifyEnabled false shrinkResources false

While check that you have minSdkVersion to 17

I have added a snippet for you to resolve the issue. Now I am looking for to have less size apk after adding flutter_vlc_player plugin.

buildTypes {
    release {
        // Signing with the debug keys for now, so `flutter run --release` works.
        signingConfig signingConfigs.debug
        minifyEnabled false
        shrinkResources false
    }
}
Share:
552
Admin
Author by

Admin

Updated on December 27, 2022

Comments

  • Admin
    Admin over 1 year

    I want flutter vlc player to stream live from my raspberry pi

    when I downloaded the example file from git their code works properly but when implemented the same code in my app the app straight away crashes with an

    error:

    Running Gradle task 'assembleDebug'...
    √ Built build\app\outputs\flutter-apk\app-debug.apk.
    Installing build\app\outputs\flutter-apk\app.apk...
    Debug service listening on ws://127.0.0.1:54105/Id2yfbjio-E=/ws
    Syncing files to device SM M515F...
    D/Dialog ( 6596): mIsSamsungBasicInteraction = false
    D/Dialog ( 6596): mIsSamsungBasicInteraction = false, isMetaDataInActivity = false
    D/PhoneWindow( 6596): forceLight changed to true from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4274 com.android.internal.policy.DecorView.updateColorViews:1547 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3252 android.view.Window.setFlags:1153 com.android.internal.policy.PhoneWindow.generateLayout:2474
    I/MultiWindowDecorSupport( 6596): [INFO] isPopOver = false
    I/MultiWindowDecorSupport( 6596): updateCaptionType >> DecorView@d8c1171[], isFloating: false, isApplication: false, hasWindowDecorCaption: false, hasWindowControllerCallback: false
    D/MultiWindowDecorSupport( 6596): setCaptionType = 0, DecorView = DecorView@d8c1171[]
    W/Gralloc3( 6596): allocator 3.x is not supported
    I/ViewRootImpl@9657a73MainActivity: setView = com.android.internal.policy.DecorView@d8c1171 TM=true MM=false
    E/AndroidRuntime( 6596): FATAL EXCEPTION: main
    E/AndroidRuntime( 6596): Process: com.example.video, PID: 6596
    E/AndroidRuntime( 6596): java.lang.AbstractMethodError: abstract method "void io.flutter.plugin.platform.PlatformView.onFlutterViewAttached(android.view.View)"
    E/AndroidRuntime( 6596): at io.flutter.plugin.platform.VirtualDisplayController.onFlutterViewAttached(VirtualDisplayController.java:181)
    E/AndroidRuntime( 6596): at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:233)
    E/AndroidRuntime( 6596): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:104)
    E/AndroidRuntime( 6596): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
    E/AndroidRuntime( 6596): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
    E/AndroidRuntime( 6596): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
    E/AndroidRuntime( 6596): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:738)
    E/AndroidRuntime( 6596): at android.os.MessageQueue.nativePollOnce(Native Method)
    E/AndroidRuntime( 6596): at android.os.MessageQueue.next(MessageQueue.java:336)
    E/AndroidRuntime( 6596): at android.os.Looper.loop(Looper.java:197)
    E/AndroidRuntime( 6596): at android.app.ActivityThread.main(ActivityThread.java:8167)
    E/AndroidRuntime( 6596): at java.lang.reflect.Method.invoke(Native Method)
    E/AndroidRuntime( 6596): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
    E/AndroidRuntime( 6596): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
    I/Process ( 6596): Sending signal. PID: 6596 SIG: 9
    Lost connection to device.
    

    Main.dart

    import 'dart:typed_data';
    
    import 'package:flutter/material.dart';
    import 'package:flutter_vlc_player/flutter_vlc_player.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatefulWidget {
      @override
      _MyAppState createState() => new _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(home: MyAppScaffold());
      }
    }
    
    class MyAppScaffold extends StatefulWidget {
      @override
      State<StatefulWidget> createState() => MyAppScaffoldState();
    }
    
    class MyAppScaffoldState extends State<MyAppScaffold> {
      String initUrl =
          "http://192.168.29.3:8080";
    
      Uint8List image;
      VlcPlayerController _videoViewController;
    
    
      var _scaffoldKey = new GlobalKey<ScaffoldState>();
      @override
      void initState() {
        _videoViewController = new VlcPlayerController(onInit: () {
          _videoViewController.play();
        });
    
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          key: _scaffoldKey,
          appBar: new AppBar(
            title: const Text('Plugin example app'),
          ),
          floatingActionButton: FloatingActionButton(
            child: Icon(Icons.camera),
            onPressed: _createCameraImage,
          ),
          body: Builder(builder: (context) {
            return Container(
              padding: EdgeInsets.all(10),
              child: ListView(
                shrinkWrap: true,
                children: <Widget>[
                  SizedBox(
                    height: 250,
                    child: new VlcPlayer(
                      aspectRatio: 16 / 9,
                      url: initUrl,
                      isLocalMedia: false,
                      controller: _videoViewController,
                      // Play with vlc options
    
                    ),
                  ),
    
                  Divider(height: 1),
                  image == null
                      ? Container()
                      : Container(child: Image.memory(image)),
                ],
              ),
            );
          }),
        );
      }
    
      @override
      void dispose() {
        _videoViewController.dispose();
        super.dispose();
      }
    
    
      void _createCameraImage() async {
        Uint8List file = await _videoViewController.takeSnapshot();
        setState(() {
          image = file;
        });
      }
    }
    

    AndroidManifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="com.example.video">
    
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.INTERNET" />
       <application
           android:label="video"
           android:icon="@mipmap/ic_launcher"
           android:usesCleartextTraffic="true">
            <activity
                android:name=".MainActivity"
                android:launchMode="singleTop"
                android:theme="@style/LaunchTheme"
                android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
                android:hardwareAccelerated="true"
                android:windowSoftInputMode="adjustResize"
                tools:ignore="Instantiatable">
                <!-- Specifies an Android theme to apply to this Activity as soon as
                     the Android process has started. This theme is visible to the user
                     while the Flutter UI initializes. After that, this theme continues
                     to determine the Window background behind the Flutter UI. -->
                <meta-data
                  android:name="io.flutter.embedding.android.NormalTheme"
                  android:resource="@style/NormalTheme"
                  />
                <!-- Displays an Android View that continues showing the launch screen
                     Drawable until Flutter paints its first frame, then this splash
                     screen fades out. A splash screen is useful to avoid any visual
                     gap between the end of Android's launch screen and the painting of
                     Flutter's first frame. -->
                <meta-data
                  android:name="io.flutter.embedding.android.SplashScreenDrawable"
                  android:resource="@drawable/launch_background"
                  />
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
            <!-- Don't delete the meta-data below.
                 This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
            <meta-data
                android:name="flutterEmbedding"
                android:value="2" />
        </application>
    
    </manifest>
    

    Please help me getting the solution. I desperately need to complete my app for project