How to build release Flutter project using Android Studio - flutter

I cannot build my project using Android Studio. I create project using console, then edit at VSCode. Now I open it at Android Studio and I cannot build release. Why this command Build bundles (green arrow) is not available?

Try to hover on Flutter name in that list or click on arrow button then build apk then create your .apk file
Or run below command
flutter build apk --release
See below image:
See your apk here-> directory:\your_project_name\build\app\outputs\flutter-apk

Open The Android Studio and also open your project.
First you click the build->Flutter->build APK.
Second you get the massage path.
Third you get the build folder then you click the
build->app->outputs->flutter-apk->app-release.apk.
You can see the image for the 3 steps to Build Apk:

Flutter project consist of subprojects:
/MyProject
/iOS - (iOS subproject)
/android - (android subproject)
When I open project "MyProject" I see:
But when I open android submodule/subproject "MyProject/android" I see another options under "Build":
So solution is:
If You want build Android package for Google Play store, You must open in IDE Android submodule, for example solder /MyProject/android
Case with Xcode, iOS and AppStore package looks similar - it is important to open iOS submodule, not whole MyProject.

Related

Where is the 'pubspec.yaml' file? Pub.dev examples won't compile in Android Studio with Flutter Plugin without adding a path, but where is it?

I have successfully installed the Flutter plugin to Android Studio on my Windows10 system, and flutter doctor -v gives me all green check marks.
However, the DART examples from pub.dev fail to compile with the error message that libraries must be added to the file 'pubspec.yaml'.
Where is this file? As shown below, no such file appears in the project hierarchy?
[enter image description here][1]
[1]: https://i.stack.imgur.com/Y5CDd.png
This is a default folder and file structure of a Flutter project. In your case pubspec.yaml file isn't present, which should be there. So I think this is an issue related to build. So just try to rebuild the project, and it should be cured. Just Open terminal on the Project folder and run the following commands.
flutter clean
flutter create <Exactly same project name>
This should rebuilt the project.
If this is a new project and you haven't done anything on the project yet, I will suggest to create a new project using terminal commandline, as according to me commandline with VSCode is the best way to work on flutter (Obviosusly it's based on preference).

Move Root Folder of Flutter Project

When working on a Mac with Flutter in Android Studio (Arctic Fox 2021.3.1 Patch 4 and XCode 13.1 and/or 13.2):
If you move the root folder of your Flutter project using Finder, then open it in Android Studio and run it, the original folder location is still re-written (multiple sub folders with empty contents, usually, but not always).
Also, the moved project will no longer build from within XCode.
This means that if you don't know the final desired location for your project at the time you create it, you will not be able to move it without weird stuff happening.
How can you move a Flutter project that was created with Android Studio without it having weird side-effects?
More info on how to reproduce:
Close all IDEs
Open Android Studio
Using Android Studio, create a new default FLUTTER project using Java as the Android code choice
Using Android Studio, run this project on an Android Emulator
Using Android Studio, run this project on an IOS simulator
Using Android Studio, open the project in XCode (right-click ios folder and select Flutter\Open project in Xcode)
Using XCode, run the project on an IOS simulator
[everything should have worked so far]
Close all IDEs
Using Finder, move the project folder to a new location that is at the same depth as its current folder, but with a different parent folder. Meaning if current location is: [root]/x/y/a/my_project_original, the destination would be: [root]/x/y/b/my_project_copy
delete the original folder and remember where it was
Using Android Studio, open the project from its new location
Using Android Studio, open the project in XCode (right-click ios folder and select Flutter\Open project in Xcode)
Attempt to run on IOS simulator
[observe error - "Command PhaseScriptExecution failed with a nonzero exit code" // "file not found exception"]
Using Finder, check to verify original folder location has NOT been re-written
Using Android Studio, run the project on Android emulator
[observe that original folder has been re-written!]
Here are the steps I follow to move a project's location on my mac :
Close your project on Android Studio (File > Close Project)
Close Android Studio
Move your project to your new location
Open Android Studio
Delete your project from the Recent Projects (on the list of Recent Projects, click on the Settings icon on the right, and "Remove from recent projects")
Click on "Open" and select your project in the new location.
Delete the .idea file and build/ folder
The steps should be the same within XCode (in the main window, remove the old location from your recent projects, and Open the new location)
You can move your Flutter project anywhere, as long as you don't move the files inside the project relative to each other.
A note about pod install: If you are immediately running from Xcode, you need to run pod install inside the ios folder after adding a plugin to your pubspec.yaml. If you run flutter run or use Android Studio to run it, that will run pod install for you automatically. However, you don't have to run pod install after moving the project, I've just tested it.
If you move the root folder of your project using Finder, then open it
in Android Studio and run it, the original folder location is still
re-written (multiple sub folders with empty contents, usually, but not
always).
This only happens if you kept Android Studio open when moving the files. You shouldn't open the old project reference in Android Studio, you should open the project using File > Open....
Also, the moved project will no longer build from within Xcode.
If you provide the errors, that will help us help you.
How can you move a Flutter project that was created with Android Studio without it having weird side-effects?
I have not found any side effects of moving a Flutter project. Quit Android Studio if it is running, and open it using File > Open.... Or if you are in terminal, run (if installed using Jetbrains toolbox) open -a ~/Applications/JetBrains\ Toolbox/Android\ Studio.app/

Android Studio error when opening existing project

I am currently trying to run an existing project in Android Studio ,but when I loaded the project in my android studio ,it gives me error, which is target url does not exist error. How should I fix this problem ,because i just cloned the whole project using the url.
enter image description here
Since i cloned the project,the packages should all be there,but it gives me error for most of the import package lines.
I am not sure if the get dependencies can solve ,but i did not find it or there is another method can solve this problem.
Go to the top menu of the Android Studio and, Build -> Rebuild Project
Maybe your dependencies are not installed
Fire a terminal and type
pub get
Maybe this would solve the problem or try
flutter pub cache repair
first is open your flutter project, and call
flutter clean
flutter doctor
right click on android studio, then open Android studio, this way(not directly by folder)

flutter inspector doesn't work for the app from my github repository

The flutter inspector doesn't work (not showing widgets tree) for my project (it's cloned from github).
To figure out what's wrong in my project, I generated new flutter applications, and the behavior is weird.
When I generate a new flutter application (flutter's default new flutter project) in a NEW directory, flutter inspector works ok.
If I make a new flutter application INSIDE my project directory (let's say myproject/temp), the inspector doesn't show the widgets tree.
If I delete my project directory (myproject), make a directory with the same name (myproject), and generate a new flutter application inside the directory (myproject/temp), then the inspector works ok.
If I make 'myproject' directory manually (mkdir myproject), copy all myproject files to myproject/ (cp myproject_backup/* myproject/), and generate a new flutter application inside myproject/temp, then the inspector doesn't work.
If I make 'myproject' directory manually (mkdir myproject), generate a new flutter application inside myproject/temp, copy all myproject files to myproject/ (cp myproject_backup/* myproject/), then the inspector doesn't work.
Can the other files in the same folder (myproject/*) affect the behavior of the flutter project (esp. inspector)?
What else can go wrong in this case?
Here's my setting:
Flutter: Channel stable, v1.17.1, on Mac OS X 10.15.5
Dart: version 2.8.2
Android SDK version 28.0.3
Android Studio (version 4.0)
Flutter plugin version 46.0.2
Dart plugin version 193.7361
My app is inside bazel WORKSPACE, that was the problem.
If I delete WORKSPACE file, the inspector works fine.

Cannot do new Image Asset in res folder

I want to do a new Image Asset in my res folder in my flutter project, to change the layout of my app icon. However when i right click on the res folder and chose New -> 'Image Asset' is no longer an option in my Android Studio... Anyone who knows how to fix this? I've been able to do it before. I've updated the Flutter plugin, but that didn't make any difference.
I'm new to flutter as well and as part of following the flutter course, ran into the same issue.
The following solution is with android studio version
Android Studio Arctic Fox | 2020.3.1 Patch 3
Build #AI-203.7717.56.2031.7784292, built on October 1, 2021
Runtime version: 11.0.10+0-b96-7281165 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 12.0.1
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 12
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: Dart, io.flutter
I found the 'Image Asset' option by following the below-listed steps
Right-click on the 'res' folder
Hover over 'Flutter' option and click 'Open Android module in Android Studio'
When a pop-up asks 'Where would you like to open the project?', select 'New Window'
Once the project opens in new window, expand the app directory to find 'res' folder.
Right-click on 'res' folder, click 'new' and you'll now see the Image Asset option
I want to clarify these answers, it's all there, but it's too confusing: You must create an images folder in the project. In most of my projects, I would create an assets folder, and then a subfolder of images. This won't work, must be a top level images folder.
Additionally, if you start your project in VS code. You have to start the project in Android Studio. You can always just start a new project, do your icon work and copy the folders over to your actual project.
But TWO things seem to interfere: If you don't have an images folder and if you did anything in VS code. I was guilty of both, and had to unwind both issues.
Start a new project in Android Studio
Create an images folder.
Add it to your pubspec.yaml in assets: Mine would look like this:
assets:
assets/images/
assets/sounds/
assets/
images/
Now you'll be able to right click on the res folder and see new image asset.
Do your icon work.
Copy the res folder over to your actual project.
Want to iterate: I put an image in the top level images folder, but I don't think it even needs that. It is looking for the folder, and you must have it. Somewhere in the code, a top level images folder is a condition to giving the image option.
Starting in Android studio will give the option, but it's greyed out.
Having the images folder is the magic key that opens the hidden door.
Go to menu file > open.... select android folder and click open.
wait until it finished loading then try to right click res folder again.
The Image asset menu will be shown.
discussion on this issue.
https://github.com/flutter/flutter-intellij/issues/3512
open android studio File->Open folder->navigate to your flutter project and select the Android folder. Wait for it to sync, then navigate inside the Android studio folder and find the res folder right click on it and choose New you will see the Image asset studio.
In the flutter project, the option won't be available...You can right-click on the android folder and go to the flutter menu and click the open project in Android Studio Option...Then the android project of your flutter project will be opened as an individual project...There you can use all the android studio's native functionalities.
It was not working for me as well. I cleared the build using flutter clean and the option was available after that.
Right click in res>Flutter>Open Android module in Android Studio
You will be able to see the image asset option after android module has opened in android studio.