EPNW / opus_flutter

Repository for the federal organized opus_flutter plugin, which is needed to easily obtain a DynamicLibrary of opus for the use in opus_dart on flutter platforms.
https://pub.dev/packages/opus_flutter
9 stars 10 forks source link

Flutter build web --release somehow make library from load function different from the parameter opus_dart.init(lib) #13

Closed alhamed1 closed 3 years ago

alhamed1 commented 3 years ago

It works in a debug and a profile builds, but not in a release build because the javascript code minified.

Code:

class AppController extends BaseController {
  @override
  void onInit() async {
    super.onInit();
    var lib = await opus_flutter.load();
    print("loaded");
    opus_dart.initOpus(lib);
    print("init");
    print(opus_dart.getOpusVersion());
  }
}

Browser console output:

Loading app from service worker.
js_primitives.dart:47 loaded
js_helper.dart:1130 Uncaught Invalid argument(s): The type minified:aq1<() => minified:W<minified:cK>> is not known!
    at Object.b (http://localhost:60956/main.dart.js:3900:3)
    at Object.aof (http://localhost:60956/main.dart.js:20893:14)
    at Object.cn (http://localhost:60956/main.dart.js:20897:86)
    at a_r.ahZ (http://localhost:60956/main.dart.js:76294:15)
    at Object.dv (http://localhost:60956/main.dart.js:13081:37)
    at http://localhost:60956/main.dart.js:40657:5
    at anv.a (http://localhost:60956/main.dart.js:5564:71)
    at anv.$2 (http://localhost:60956/main.dart.js:34783:23)
    at amo.$1 (http://localhost:60956/main.dart.js:34775:30)
    at SF.ph (http://localhost:60956/main.dart.js:35860:41)

Flutter doctor --verbose: [√] Flutter (Channel stable, 2.2.2, on Microsoft Windows [Version 10.0.19042.985], locale en-AE) • Flutter version 2.2.2 at C:\flutter • Framework revision d79295af24 (3 weeks ago), 2021-06-11 08:56:01 -0700 • Engine revision 91c9fc8fe0 • Dart version 2.13.3

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at D:\Android\sdk • Platform android-30, build-tools 30.0.3 • ANDROID_HOME = D:\Android\sdk • ANDROID_SDK_ROOT = D:\Android\sdk • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.1.0) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] IntelliJ IDEA Community Edition (version 2020.1) • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1.3 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart

[√] IntelliJ IDEA Ultimate Edition (version 2021.1) • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA 2021.1.2 • Flutter plugin version 57.0.5 • Dart plugin version 211.7665

[√] VS Code (version 1.57.1) • VS Code at C:\Users\ahmed\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.23.0

[√] Connected device (2 available) • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.124 • Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.59

• No issues found!

EP-u-NW commented 3 years ago

Hm very interesting... I'm not even sure if this is a opus_flutter problem or a web_ffi problem. While opus_flutter injects js code to the page using inject_js, this is done with JavaScript code from the asset folder at runtime and should thus not be subject to any minification... You can read more about this process here if you are interessted.

Can you reopen the issue at web_ffi? I will answer it there.

alhamed1 commented 3 years ago

Yes, you're right. I did some debugging and I found out that the type comparison is the problem in types.dart

int sizeOf<T extends NativeType>() {
  if (_isPointerType<T>()) { 
    size = sizeMap[IntPtr];
  } else {
    size = sizeMap[T];
  }
  print('size: $size');
  if (size != null) {
    return size;
  } else {
    throw new ArgumentError('The type $T is not known!');
  }
}

bool _isPointerType<T extends NativeType>() => // needs to address the changes that resulted from minification
    T.toString().startsWith('Pointer<');

bool _isNativeFunctionType<T extends NativeType>() => // here also
    T.toString().startsWith('NativeFunction<');

bool _isVoidType<T extends NativeType>() => T.toString() == 'Void'; // here also

I will reopen the issue in web_ffi