Showing posts with label Flutter. Show all posts
Showing posts with label Flutter. Show all posts

Monday, December 20, 2021

Hello World Program Using Dart 2


Brief About Execution of Dart Code

The execution of Dart code operates in two modes—Just-In-Time (JIT) compilation or Ahead-Of-Time (AOT) compilation: JIT compilation A JIT compilation is where the source code is loaded and compiled to native machine code by the Dart VM on the fly. It is used to run code in the commandline interface or when you are developing a mobile app in order to use features such as debugging and hot reloading. AOT compilation An AOT compilation is where the Dart VM and your code are precompiled and the VM works more like a Dart runtime system, providing a garbage collector and various native methods from the Dart software development kit (SDK) to the application. Dart contributes to Flutter's most famous feature, hot reload, which is based on the Dart JIT compiler, allowing fast interactions with live code swaps.

To Demonstrate The 'Simple Hello World' program of Dart, we only need the Windows CMD

Note: we created the "simple_hello_world.dart" in Visual Studio Code first. (base) C:\Users\Ashish Jain\OneDrive\Desktop>dir Volume in drive C is Windows Volume Serial Number is 8139-90C0 Directory of C:\Users\Ashish Jain\OneDrive\Desktop 12/20/2021 01:48 PM <DIR> . 12/20/2021 01:48 PM <DIR> .. 12/20/2021 01:48 PM 173 simple_hello_world.dart 12/20/2021 01:59 PM 905 write-up.html 11 File(s) 31,664,672 bytes 11 Dir(s) 66,662,928,384 bytes free (base) C:\Users\Ashish Jain\OneDrive\Desktop>type simple_hello_world.dart main() { // the entrypoint of an Dart app var a = 'world'; // declaring and initializing variable print('hello $a'); // call function to print to display output } (base) C:\Users\Ashish Jain\OneDrive\Desktop> (base) C:\Users\Ashish Jain\OneDrive\Desktop>dart simple_hello_world.dart hello world

Yet Another Hello World Program

File: hello_world_with_for_loop.dart (base) C:\Users\Ashish Jain\OneDrive\Desktop>dir Volume in drive C is Windows Volume Serial Number is 8139-90C0 Directory of C:\Users\Ashish Jain\OneDrive\Desktop 12/20/2021 03:46 PM <DIR> . 12/20/2021 03:46 PM <DIR> .. 12/20/2021 01:15 PM 86 hello_world_with_for_loop.dart 14 File(s) 31,774,195 bytes 11 Dir(s) 63,985,053,696 bytes free (base) C:\Users\Ashish Jain\OneDrive\Desktop>type hello_world_with_for_loop.dart void main() { for (int i = 0; i < 5; i++) { print('hello ${i + 1}'); } } (base) C:\Users\Ashish Jain\OneDrive\Desktop>dart hello_world_with_for_loop.dart hello 1 hello 2 hello 3 hello 4 hello 5 (base) C:\Users\Ashish Jain\OneDrive\Desktop>
Tags: Technology,Flutter,

Tuesday, October 13, 2020

Flutter for Android Development (Notes, Oct 2020)


Follow these steps as part of setting up an old project on a new system. Such as in case of taking a project from Ubuntu machine to a Windows machine.

1.1 - Go to SDK Manager
1.2 - Install the required Android SDK
2 - Build.grade changes - Removing unnecessary dependencies
3 - Changes in Gradle.properties to use AndroidX and Jetifier
4 - Flutter Commands To Begin With

Monday, September 21, 2020

Flutter Notes (Week 2, Sep 2020)


Ques: How to fix initialization error for DefaultKotlinSourceSetKt?
  Error: Could not initialize class org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt

Answer:
This error comes on upgrading Android Studio (from October 2019 Release to Sep, 2020 (v4.0.1)) and the SDK Components.

On updating the Kotlin version on Android Studio -> Tools -> Kotlin -> Check For Update.

Then make changes on Kotlin Version as below on build.gradle 

After changing: ext.kotlin_version = '1.3.72' Old value: 1.3.10 Issues appearing in "Build" process logs: 1. Deprecation Warning for 'Android Gradle' plugin: WARNING: API 'variant.getMergeAssets()' is obsolete and has been replaced with 'variant.getMergeAssetsProvider()'. It will be removed in version 5.0 of the Android Gradle plugin. For more information, see https://d.android.com/r/tools/task-configuration-avoidance. To determine what is calling variant.getMergeAssets(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information. WARNING: API 'variantOutput.getProcessResources()' is obsolete and has been replaced with 'variantOutput.getProcessResourcesProvider()'. It will be removed in version 5.0 of the Android Gradle plugin. For more information, see https://d.android.com/r/tools/task-configuration-avoidance. To determine what is calling variantOutput.getProcessResources(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information. 2. > Task :app:compileFlutterBuildDebugArm ╔==== ║ A new version of Flutter is available! ║ ║ To update to the latest version, run "flutter upgrade". ╚==== C:\Users\Ashish Jain>flutter --version Waiting for another flutter command to release the startup lock... Flutter 1.9.1+hotfix.2 • channel stable • https://github.com/flutter/flutter.git Framework • revision 2d2a1ffec9 (1 year, 1 month ago) • 2019-09-06 18:39:49 -0700 Engine • revision b863200c37 Tools • Dart 2.5.0 3. Manifest merger failed : Overlay manifest:package attribute declared at AndroidManifest.xml:2:5-37 value=(com.survival8.survival) has a different value=(com.survival8.one) declared in main manifest at AndroidManifest.xml:2:5-32 Suggestion: remove the overlay declaration at AndroidManifest.xml and place it in the build.gradle: flavorName { applicationId = "com.survival8.survival" }
4. On replacing the entire code from a back-up of code developed on 'Ubuntu': "\home\administrator\flutter" was our path in Ubuntu machine. Error: C:\Users\Ashish Jain\AndroidStudioProjects\survival\android\app\home\administrator\flutter\packages\flutter_tools\gradle\flutter.gradle (The system cannot find the path specified)
We have a "local.properties" file with contents: Path: C:\Users\Ashish Jain\AndroidStudioProjects\survival\android\local.properties Contents from Ubuntu back-up code: ## This file must *NOT* be checked into Version Control Systems, # as it contains information specific to your local configuration. # # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the header note. # Mon Sep 21 19:31:06 IST 2020 flutter.buildMode=release flutter.versionName=1.0.0 flutter.sdk=/home/administrator/flutter sdk.dir=C\:\\Users\\Ashish Jain\\AppData\\Local\\Android\\Sdk flutter.versionCode=1 Here, we need to change the property "flutter.sdk" according to our current system. --> flutter.sdk=E\:\\programfiles\\flutter C:\Users\Ashish Jain\AndroidStudioProjects>flutter upgrade Flutter 1.20.4 • channel stable • https://github.com/flutter/flutter.git Framework • revision fba99f6cf9 (7 days ago) • 2020-09-14 15:32:52 -0700 Engine • revision d1bc06f032 Tools • Dart 2.9.2 Running flutter doctor... Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 1.20.4, on Microsoft Windows [Version 10.0.18363.1082], locale en-US) [!] Android toolchain - develop for Android devices (Android SDK version 29.0.2) X Android license status unknown. Try re-installing or updating your Android SDK Manager. See https://developer.android.com/studio/#downloads or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions. [√] Android Studio (version 4.0) C:\Users\Ashish Jain\AndroidStudioProjects>flutter --version Flutter 1.20.4 • channel stable • https://github.com/flutter/flutter.git Framework • revision fba99f6cf9 (7 days ago) • 2020-09-14 15:32:52 -0700 Engine • revision d1bc06f032 Tools • Dart 2.9.2
5. When opening a project, open the "android" folder and not the parent directory such as "survival" or "survival8".
6. Where to view the Gradle version running:
7. Way to clone 'stable' Flutter GitHub repository: $ git clone -b stable https://github.com/flutter/flutter.git

Sunday, September 20, 2020

Failing to launch Android Virtual Device on Ubuntu in VirtualBox on Windows 10


'Android Virtual Device' fails to run on Ubuntu in VirtualBox on Windows 10:
Your CPU does not support required features (VT-x or SVM).

Message you get on clicking 'Troubleshoot':
If your computer does not support hardware accelerated virtualization. Android Studio provides suggestions: 1. Use a physical device for testing. 2. Develop on a Windows/OSX computer with an Intel processor that supports VT-x and NX. 3. Develop on a Linux computer that supports VT-x or SVM. 4. Use an Android Virtual Device based on an ARM system image. (This is 10X slower than hardware accelerated virtualization.) Our VirtualBox GuestOS setting:
How to enable the "nested vtx/amd-v" in Orable VirtualBox for Windows? In Windows, go to VirtualBox installation folders -> type 'cmd' in the 'address' bar (it will pop up 'cmd' in that folder) -> type VBoxManage modifyvm YourVirtualBoxName --nested-hw-virt on -> enter.
Now it should be ticked. Warning we still get:
Performance Issues 1.
2. AVD never starts beyond this:

Setting up Ubuntu 20.04 for Flutter based Android app development


1.
Install Git.

  $ sudo apt install git


2.
Create a directory where we download the 'flutter':

(base) ashish@ashish-VirtualBox:~/Desktop/ws/programfiles/flutter$ pwd
/home/ashish/Desktop/ws/programfiles/flutter_box 


3.
Download 'flutter':

$ pwd
/home/ashish/Desktop/ws/programfiles/flutter_box 

$ git clone https://github.com/flutter/flutter.git 


4.
Add the flutter tool to your path:

 $export PATH="$PATH:`pwd`/flutter/bin" 
 
OR

Update this in "~/.bashrc" file.

$ nano ~/.bashrc
$ source ~/.bashrc 


5.
Optionally, pre-download development binaries:

The flutter tool downloads platform-specific development binaries as needed. For scenarios where pre-downloading these artifacts is preferable (for example, in hermetic build environments, or with intermittent network availability), iOS and Android binaries can be downloaded ahead of time by running:

$ flutter precache 


6.
Install "Android SDK" from 'Terminal'.

$ sudo apt update && sudo apt install android-sdk 


7. 
Install "Android Studio" from "Ubuntu Software".

8. When you launch 'Android Studio' for the first time, it gives the prompt for 'Import Android Studio Settings':
Set it to "Do not import 'Settings'." 9. It will next launch the 'Android Studio Setup Wizard'.
10. Default JDK location:
11. Next, it downloads SDK components:
12. Prompt for 'Emulator Settings for Hardware Acceleration'
13. Undate Android license status. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/linux#android-setup for more details. $ flutter doctor --android-licenses 14. Launch "Settings" as shown below. Then go to "Plugins".
If we launch installation of 'Flutter' plugin, it automatically prompts for the installation for 'Dart'.
Then, give 'Android Studio' a restart. 15. Installing 'Flutter Extension' in Visual Studio Code. Go to 'Extensions' as shown below and search for 'flutter'.
...
16. Test installation: (base) ashish@ashish-VirtualBox:~/.../flutter_box$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel master, 1.22.0-10.0.pre.264, on Linux, locale en_IN) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [✓] Android Studio (version 4.0) [✓] VS Code (version 1.49.1) [!] Connected device ! No devices available ! Doctor found issues in 1 category. 17. Common Issues that we notice from 'flutter doctor': As of Flutter’s 1.19.0 dev release, the Flutter SDK contains the dart command alongside the flutter command so that you can more easily run Dart command-line programs. Downloading the Flutter SDK also downloads the compatible version of Dart, but if you’ve downloaded the Dart SDK separately, make sure that the Flutter version of dart is first in your path, as the two versions might not be compatible. $ flutter doctor Doctor summary (to see all details, run flutter doctor -v): 17.1. [!] Android toolchain - develop for Android devices (Android SDK version 27.0.1) ✗ Flutter requires Android SDK 29 and the Android BuildTools 28.0.3 To update the Android SDK visit Flutter.dev: Android Setup on Linux for detailed instructions. 17.2. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See Flutter.dev: Android Setup on Linux for more details. 17.3. ✗ Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses 17.4. [!] Android Studio (not installed) 17.5. [!] Android Studio (version 4.0) ✗ Flutter plugin not installed; this adds Flutter specific functionality. 17.6 [!] Android Studio (version 4.0) ✗ Dart plugin not installed; this adds Dart specific functionality. 17.7. [!] VS Code (version 1.49.1) ✗ Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter 17.8. [!] Connected device ! No devices available ! Doctor found issues in 4 categories. Dated: Sep 2020 Ref: https://flutter.dev/docs/get-started/install/linux