Build file 'D:\AndroidStudio\clone_flutter\android\app\build.gradle' line: 24 - android

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.

Related

"Exception: Gradle build failed" only for flutter project in AndroidStudio

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.

Execution failed for task ':app:processReleaseMainManifest', while building flutter apk

I have an app that was building fine before I formated my PC. I installed everything flutter needs and what I had in my previous install and tried to build my app after cloning from github. It results in failure.
PS D:\flutter_projects\uni-access> flutter build apk
Running "flutter pub get" in uni-access... 1.849ms
💪 Building with sound null safety 💪
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processReleaseMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module #6732aa85
* 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 29s
Running Gradle task 'assembleRelease'... 30,6s
Gradle task assembleRelease failed with exit code 1
My flutter env.
PS D:\flutter_projects\uni-access> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.1, on Microsoft Windows [Version 10.0.22000.978], locale el-GR)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Chrome - develop for the web
[✗] Visual Studio - develop for Windows
✗ Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
[!] Android Studio (not installed)
[✓] VS Code (version 1.71.1)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.
I have java 17 and my build.gradle in android/app is the following.
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: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
// compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 32
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.flutter_uni_access"
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
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 platform('com.google.firebase:firebase-bom:29.2.1')
implementation 'com.google.firebase:firebase-analytics'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation 'com.android.support:multidex:2.0.1'
}
This problem seems bizzare. I have tried flutter clean, gradle clean, deleting the .gradle dir from my user dir. Still nothing.

Plugin with id 'com.google.gms:google-services' not found while trying to integrate push notifications into flutter app

I am trying to integrate push notifications into my futter application with firebase, I followed the instructions on how to go about it. But each time I add "com.google.gms:google-services" in my android/app/build.gradle file, I get the following error:
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\flutter_project\my_app\android\app\build.gradle' line: 27
* What went wrong:
A problem occurred evaluating project ':app'.
> Plugin with id 'com.google.gms:google-services' not found.
* 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
I have tried other solutions I saw online and none have helped me. Please I need help.
Here is my flutter doctor output:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.20.2, on Microsoft Windows [Version 10.0.18362.1016], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.48.2)
[√] Connected device (1 available)
• No issues found!
here is my android/app/build.gradle file:
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' //defaulting code
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID
applicationId "com.myapp.myapp"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.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 {
testImplementation 'junit:junit:4.12'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
I have also updated my flutter to the latest version I still get this error. What am I doing wrong?
It should be
apply plugin: 'com.google.gms.google-services'
Dot, not colon.
Firstly:
you need add classpath 'com.google.gms:google-services:4.3.3' in your project-level build.gradle
Then:
add "com.google.gms:google-services" in android/app/build.gradle file
I guess you missed firset step. Here is the doc https://firebase.google.com/docs/cloud-messaging/android/client

Flutter error - Gradle task assembleDebug failed with exit code -1

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 ☺

Android App Crashing After Successfully Creating New User With Firebase In Flutter [closed]

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

Categories

Resources