I'm new to flutter. I just created a new project in flutter and have not even altered the code.
And when I run the code I get the following error.
Launching lib\main.dart on SM A750F in debug mode...
Gradle task assembleDebug failed with exit code -1
Exited (sigterm)
I have no idea how to fix this, searched a number of ways
When I run flutter doctor I get this error,
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/setup/#android-setup for detailed instructions.
I dont know if this has got anything to do with the error above.
build.gradle(app)
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.dev.teamo"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
Thanks in advance
You need to accept the licenes from Android to run the app:
run:
flutter doctor --android-licenses
And accept the terms on the terminal
I didn't find a perfect solution for this.
I solved it by resetting my windows. All licenses are now accepted and the app runs fine.
I tried this as coined from here since I couldn't get it to work from all methods:
in root/android/gradle/wrapper/gradle-wrapper.properties set
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
in root/android/build.gradle, set
dependencies { classpath 'com.android.tools.build:gradle:3.3.2' }
check if in root/android/app/build.gradle SDK version is set to minimum 28 for:
compileSdkVersion 28 and targetSdkVersion 28
My project successfully built after doing this
Delete the .gradle folder then re-run flutter run.
you can try this way it actually worked for me:
1- visit gradle releases webpage and download last version of gradle
2- unzip the file in this path : "C:\Users"pc name".gradle\wrapper\dists
3- open your editor and try again and it will work inshaalah ☺
Related
My Flutter project works fine, I can build it as Android app with VisualStudio Code. With AndroidStudio I am able to build the Android app if I open only the android folder and build the Android app as android project.
But if I open the whole Flutter project in AndroidStudio and try to build it for Android (iOS works fine) I get this error:
Exception: Gradle build failed to produce an .apk file. It's likely that this file was generated under .../build, but the tool couldn't find it.
Seems like an IDE bug, is there anyone with a solution for me?
Android Studio version : Android Studio Electric Eel | 2022.1.1 (Build #AI-221.6008.13.2211.9477386, built on January 11, 2023)
Update:
app/build.gradle
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
def flutterVersionName = localProperties.getProperty('flutter.versionName')
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 33
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
flavorDimensions "distribute"
productFlavors {
appCenter {
dimension "distribute"
}
googlePlay {
dimension "distribute"
}
}
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "myId"
minSdkVersion 21
targetSdkVersion 33
versionCode 3
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
You have no default flavor defined, so you need to specify flavor to build. From command line:
flutter run --flavor appCenter (or googlePlay)
In Android Studio, go to Run->Edit configurations and set flavor to build (in your case appCenter or googlePlay. You can also add new configuration to be able to swith between them to build different flavor.
**This is the error message :**
Launching lib\main.dart on sdk gphone x86 in debug mode...
Running Gradle task 'assembleDebug'...
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\HP-LinkR\Videos\event_notifier\android\build.gradle'
line: 35
* What went wrong:
A problem occurred evaluating root project 'android'.
> Could not find method implementation() for arguments
[com.android.support:support-annotations:28.0.0] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
* 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 2s
Exception: Gradle task assembly debug failed with exit code 1
***This is code for the Build.gradle file that is giving the error:***
New Properties methods is highlighted red
This is code for the Build.gradle file that is giving the error:
New Properties methods is highlighted red
This is code for the Build.gradle file that is giving the error:
New Properties methods is highlighted red
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with
flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID
(https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.event_notifier"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --
release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-
jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics:17.2.2'
compile 'com.android.support:multidex:1.0.1'
}
Goto event_notifier\android\build.gradle ...
These dependencies should make it build:
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-
jdk7:$kotlin_version"
compile "com.google.firebase:firebase-analytics:17.2.2"
compile "com.android.support:multidex:1.0.1"
}
The actual problem seems to be a quite outdated version of the Android Gradle Plugin.
You'd have to upgrade to something more current to use implementation:
classpath "com.android.tools.build:gradle:4.0.1"
And maybe already start with current androidx packages ...because else you'll be stuck at the latest version of Firebase libraries, which use these obsolete support libraries. That Flutter project may generally be outdated and might require some refactoring (unless using the above compile):
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.72"
implementation "com.google.firebase:firebase-analytics:17.4.4"
// https://mvnrepository.com/artifact/androidx.multidex/multidex
implementation "androidx.multidex:multidex:2.0.1"
}
I can't connect my app to Google Firebase and I need to see somethings in that build gradle file. When I open the app level build gradle, I get errors, I am trying to connect my app to Google Firebase but when I open my app normally, I see no errors at all and everything is going just fine and I can still run my app on the Android Emulator, but when I go ahead and open the file, errors start to pop up and I am unable to run my app, here is my app level build gradle for Android:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 29
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "co.appbrewery.flash_chat"
minSdkVersion 16
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flut
ter {
source '../..'
}
dependencies {
implementation 'androidx.multidex:multidex:2.0.0'
}
I am unable to understand the problem. Please help.
You can't edit the gradle files in the flutter project. You have to click on Tools --> Flutter --> Open Android Module in Android Studio. Then you can edit the graddle, run the app and come back to the flutter project with no errors.
works
Goto : Tools -> Flutter -> Open Flutter Module in Android Studio -> Make changes in build gradle
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
My app crashes whenever I try to send create a new user with email and password with firebase_auth package. It successfully creates the account but then app crashes. I changed 'com.google.gms:google-services:4.2.0' to 3.2.1 in my build.gradle file but that did not helped. The problem still occurs and I don't know what to change.
The Error:
https://pastebin.ubuntu.com/p/fbzC3dNkv8/
My Code:
https://pastebin.ubuntu.com/p/5Ghjp2Hw55/
My Flutter Doctor Output
[√] Flutter (Channel stable, v1.9.1+hotfix.6, on Microsoft Windows [Version 6.3.9600], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 3.5)
[!] VS Code (version 1.39.2)
X Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected device
! No devices available
! Doctor found issues in 2 categories.
My build.gradle file:
https://pastebin.ubuntu.com/p/t6MPZ5z34M/
My app level build.gradle file:
https://pastebin.ubuntu.com/p/tzztfQ4Nhb/
I solved the problem. I changed my gradle.properties file like this:
android.useAndroidX=true
android.enableJetifier=true
org.gradle.jvmargs=-Xmx1536M
Also my app level gradle file like this:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.cagriserpin.focus_on"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
}
apply plugin: 'com.google.gms.google-services'
I hope that helps other people who encounters this problem
While connect my app with firebase generate SHA key app-level build.gradel shows an error in line 24 after adding google.json file I don't get where I am doing wrong line 24 starts from apply plugin. I upgrade flutter still I am getting this error -
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "mdhv.co.clone_flutter"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
After run Flutter doctor don't get any issue then where is the problem?
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v1.10.3-pre.54, on Microsoft Windows [Version 10.0.18362.356], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 3.5)
[√] Connected device (1 available)
• No issues found!
The error you've provided is complete, but build errors are usually caused by the added package not being installed correctly. Running flutter clean then flutter pub get should do the job. Also, depending on the Firebase products that you're using, you only need to use Firebase CLI and flutterfire_cli to setup Firebase in your Flutter project.