【问题标题】:When Using a release apk some code has been removed by Dart AOT Compiler (TFA)当使用发布 apk 时,Dart AOT 编译器 (TFA) 删除了一些代码
【发布时间】:2020-01-25 12:46:17
【问题描述】:

我想给一些朋友一个我的项目的 apk 版本来测试它。 在我的 IDE 上,我的项目运行良好,可能存在一些错误,但主要概念是可行的。

他们报告了一些在我这边没有发生的错误,所以我尝试了 release apk,当我触发 some specifics methods 时出现此错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Attempt to execute code removed by Dart AOT
compiler (TFA)

this is the error message

触发此错误的方法有:

Future askFriends(String friendName) async {
    print("Send FRIENDS Request");
    print(friendName);
    await _fs
        .collection("Users")
        .document(await pbd.getEmail(friendName))
        .collection("FriendsRequest")
        .document(await pbd.getUserName())
        .setData({
      "profilPicture": await pbd.getProfilePicture(),
      "friendName": await pbd.getUserName(),
      "friendEmail": currentUserEmail,
    });
  }

void acceptFriends(String friendName, String profilPicture) async {
    var reference = randomAlphaNumeric(20);
    String friendEmail = await pbd.getEmail(friendName);
    String userName = await pbd.getUserName();
    print("ADD FRIENDS");
    await _fs
        .collection("Users")
        .document(currentUserEmail)
        .collection("FriendsRequest")
        .document(friendName)
        .delete();
    await _fs
        .collection("Users")
        .document(friendEmail)
        .collection("Friends")
        .document(userName)
        .setData({
      "profilPicture": await pbd.getProfilePicture(),
      "friendName": userName,
      "friendEmail": currentUserEmail,
      "chatReference": reference,
    });
    await _fs
        .collection("Users")
        .document(currentUserEmail)
        .collection("Friends")
        .document(friendName)
        .setData({
      "profilPicture": profilPicture,
      "friendName": friendName,
      "friendEmail": friendEmail,
      "chatReference": reference,
    });
    _fs.collection("PrivateChat").document(reference).setData({
      "users": [userName, friendName]
    });
    _fs.collection("Users").document(currentUserEmail).updateData({
      "friends": await pbd.getUserFriendsNumber(currentUserEmail) + 1,
    });
    _fs.collection("Users").document(friendEmail).updateData({
      "friends": await pbd.getUserFriendsNumber(friendEmail) + 1,
    });
  }

同样在运行“Flutter run --release -v”时 关于它只返回的 AOT:

c:\src\flutter\bin\cache\artifacts\engine\common\flutter_patched_sdk_product/ --target=flutter -Ddart.developer.causal_async_stacks=true
-Ddart.vm.profile=false -Ddart.vm.product=true --bytecode-options=source-positions --aot --tfa --packages D:\Willy\myApp\Komeet\.packages
--output-dill D:\Willy\myApp\Komeet\.dart_tool\flutter_build\605851d98f347f3bc8bcbe0b131320ff\app.dill --depfile
D:\Willy\myApp\Komeet\.dart_tool\flutter_build\605851d98f347f3bc8bcbe0b131320ff\kernel_snapshot.d package:Komeet/main.dart
[+15101 ms] [+15122 ms] kernel_snapshot: Complete
[ +198 ms] [ +266 ms] invalidated build due to missing files:
c:\src\flutter\bin\cache\artifacts\engine\android-arm64-release\windows-x64\gen_snapshot
[ +600 ms] [ +509 ms] android_aot_release_android-arm64: Starting due to {InvalidatedReason.inputChanged, InvalidatedReason.inputMissing}
[   +1 ms] [   +6 ms] executing: c:\src\flutter\bin\cache\artifacts\engine\android-arm64-release\windows-x64\gen_snapshot
--causal_async_stacks --deterministic --snapshot_kind=app-aot-elf
--elf=D:\Willy\myApp\Komeet\.dart_tool\flutter_build\605851d98f347f3bc8bcbe0b131320ff\arm64-v8a\app.so --strip
D:\Willy\myApp\Komeet\.dart_tool\flutter_build\605851d98f347f3bc8bcbe0b131320ff\app.dill
[   +1 ms] [        ] aot_android_asset_bundle: Starting due to {InvalidatedReason.inputChanged}
[ +197 ms] [ +231 ms] aot_android_asset_bundle: Complete
[+10601 ms] [+10568 ms] android_aot_release_android-arm64: Complete
[ +198 ms] [ +245 ms] android_aot_bundle_release_android-arm64: Starting due to {InvalidatedReason.inputChanged}
[ +101 ms] [  +59 ms] android_aot_bundle_release_android-arm64: Complete
[        ] [  +82 ms] Persisting file store
[  +99 ms] [  +65 ms] Done persisting file store
[   +1 ms] [   +3 ms] build succeeded.

在 firestore 上写入 read 不是问题,因为 apk 中使用的许多方法都使用 Cloud Firestore 并且完全可以。

Flutter doctor

My Pubspec.yaml

Build.grade[APP-level]

Build.grade[Project-level]

我在网上只发现了一个类似的问题: Attempt to execute code removed by Dart AOT compiler (TFA), how to troubleshoot this issue

所以我尝试删除构建目录,flutter clean,flutter pub缓存修复,重新创建一个新的flutter项目,导入我项目的所有组件。改变flutter的通道。

另外写“Flutter clean”给这个警告。

Failed to remove build. A program may still be using a file in the directory or the directory itself. To find and stop such a program, see:
https://superuser.com/questions/1333118/cant-delete-empty-folder-because-it-is-used

我已按照说明进行操作,但没有任何改变。

谢谢你帮助我。

【问题讨论】:

    标签: android firebase flutter dart google-cloud-firestore


    【解决方案1】:

    好的,所以我通过以下方式解决了这个问题:

    -将颤振通道更改为稳定

    -更改内部版本号

    -更改具体方法:

    似乎(cloud firestore 有一些问题(与 IDE 上的项目没有提供相同的结果)。

    cf : https://github.com/FirebaseExtended/flutterfire/issues/1857

    之前的方法:

    Future askFriends(String friendName) async {
        print("Send FRIENDS Request");
        print(friendName);
        await _fs
            .collection("Users")
            .document(await pbd.getEmail(friendName))
            .collection("FriendsRequest")
            .document(await pbd.getUserName())
            .setData({
          "profilPicture": await pbd.getProfilePicture(),
          "friendName": await pbd.getUserName(),
          "friendEmail": currentUserEmail,
        });
      }
    
    void acceptFriends(String friendName, String profilPicture) async {
        var reference = randomAlphaNumeric(20);
        String friendEmail = await pbd.getEmail(friendName);
        String userName = await pbd.getUserName();
        print("ADD FRIENDS");
        await _fs
            .collection("Users")
            .document(currentUserEmail)
            .collection("FriendsRequest")
            .document(friendName)
            .delete();
        await _fs
            .collection("Users")
            .document(friendEmail)
            .collection("Friends")
            .document(userName)
            .setData({
          "profilPicture": await pbd.getProfilePicture(),
          "friendName": userName,
          "friendEmail": currentUserEmail,
          "chatReference": reference,
        });
        await _fs
            .collection("Users")
            .document(currentUserEmail)
            .collection("Friends")
            .document(friendName)
            .setData({
          "profilPicture": profilPicture,
          "friendName": friendName,
          "friendEmail": friendEmail,
          "chatReference": reference,
        });
        _fs.collection("PrivateChat").document(reference).setData({
          "users": [userName, friendName]
        });
        _fs.collection("Users").document(currentUserEmail).updateData({
          "friends": await pbd.getUserFriendsNumber(currentUserEmail) + 1,
        });
        _fs.collection("Users").document(friendEmail).updateData({
          "friends": await pbd.getUserFriendsNumber(friendEmail) + 1,
        });
      }
    

    现在的方法:

    Future askFriends(String friendName) async {
        print("Send FRIENDS Request");
        String userName = await pbd.getUserName();
        String friendEmail = await pbd.getEmail(friendName);
        String profilPicture = await pbd.getProfilePicture();
        print(friendName);
        await _fs
            .collection("Users")
            .document(friendEmail)
            .collection("FriendsRequest")
            .document(userName)
            .setData({
          "profilPicture": profilPicture,
          "friendName": userName,
          "friendEmail": currentUserEmail,
        });
      }
    
    void acceptFriends(String friendName, String profilPicture) async {
        var reference = randomAlphaNumeric(20);
        String friendEmail = await pbd.getEmail(friendName);
        String userName = await pbd.getUserName();
        String userProfilPicture = await pbd.getProfilePicture();
        int userFriends = await pbd.getUserFriendsNumber(currentUserEmail);
        int friendFriends = await pbd.getUserFriendsNumber(friendEmail);
        print("ADD FRIENDS");
        await _fs
            .collection("Users")
            .document(currentUserEmail)
            .collection("FriendsRequest")
            .document(friendName)
            .delete();
        await _fs
            .collection("Users")
            .document(friendEmail)
            .collection("Friends")
            .document(userName)
            .setData({
          "profilPicture": userProfilPicture,
          "friendName": userName,
          "friendEmail": currentUserEmail,
          "chatReference": reference,
        });
        await _fs
            .collection("Users")
            .document(currentUserEmail)
            .collection("Friends")
            .document(friendName)
            .setData({
          "profilPicture": profilPicture,
          "friendName": friendName,
          "friendEmail": friendEmail,
          "chatReference": reference,
        });
        _fs.collection("PrivateChat").document(reference).setData({
          "users": [userName, friendName]
        });
        _fs.collection("Users").document(currentUserEmail).updateData({
          "friends": userFriends + 1,
        });
        _fs.collection("Users").document(friendEmail).updateData({
          "friends": friendFriends + 1,
        });
      }
    

    【讨论】:

      猜你喜欢
      • 2019-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-15
      相关资源
      最近更新 更多