Exception: Gradle build failed to produce an .apk file,the tool couldn't find it - flutter

I used flutter flavor and I can't run but it run from terminal using this type of command:
flutter run --flavor prod -t lib/main_prod.dart
When I run using android studio run button then show this exception, which I write below:
Exception: Gradle build failed to produce an .apk file. It's likely that this file was generated under C:\Users\ranak\StudioProjects\bachelor_flat\build, but the tool couldn't find it.
here is my app-build.gradle file

Click on the dropdown near the run button and select Edit Configurations, then write --flavor prod -t lib/main_prod.dart or anything you want in the Additional run args text field.

Related

Flutter Re-run cmake with a different source directory

When I tried to run Flutter app on windows, it gives an error then says Exited Sigterm. or stmh like this.
the error says;
Re-run cmake with a different source directory
cmake files does not match...
etc.
The Steps that helped me to handle this error are;
open your terminal then write following commands
flutter clean
flutter pub get
flutter run
This will remove you build file and re-create it.
Your problem should have solved now.

flutter: split-debug-info Don't work for web project?

when I use the command on windows build everything is ok:
flutter build windows --split-debug-info=mySoftware/symbols
When I use the same command to web build i get the message:
flutter build web--split-debug-info=profept_client/symbols
**`Could not find an option named "split-debug-info".`**
why I can't run this command o flutter web?

run shell command script in dart

Is it possible to run the terminal command in dart?
I want to run this command using custom command on the terminal.
custom command like this
dart run build-dev(build-dev is a script file)
full command in build-dev file
rm pubspec.lock && flutter clean && flutter pub get && flutter pub upgrade && flutter build apk --flavor dev -t lib/main_dev.dart
Found the answer myself.
install this package.
dart pub global activate flutter_scripts
(if you use mac os, you should setup mac shell)
you can run the same command in Flutter by using the flutter run command. Here's an example of how you can do this:
Open the pubspec.yaml file in your Flutter project.
Add a new script to the scripts section of the file:
scripts:
build-dev: flutter build apk --flavor dev -t lib/main_dev.dart
Run the script using the flutter run command:
flutter_scripts run build-dev
This will execute the flutter build apk command with the specified arguments. You can then run this script anytime by using the flutter run build-dev command.
You're asking for trouble running a dart script in a package that deletes the lock file and runs clean and pub get.
Also, pub get then pub upgrade is redundant. Just run pub upgrade.
Just make this a shell script (or batch file)!

The flutter project has been configured with flavor

The flutter project has been configured with flavor. When I run the project natively from Android, how do I specify the flutter program entry file?
An example to run a flavor:
flutter run --flavor prod -t lib/main_prod.dart
--flavor prod after the --flavor option you need to provide the flavor's name as it is declared.
-t lib/main_prod.dart the -t flag is the entry file target.

JDK installation not found by flutter starter app

I have cloned the flutter repo and installed the Android SDK command-line tools, setting them up in $HOME/Android. I then made flutter aware of the SDK installation by setting $ANDROID_HOME to $HOME/Android. Things seem to have worked out, with <path-to-flutter> doctor finding
Android SDK
my Java JDK 8 installation (openjdk-8-jdk package on Ubuntu 18.04), and
a connected Android phone with USB debugging
I am now trying to follow the test-run instructions for building a first app on the command line. <path-to-flutter> create myapp works and produces a myapp directory. I then try to run the resulting starter app:
cd myapp
~/myapp$ ANDROID_HOME=~/Android JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 <path-to-flutter> run
This results in the following error:
Launching lib/main.dart on ONEPLUS A6013 in debug mode...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
* 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 10s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done 11.0s
Exception: Gradle task assembleDebug failed with exit code 1
I have seen this issue discussed before, but none of those replies seem to address it (in my case, at least). You can see from the command that I am exporting the right $JAVA_HOME, and besides, running
./android/gradlew build
inside the myapp directory does work:
~/myapp$ ./android/gradlew build
> Task :buildEnvironment
------------------------------------------------------------
Root project
------------------------------------------------------------
classpath
No dependencies
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 319ms
1 actionable task: 1 executed
So this seems to be specific to flutter itself somehow, rather than gradle.
It turns out this must have been a path issue. The Flutter starter app builds (and pops up on my device) after inserting the following snippet in a file sourced in my profile (my .bashrc):
# Java
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
# Android
export ANDROID_HOME=${HOME}/Android
export ANDROID_SDK_ROOT=${HOME}/Android
# Flutter
export FLUTTER_HOME=${HOME}/repos/flutter
PATH=${FLUTTER_HOME}/bin:$PATH; export PATH
you can do like this -->
sudo apt-get remove --auto-remove openjdk*
sudo apt-get install openjdk-8-jre
now goto to home and visible your hidden folder by pressing ctrl+h
Now open .bashrc or your .rc
paste these on last
export PATH="$PATH:/snap/bin/flutter/bin"
export PATH="$PATH:/usr/bin/java"
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
export ANDROID_SDK_ROOT=/home/<YOUR USER NAME>/Android/Sdk
then run
source ~/bashrc
flutter doctor -v