why the flutter multi entry point did not work as expect - flutter

I want to using entry-point in my flutter 2.10.3 project, so I tried to write a demo file like this:
void main() {
print("main");
}
#pragma('vm:entry-point')
void entryPoint() {
print("entry-point");
}
when I run this project, it print the main but did not print the entry-point. why the entry-point did not work? the log output like this:
Launching lib/main.dart on iPhone Xʀ in debug mode...
Running Xcode build...
Xcode build done. 19.8s
Debug service listening on ws://127.0.0.1:64706/lkdcvnIiXyQ=/ws
Syncing files to device iPhone Xʀ...
flutter: main

you must attach enterpoint method into flutter engine by java and kotlin or swift (write native code) also
follow this article
https://medium.com/#vad.pinchuk/multiple-entry-android-application-with-flutter-or-alternative-ways-to-restrict-access-to-1260e097ef9f

Related

Flutter macOS app: Unable to find executable to run

I have an app that runs perfectly on the iPhone simulator and Chrome. However, when I try to run it as native macOS app, it fails with the below error dump. I tried running flutter clean but no luck. Can anyone please help me with it? Do let me know if I can share any files that can help debug this issue.
% flutter run -d macos
Launching lib/main.dart on macOS in debug mode...
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:x86_64, id:XYZ-ABC }
{ platform:macOS, name:Any Mac }
Building macOS application...
Unable to find app name. /location/myApp/macos/Flutter/ephemeral/.app_file
name does not exist
Unable to find executable to run
Error launching application on macOS.
Try recreating your macos directory. For example, by running the following bash script from your top-level Flutter project directory.
# Archive macos directory just in-case you want to undo later
mv macos ~/Desktop/
# Recreate macos directory from scratch
flutter create --platforms=macos .
# Try again to run the app on macos
flutter run -d macos

How do you compile a flutter application?

I'm seeing that I can introduce a compilation error in my dart code but flutter build ios will still successfully run. If I flutter run -d [my-simulator] the compile error will immediately be presented in a red screen on the simulator but I can't currently easily do this in a CI type check.
Is there are cli command I can run to ensure that all of the dart code is free of compile errors?
You can run dart analyze or flutter analyze commands.
More info

Flutter audio_service plugin: Error: JS interop class 'MediaMetadata' conflicts with natively supported class 'MediaMetadata' in 'dart:html'

I'm making a Flutter app that uses the audio_service plugin. It works on Android, iOS and macOS. However when I run it on the web with Chrome I get the following error:
Launching lib/main.dart on Chrome in debug mode...
lib/main.dart:1
../../../../.pub-cache/hosted/pub.dartlang.org/audio_service-0.16.1/lib/js/media_metadata.dart:7:7: Error: JS interop class 'MediaMetadata' conflicts with natively supported class 'MediaMetadata' in 'dart:html'.
class MediaMetadata {
^
Failed to compile application.
How do I work around this error before the issue is solved?
Instead of running your app from the IDE, run it from the command line:
flutter run -d chrome
This worked for me and was also reported to work here.

How can I run release build of my Flutter app on Simulator

I need to take screenshots of my Flutter application across various devices. Since I do not have a variety of physical devices, I need to use the Simulator. However, I cannot figure out how to run my app in non-debug mode -- I always see the "Debug" banner in the top right corner. How can I run a Release build in the iOS Simulator?
When I try: flutter run --release, it says, "Release mode is not supported for emulators."
When I try: flutter install, it says:
[ +108 ms] An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
[ +12 ms] "flutter install" took 4,601ms.
Install failed
Alternatively, can I run a debug build without showing the Debug banner?
You won't be able to run release mode on simulator as it only runs on actual device.
However you can remove the debug banner by passing debugShowCheckedModeBanner:false in your MaterialApp()
MaterialApp(
debugShowCheckedModeBanner:false,
home:...
)
The command flutter run --release compiles to release mode.
To remove "debug banner" you can use debugShowCheckedModeBanner property of MaterialApp() widget. If you set this property to false , banner will be disappeared.
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
No, You can't run release build on Emulator. You need a actual device to run release build and ios devices won't support release build.
If you want to remove the debug banner from your app,
Add this line in your MaterialApp
debugShowCheckedModeBanner:false,
To run release build on android devices
flutter run --release
To get release build on your storage
flutter build apk --release
This will generate a release build, If you want to get a normal build run below command
flutter run
If you want to get ios build you should run this command ( you can't run this command on Windows and LINUX computers, You need a MAC system for get ios build )
flutter build ios
I hope this will help someone who new to flutter
The command flutter run --release compiles to release mode.
check the official doc for Flutter's build modes
Running flutter run --release worked for me even on the emulator and also I received FCM notification.
run flutter clean
enable android:debuggable="true" in manifest
flutter build --release
it works for me in emulator pixel 3 and real device

How to create a Flutter plugin that works in another Flutter project?

I have a Flutter plugin successfully running on my newly created Flutter-plugin project. And both worlds, iOS and Android, are able to run the example/lib/main.dart example-code of this Flutter-plugin successfully.
However, once I try to use the plugin in another Flutter project, that's when things crash.
So far, I have tried two ways of how to integrate my self-written plugin into another Flutter project:
Inside my Flutter project (the one I try to use the plugin inside), I go to the pubspec.yaml file and I write:
I tried ...local path integration:
dependencies:
flutter:
sdk: flutter
my_plugin_name:
path: ../../../Flutter_plugins/my_plugin_name/
or I tried ...remote integration:
dependencies:
flutter:
sdk: flutter
my_plugin_name:
git:
url: https://github.com/XXXX/my_plugin_name.git
Both integrations work fine and VSCode seem to import the plugin correctly !
BUT THIS IS WHERE THINGS CRASH!! AS SOON AS I ADD ANYTHING TO THE dependencies, THAT IS WHEN THINGS CRASH AFTERWARDS.
To test if it works, I open my Flutter project and I go to lib/main.dart:
And inside lib/main.dart of the project I want to integrate the plugin into, I write pretty much the same as was written in the plugin-example folder of the plugin-project (see code further down).
Or in other words, I try to run exactly the same code that was given by the plugin-example folder, but this time inside my other Flutter project having the plugin imported.
I therefore paste the example-code into my lib/main.dart file of my Flutter project.
Inside main.dart, I add the following imports:
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:my_plugin_name/my_plugin_name.dart';
.
And the code pasted into main.dart:
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
#override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await MyPluginNameClass.getVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('$_platformVersion\n'),
),
),
);
}
}
The compiler does not give me any error or warning at this point. All seems fine.
HOWEVER, IF I BUILD AND RUN, I GET ERROR EXCEPTIONS FOR BOTH WORLDS, IOS AND ANDROID - WHY ?????
On iOS, the error messages are:
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/KZLinkedConsole.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ColorSenseRainbow.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.179 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/BBUDebuggerTuckAway.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2018-12-23 14:32:52.180 xcodebuild[56661:1181076] [MT] PluginLoading: Required plug-in compatibility UUID D76765677-CB11-4D25-A34B-E33DB5A7C231 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET sqflite OF PROJECT Pods WITH CONFIGURATION Debug ===
/Users/user/Documents/flutter/.pub-cache/git/my_plugin_name-5cc22b5c6d2345ba1ab23a44324b222c68d24ab4/ios/Classes/MyPluginName.m:2:9: fatal error: 'my_plugin_name/my_plugin_name-Swift.h' file not found
#import < my_plugin_name/my_plugin_name-Swift.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Could not build the application for the simulator.
Error launching application on iPhone XS.
Exited (sigterm)
(...I already tried flutter clean or pod update as was mentioned in other stackoverflow entries - but no change on the error...)
On Android, the error messages are:
Launching lib/main.dart on Android SDK built for x86 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:packageDebug'.
> Execution of compression failed.
* 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 25s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
Does anybody have any clue on what to do here ?
What do I miss when integrating a local or remote Flutter-plugin ?
Turns out that not the plugin-adding is the problem!
It is rather my large asset that I have inside the Flutter app that causes the exception.
And it must be more or less a coincidence that my Flutter app crashes from the moment I add the plugin to my app. It was misleading. (I therefore assume that the exception might have happened as well - later when I build-up my Flutter app and add more code. It might be a memory issue of some sort...or you tell me!)
As soon as I remove my large asset (665 MB), the plugin integration works smoothly without any exception.
The question shifts tough to another StackOverflow question: How to integrate a large asset in my Flutter app
And this query can be closed.