Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to execute code removed by dart aot compiler #52874

Closed
milindgoel15 opened this issue Jul 7, 2023 · 7 comments
Closed

Attempt to execute code removed by dart aot compiler #52874

milindgoel15 opened this issue Jul 7, 2023 · 7 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.

Comments

@milindgoel15
Copy link

milindgoel15 commented Jul 7, 2023

When running a release build of the Flutter application, an exception is thrown leading to a blank white screen.

Log:
https://katb.in/ijasupezuwa

realm_services file mentioned in logs:

import 'package:realm/realm.dart';

import '../screens/home/models/note_model.dart';
import '../screens/home/models/todo_model.dart';

class RealmServices {
  late Realm realm;

  RealmServices() {
    realm = getRealm();
  }

  Realm getRealm() {
    final Configuration config;
    config = Configuration.local(
      [
        TodoModel.schema,
        NoteModel.schema,
      ],
      schemaVersion: 2,
    );

    realm = Realm(config);

    return realm;
  }
}
  • Dart SDK Version (dart --version)
    Dart SDK version: 3.0.5 (stable) (Mon Jun 12 18:31:49 2023 +0000) on "windows_x64"

  • Whether you are using Windows, MacOSX, or Linux (if applicable)
    Android

  • Whether you are using Chrome, Safari, Firefox, Edge (if applicable)
    n/a

@vsmenon vsmenon added the area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. label Jul 7, 2023
@vsmenon
Copy link
Member

vsmenon commented Jul 7, 2023

fyi - @alexmarkov - per the log:

Attempt to execute code removed by Dart AOT compiler (TFA)

@milindgoel15
Copy link
Author

Is there any temporary workaround for this issue? Or I should wait for a fix?

I'm not in a rush or anything but if I wanted to build a release build for testing.

@mraleph
Copy link
Member

mraleph commented Jul 10, 2023

Duplicate of #52596

@mraleph mraleph marked this as a duplicate of #52596 Jul 10, 2023
@mraleph mraleph closed this as completed Jul 10, 2023
@mraleph
Copy link
Member

mraleph commented Jul 10, 2023

@milindgoel15 rewrite your code as:

  Realm getRealm() {
    final Configuration config = Configuration.local(
      [/* ... */],
      schemaVersion: 2,
    );

    return Realm(config);
  }

This should fix it.

@milindgoel15
Copy link
Author

  Realm getRealm() {
    final Configuration config = Configuration.local(
      [/* ... */],
      schemaVersion: 2,
    );

    return Realm(config);
  }

So, say for instance, I want to provide user an ability to choose the flexible sync approach instead of local configuration. I was initially doing a check using if else as:

If the user decides to login, the configuration picks up the flexible sync otherwise local which was also breaking due to this dart aot compiler.

Can I still do it? Because we are now declaring the config data directly instead of assigning them later.

Maybe use of late ig.

@milindgoel15
Copy link
Author

This should fix it.

That fixed it. Thanks

@mraleph
Copy link
Member

mraleph commented Jul 10, 2023

@milindgoel15 you can use ternary (or Dart 3 switch expression) or alternatively you can remove the final and make the variable nullable as a temporary workaround:

  Realm getRealm() {
    Configuration? config;
    if (something) {
      config = /* ... */;
    } else {
      config = /* ... */;
    }

    return Realm(config!);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

3 participants