Flutter build for web fails with aes_decrypt.dart Error: Not found: 'dart:ffi' import 'dart:ffi' - flutter-web

After adding the syncfusion_flutter_datagrid, printing and pdf packages, When building for web I get the following error:
I have run flutter clean && flutter pub get but it didn't help. I also tried adding ffi to pubspec.yml.
Compiling lib/main.dart for the Web... 16.0s
Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
/root/.pub-cache/hosted/pub.dartlang.org/archive-3.3.3/lib/src/util/aes_decrypt.dart:1:8:
Error: Not found: 'dart:ffi'
import 'dart:ffi';
^
/root/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_datagrid-20.3.56/lib/src/datagrid_widget/widgets/cell_widget.dart:695:19:
Warning: Operand of null-aware operation '!' has type 'OverlayState' which excludes null.
- 'OverlayState' is from 'package:flutter/src/widgets/overlay.dart' ('/usr/local/flutter/packages/flutter/lib/src/widgets/overlay.dart').
Overlay.of(context)!.context.findRenderObject()! as RenderBox;
^
Error: Compilation failed.
Exception: Failed to compile application for the Web.
The command '/bin/sh -c flutter build web' returned a non-zero code: 1
mark#mark-desktop:~/dev/example/cmd/client$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.7, on Ubuntu 22.04.1 LTS 5.15.0-52-generic, locale en_AU.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2021.3)
[✓] VS Code
[✓] Connected device (2 available)
[✓] HTTP Host Availability
• No issues found!
edit: I remove the syncfusion_data_grid but continue to get the same error.

Well.. it's pretty hard to pin-point the exact reason without the specific version for each package used in your project. HOWEVER, it seems like a common issue that occurs whenever a sub-dependency is configures to an old version that causes trouble.
Following this great post it seems that you need to upgrade your packages to avoid this error. Please follow these steps:
run flutter pub upgrade
if the error is not resolved - run flutter pub upgrade --major-versions
if not resolved yet - remove all dependencies (plus - comment all related code) and verify that the project compiles successfully
Needles to say that you should verify that you have proper access to your file system in order to avoid read / write issues due to insufficient permissions

Related

How to solve "target died before we could attach" message in Flutter console?

i am new to android app development, i just started learning flutter and there is so much information to take in , i downloaded a project from github to try and make sense out the things that i only read about online and when i run the app this is what i get :
Screenshot1
Screenshot2
in the red boxes you can see there is a lot of things saying " target died before we could attach " what exactly is this ? is it something to be concerned about ? i tried googling it to see if i find some information about em but i couldn't find anything useful , maybe i was searching it the wrong way ...
Update: After running the "flutter doctor" this is what i got :
C:\src\flutter\flutter>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.22.4, on Microsoft Windows [Version 10.0.19042.631], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
X Android license status unknown.
Run flutter doctor --android-licenses to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[!] Android Studio (version 4.1.0)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.52.0)
X Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (1 available)
! Doctor found issues in 3 categories.
but i am sure that i have installed the flutter and dart plugin
I have no idea what causes this error but this is how I resolved mine.
Confirm that flutter doctor generates no errors.
Uninstall any versions of the application from your emulator.
flutter run
Now you should be okay.
From a console window that has the Flutter directory in the path, run the following command to see if there are any platform dependencies you need to complete the setup:
C:\src\flutter>flutter doctor
This command checks your environment and displays a report of the status of your Flutter installation. Check the output carefully for other software you might need to install or further tasks to perform
source here
# Edit
If the doctor command does not indicate an error, then try to create a new project and copy and paste the classes from the project you downloaded to your new project. Flutter need to download the Gradle, it may be some IDE bug that can be solved by creating a new project

Flutter Secure Storage not working after build in release mode

Everything works fine in debug mode and release on emulator, but reading values from FlutterSecureStorage fails on a physical device. Other functionalities in application work properly, when I comment using FlutterSecureStorage.
After installing .apk file and launching application on a device, it uses FlutterSecureStorage to get information if user is logged in or not, along with other values. I expect null during first run, of course, but storage.read(key) seams to fail before returning any value.
Added backup tags in main/AndroidManifest.xml
<application
...
android:allowBackup="false"
android:fullBackupContent="false">
Added deleting keys on startup
final FlutterSecureStorage storage = FlutterSecureStorage();
Future<void> checkIfUserIsSignedIn() async {
storage.deleteAll();
try{
isUserSignedIn = await storage.read(key: _isLoggedIn);
}
catch (e){
print(e);
}
setState(() {});
}
Tried with FlutterSecureStorage v.3.3.3 and FlutterSecureStorage v.3.2.0, but there was no change.
I checked SDK version of my device (Honor 10) - 29. Also checked on other device (Samsung Galaxy S9+), but the issue also occurs.
Running flutter run --release causes warnings:
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: C:\Users\karo\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_secure_storage-3.2.0\android\src\main\java\com\it_nomads\fluttersecurestorage\FlutterSecureStoragePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
and error:
Installing build\app\outputs\flutter-apk\app.apk... 376ms
Error: ADB exited with exit code 1
Performing Streamed Install
adb: failed to install C:\Users\karo\idom_mobile\build\app\outputs\flutter-apk\app.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.project.idom signatures do not match previously installed version; ignoring!]
Uninstalling old version...
Installing build\app\outputs\flutter-apk\app.apk... 6.9s
but successfully installs application on emulator and everything works as expected.
The problem is when I install application on physical device. To generate .apk I use flutter build apk --release and install using app-release.apk file as stated in build log:
flutter build apk --release
You are building a fat APK that includes binaries for android-arm, android-arm64, android-x64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64,android-x64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 69.9s
√ Built build\app\outputs\flutter-apk\app-release.apk (48.9MB).
My flutter doctor -v
flutter doctor -v
[√] Flutter (Channel dev, 1.24.0-10.2.pre, on Microsoft Windows [Version 10.0.18362.1198], locale en-GB)
• Flutter version 1.24.0-10.2.pre at C:\Users\karo\flutter
• Framework revision 022b333a08 (27 hours ago), 2020-11-18 11:35:09 -0800
• Engine revision 07c1eed46b
• Dart version 2.12.0 (build 2.12.0-29.10.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\karo\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] 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 1.8.0_242-release-1644-b01)
[√] Connected device (1 available)
• Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64 • Android 10 (API 29) (emulator)
• No issues found!
I tried to make sure my project is migrated to AndroidX and got a message: No Usages Found in the Project.
I don't have any more ideas, could you help me?
EDIT
I tried using SharedPreferences as a temporary workaround, but it still didn't work - as I guess, the package was not initialized.
I built my app with flutter build apk --release --no-shrink after reading this thread https://github.com/flutter/flutter/issues/65334.
Then tried flutter build apk --release --no-shrink with the version of my application that uses FlutterSecureStorage and it worked.
Should I really consider it as a valid fix and always build my application this way?
How are you initializing the package? The issue seems to occur while the app runs in the background, A workaround posted in this thread is by registering the plugins on Android's MainActivity - this adds FlutterSecureStoragePlugin.
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
}
}
You can fix this like I did
Check in pubspec.yml
environment:
sdk: ">=2.16.2 <3.0.0"
and
flutter_secure_storage: ^4.2.1
Check in android/app/build.gradle
compileSdkVersion 32
did you add the permission to your manifest file?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Build failed- Flutter

I had to reinstall my windows and so I had to freshly install Android studio, flutter sdk and everything.
After completing all my installations I am unable to run my project. Before upgrading the system my project was working all fine with 0 errors.
Flutter doctor:
C:\Users\Admin>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.18362.959], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
[√] Android Studio (version 4.0)
[√] Connected device (1 available)
• No issues found!
Error:
Launching lib\main.dart on Mobile in debug mode...
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':agora_rtc_engine:extractDebugAnnotations'.
> Could not resolve all files for configuration ':agora_rtc_engine:lintClassPath'.
> Could not download kotlin-compiler.jar (com.android.tools.external.com-intellij:kotlin-compiler:26.6.3)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/external/com-intellij/kotlin-compiler/26.6.3/kotlin-compiler-26.6.3.jar'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/external/com-intellij/kotlin-compiler/26.6.3/kotlin-compiler-26.6.3.jar'.
> dl.google.com
> Could not download uast.jar (com.android.tools.external.org-jetbrains:uast:26.6.3)
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/external/org-jetbrains/uast/26.6.3/uast-26.6.3.jar'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/external/org-jetbrains/uast/26.6.3/uast-26.6.3.jar'.
> dl.google.com
> Could not download groovy-all.jar (org.codehaus.groovy:groovy-all:2.4.15)
> Could not get resource 'https://jcenter.bintray.com/org/codehaus/groovy/groovy-all/2.4.15/groovy-all-2.4.15.jar'.
> Could not GET 'https://jcenter.bintray.com/org/codehaus/groovy/groovy-all/2.4.15/groovy-all-2.4.15.jar'.
> jcenter.bintray.com
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 46s
Exception: Gradle task assembleDebug failed with exit code 1
This is the first time I am moving my project from my original system to this new one.
I don't have enough reputation to comment so I will write it as an answer. Since it is the first time running the app, make sure you have an internet connection so it can download the required files.
Solution:
As of now what I have done is the following:
agora_rtc_engine that was showing up as error I have removed it. (I will be re-adding this package as this is required for my app)
java jdk download i have added I was getting error on keytool to generate SHA1 Key Fingerprint.
I updated my SHA1 Key Fingerprint in Firebase. I have to do this as I was getting error when login in using Google sign-in.
Now my App is working fine with no errors.
This might not be the correct solution for the issue, so feel free to give your suggestion on the above error that I had faced.

Can not turn on non-nullable feature in an existing flutter project in Android Studio

I have an existing project in Flutter in Android studio 4.0. I'm trying to migrate it to the dev channel with non-nullable feature turned on by default. What I did:
Updated the SDK requirement in pubspec.yaml:
environment:
sdk: ">=2.9.0-14.0.dev <3.0.0"
Run pub get and pub upgrade:
> flutter --version
Flutter 1.20.0-3.0.pre • channel dev • https://github.com/flutter/flutter.git
Framework • revision 0af027f805 (30 hours ago) • 2020-07-04 12:19:20 -0700
Engine • revision a751393804
Tools • Dart 2.9.0 (build 2.9.0-20.0.dev 22da8934ac)
Created the analysis_options.yaml file with the following content:
analyzer:
enable-experiment:
- non-nullable
I run this command:
> dart --enable-experiment=non-nullable
Usage: dart [<vm-flags>] <dart-script-file> [<script-arguments>]
Executes the Dart script <dart-script-file> with the given list of <script-arguments>.
Common VM flags:
--enable-asserts
Enable assert statements.
--help or -h
Display this message (add -v or --verbose for information about
all VM options).
--packages=<path>
Where to find a package spec file.
--observe[=<port>[/<bind-address>]]
The observe flag is a convenience flag used to run a program with a
set of options which are often useful for debugging under Observatory.
These options are currently:
--enable-vm-service[=<port>[/<bind-address>]]
--pause-isolates-on-exit
--pause-isolates-on-unhandled-exceptions
--warn-on-pause-with-no-debugger
This set is subject to change.
Please see these options (--help --verbose) for further documentation.
--write-service-info=<file_uri>
Outputs information necessary to connect to the VM service to the
specified file in JSON format. Useful for clients which are unable to
listen to stdout for the Observatory listening message.
--snapshot-kind=<snapshot_kind>
--snapshot=<file_name>
These snapshot options are used to generate a snapshot of the loaded
Dart script:
<snapshot-kind> controls the kind of snapshot, it could be
kernel(default) or app-jit
<file_name> specifies the file into which the snapshot is written
--version
Print the SDK version.
But the result is nothing. When I run the project from IDE I get the following error:
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...
lib/ui/test.dart:21:6: Error: This requires the 'non-nullable' language feature to be enabled.
Try updating your pubspec.yaml to set the minimum SDK constraint to 2.9 or higher, and running 'pub get'.
int? v = 0;
^
I didn't found any clear official instructions on this case.
What I'm doing wrong?
Null-safety has been a feature of Flutter ever since its stable release on Flutter 2. Update the environment config to sdk: ">=2.12.0 <3.0.0", run flutter clean and flutter pub get to refresh the project and have null-safety support.

Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'. problem on flutter

FAILURE: Build failed with an exception.
What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
Failed to install the following Android SDK packages as some licences have not been accepted.
build-tools;28.0.3 Android SDK Build-Tools 28.0.3
platforms;android-28 Android SDK Platform 28
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html
Using Android SDK: C:\Users\emre\AppData\Local\Android\sdk
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 11s
FAILURE: Build failed with an exception.
What went wrong:
Could not update C:\Users\emre.gradle\caches\5.6.2\file-changes\last-build.bin
C:\Users\emre.gradle\caches\5.6.2\file-changes\last-build.bin (Access is denied)
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 11s
Exception: Gradle task assembleDebug failed with exit code 1
Apparently you should accept the license,so in your command promp:
cd /d "%ANDROID_SDK_ROOT%/tools/bin"
and then
sdkmanager --licenses
just accept the license and the error should goes away.
Here is the main problem
Failed to install the following Android SDK packages as some licenses have not been accepted. build-tools;28.0.3 Android SDK Build-Tools 28.0.3 platforms;android-28 Android SDK Platform 28
As the error suggests, first accept all licenses by running the following command
flutter doctor --android-licenses
next head over to https://androidsdkmanager.azurewebsites.net/Buildtools and download the build tool that corresponds to the one you are missing in this case 28.0.3 After downloading extract the zip file into C:\Android\Sdk\build-tools\28.0.3 if you are on windows and /Library/Android/sdk/build-tools/28.0.3 if you are on mac
finally, download the missing Android SDK platform 28 from https://androidsdkmanager.azurewebsites.net/SDKPlatform and unzip it into /Library/Android/sdk/platforms/android-28 if you are on mac or C:\Android\Sdk\platforms\android-28 if you are on windows
Run your project (flutter run) and enjoy
Try running flutter doctor on cmd. If it shows:
[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.19042.685], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
X Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 4.1.0)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.52.0)
X Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (0 available)
Then run flutter doctor --android-licenses,
and accept all the license agreement. The problem must be solved then.
go setting
android SDK
SDK Tools
and then
click show package details
and Android SDK Build-Tools
Download 28.0.3
Apply and ok :)
In my own case, Deleting .gradle folder solved the problem. Just head-on into your usual project dir and navigate into android and you'd find .gradle folder waving a hand in there. I hope this helps somebody out there. But make sure you have done
flutter doctor --andriod-licences
Don't do anything, like changing the SDK path or updating tools.
At first, what you should try to do is this:
Remove your physical device from your machine which is connected via USB and instead of the physical device, run your application on a browser (I suggest Chrome) and if there is no other issue then you will find the error will have been tackled. So I am saying that the problem is neither in the path nor in the software or code. Please try this suggestion first, because I wasted a full day trying to tackle this problem!
We just need to install proper Android version manually
Go To SDK Manager
Android SDK
Uncheck Installed Version
Manually Install Android version which it tried and throwing error for(see in error message)
Apply and OK
Restart
It worked for me.

Resources