An error occurs during compilation. flutter, firebase app (developed on Android Studio)

Asked 2 years ago, Updated 2 years ago, 93 views

When I start the app with Run, I get the following error:

● Error contents

Launching lib\main.dart on Android SDK build for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Finished with error: Please review your Gradle project setup in the android/folder.

Error running Gradle:
ProcessException: Process "C:\Users\\AndroidStudioProjects\flutter_app2\android\gradlew.bat "exited normally:
FAILURE: Build failed with an exception.

  • Where:
    Build file'C:\Users\\AndroidStudioProjects\flutter_app2\android\build.gradle'>line:24

  • What was wrong:
    A problem occurred validating root project 'android'.
    A problem occurred configuring project': app'.
    Could not resolve all artifacts for configuration':app:classpath'.
    Cannot resolve external dependency com.google.gms:google-services:4.0.1 because no repositories are defined.
    Required by:
    project:app

  • 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

Where:
Build file'C:\Users\\AndroidStudioProjects\flutter_app2\android\build.gradle'>line:24

What was wrong:
A problem occurred validating root project 'android'.
A problem occurred configuring project': app'.
Could not resolve all artifacts for configuration':app:classpath'.
Cannot resolve external dependency com.google.gms:google-services:4.0.1 because no repositories are defined.
Required by:
project:app

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 1s
Command: C:\Users\\AndroidStudioProjects\flutter_app2\android\gradlew.bat app:properties

If you do not include the following information in the build.gradle file, there will be no errors, so I think this is the cause of the error, but I would appreciate it if you could tell me how to deal with it.

buildscript{
dependencies {
    // Add this line
    classpath'com.google.gms:google-services:4.0.1'
    }
}
allprojects {
    // ...
    repositories {
        Google() // Google's Maven repository
        // ...
    }
}

apply plugin: 'com.android.application'

android{android{
    // ...
}

dependencies {
    // ...
    implementation'com.google.firebase:firebase-core:16.0.1'
    // Getting a "Could not find" error? Make sure you have
    // added the Google maven repository to your root build.gradle
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

●build.gradle File Contents

deflocalProperties=newProperties()
deflocalPropertiesFile=rootProject.file('local.properties')
if(localPropertiesFile.exists()){
    localPropertiesFile.withReader('UTF-8') {reader->
        localProperties.load(reader)
    }
}

defflutterRoot=localProperties.getProperty('flutter.sdk')
if(flutterRoot==null){
    row new GradleException("Flutter SDK not found.Define location with flutter.sdk in the local.properties file.")
}

defflutterVersionCode=localProperties.getProperty('flutter.versionCode')
if(flutterVersionCode==null) {
    flutterVersionCode='1'
}

defflutterVersionName=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{android{
    compileSdkVersion28

    US>lintOptions{
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO —Specify your own unique Application ID (https:// developer.andro id.com/studio/build/application-id.html).
        applicationId "com.example.androidstudio.flutter_app2"
        minSdkVersion16
        targetSdkVersion28
        versionCodeflutterVersionCode.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
        }
    }
}

US>flutter{
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation'com.android.support.test:runner:1.0.2'
    androidTestImplementation'com.android.support.test.espreso:espresso-core: 3.0.2'
}


buildscript {
    dependencies {
        // Add this line
        classpath'com.google.gms:google-services:4.0.1'
    }
}
allprojects {
    // ...
    repositories {
        Google() // Google's Maven repository
        // ...
    }
}

apply plugin: 'com.android.application'

android{android{
    // ...
}

dependencies {
    // ...
    implementation'com.google.firebase:firebase-core:16.0.1'
    // Getting a "Could not find" error? Make sure you have
    // added the Google maven repository to your root build.gradle
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

android-studio firebase gradle

2022-09-30 11:29

1 Answers

Could not separate build.gradle per project from build.gradle per application.
After rewriting each file, the error no longer occurs.
https://teratail.com/questions/183014


2022-09-30 11:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.