Flutter: Android build for deployment - android-studio

How can I create/prepare Android build for deployment on Appstore, using Android Studio? (I've developer account singed app and keys/credential)
What are step and checklist, required to create Android deployment build for flutter project

They have provided all the steps over here
Preparing an Android App for Release.
And for project You can set all common settings in pubspec.yaml file.

To build an android release of your project.
1. Using the GUI (AndroidStudio)
As shown in the image below, in your Android Studio action bar click on build and then select flutter and choose the type of build you want;
Build Apk
Well, for example when you want to test your app outside of google play store.
Build App bundle
Recommended when you want to publish your app on playstore
2. Using the CLI (Terminal, Cmd )
Open the terminal and navigate to the root folder of your project and then tape the following command;
flutter build apk
or
flutter build appbundle
After the build you'll see a message like this :
Running Gradle task 'assembleRelease'... 191.3s
✓ Built build/app/outputs/flutter-apk/app-release.apk (32.1MB).
This means everything is fine, so go to the build folder in your project's root folder to access your final app file.
For more details, Please use the official documentation guidelines : https://docs.flutter.dev/deployment/android.

Related

Android studio is giving the following error when I am trying to build a ionic project "Gradle sync failed: Sync failed: reason unknown"

I am trying to build a ionic project in Android studio on Ubuntu 20.04 . I am using the command ionic capacitor build then android studio opens up as expected then it shows this error Gradle sync failed: Sync failed: reason unknown. I am unable find a solution for this particular gradle sync error. I have reinstalled Ubuntu and other things but still the problem persists.
In my case, a fresh install of Android Studio resulted in Android 31 being the only SDK available but the project was targeting Android 30. I went to Tools > SDK Manager and made sure the appropriate version of Android SDK was installed and available. After restarting, and allowing the gradle sync to complete I was able to build/run the app on a virtual device, etc.
Here is what I found
This is the screenshot thanks for helping.
Capacitor lets you manage your own Android project. Like any IDE-backed project, sometimes things get so out of sync that the only solution is to rebuild the project.
To do this, follow these steps:
Copy any source code you created (such as Java files in app/android/src, manifest files, or resource files) into a safe location outside of app/android.
Next, make sure you are running an updated version of the Capacitor CLI:
npm install #capacitor/cli#latest
Remove the android directory:
rm -rf android/
Re-create the Android app from Capacitor:
npx cap add android
Copy your saved source files back into the project.
Check the error log. You should find something like "Module: 'mobile' platform 'android-30' not found" or something similar. Click Tools > SDK Manager and download the appropriate Android SDK Platform package.
on top right you will see option to view log file upon clicking there you will redirect to file manager and open idea file there
example :
open idea file and scroll down you will see actual issue.
In my case android sdk 31 was not installed.
I installed android sdk 31 from File>Settings>Apprearance and behaviour>system settings>android sdk and install required android sdk and rebuild the project.
accord to my observation in most cases you get this error because you have not required sdk installed in your system.

How can I build the apk from android studio from flutter

now I'm making an app using flutter and trying to upload the app as internal test on Google play store. I saw people asking how to do it, but could not figure it out...
On the official document, it says "Build > Build > Generate Signed Bundle/APK" and I can generate APK, but I don't see the "Generate Signed Bundle/APK".
When I select "Build APK" in the picture above, it gives me the message like
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'...
27.9s ✓ Built build/app/outputs/apk/release/app-release.apk (19.2MB). Process finished with exit code 0
Also, I saw this chat (How to build signed apk from Android Studio for Flutter), but I cannot see "open android module in android studio"
Even when I opened the android project with different window, I cannot see the option as well..
it will be really helpful if someone can teach me how to generate the APK from my current situation...
Thank you so much..
The reason why Open Android module in Android Studio is missing under Tools > Flutter is likely because you're using an older version of Flutter DevTools on Android Studio. You can run flutter pub global activate devtools on the Terminal to update the DevTools installed on the machine as mentioned on this guide.
to build apk use this line in terminal
flutter build apk --release --no-sound-null-safety

Flutter in Android Studio: Build Bundle/APK greyed out

I installed Flutter and Android Studio following this link here:
https://flutter.dev/docs/get-started/editor
I've been coding in flutter for two months now and can run my app in simulator or on a connected device no problem.
But when I try to actually build an apk via "Build" --> "Build Bundle(s) / APK", this option is greyed out.
Android Studio: 3.3.2
You can't build apk using Build option in Android Studio if you are running your Flutter project.
There are 2 solutions to build it.
In terminal, write flutter build apk (this will build apk for release version not the debug version)
Open your module in Android Studio and you can use Build option of the Android studio to build the debug apk.
For option 2, you can go to build.gradle file and you should see an option in Android Studio asking you to open the module separately (see the screenshot) Tap on this option and you can then build your apk in both debug and release mode.
I realize this might have already been answered, but I have another solution to this issue. I was having the same problem after modifying my pubspec.yaml file, so after trying to build within terminal nothing would happen. Apparently, you have to open the .yaml file within Android Studio from your project directory in order to for AS to realize that there's been a change to the file. After I opened the file from the project folder, the option for Build > flutter > Build Bundle(s) /APK > Build App Bundle finally reappeared again. Just sharing my experience and hope it can help someone else who may come across this rather strange issue.
Reopen the project from your projects directory, not from recent projects option. This solved for me
Please follow these steps:-
Go To Project Structure>Project>NOSDK
Change NOSDK to the latest
ANDROID API PLATFORM
Then go to MODULE and DO THE SAME

Cannot create flutter project or run flutter project in Android studio. (flutter works fine)

I'm getting into flutter so I followed the install doc on the website and had no issue, installed the flutter and dart plug-ins on both Android Studio and Intelli J. The flutter doctor -v command results in the following
But yet when I try to create a new flutter project in Android Studio a folder is created with the project name but it is empty and I get the following in the event button on the welcome screen.
Error creating project
Flutter create command was unsuccessful
So I decided to create the project manually in gitbash where the create command worked perfectly.
I opened the project in Android Studio and discovered another problem even with the emulator running or phone attached the devices section of the run ribbon displays no device and always says loading in the dropdown when clicked.
So again I opened gitbash and in the project root folder type flutter run and the default flutter test app appeared on the emulator.
In Summary, Android studio can open but not create the project nor can it run it but the project can be run from gitbash on the emulator I launched from Android studio.
BTW: IntelliJ has a similar result when creating a project.
I have no idea what was causing the issue but a fresh install of Git seems to have resolved the issues.

Flutter How to make release version in Android Studio?

By default Android Studio use debug mode when building Flutter application. You can build the release version with the command line, see How to optimize the Flutter App size?
flutter build apk --release
Now: how to configure Android Studio to do the same, when I run the application (Shift+F10)? I can't find this setting...
You have to edit the run configuration:
Open the run configuration:
Add the --release flag:
Note that using the --release flag is not supported when you build with the Android Emulator.
In Android Studio , click on :
> Run
> Flutter Run 'main.dart' in Release Mode
flutter build appbundle --release --build-name=1.1.1 --build-number=3
Or you can run that in your Terminal, Remember to change build name and build number to corresponding values of your release app versioning.
as the green play button in toolbar runs the debug mode, i switched it to release mode via:
Right click Play Icon in toolbar -> Customize Toolbar
click "+", chose Add Action
chose "Plugins/Flutter/Run in Flutter release mode"
Delete the old Play button by selecting it and click "-"
The best way to make your apk for release mode is that open the project -> click on the android folder then make your apk as same as generated application build in android using your .jks key and alias password and name. this is the correct way for making apk in flutter.

Resources