1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] FAILURE: Build failed with an exception (flutter firebase)

Discussão em 'Mobile' iniciado por Stack, Novembro 9, 2024 às 22:03.

  1. Stack

    Stack Membro Participativo

    I was trying to integrate Firebase for my app but did not succeed in it. Every time I try to run it throws Gradle exception error.

    This is my android/app/build.gradle file content:

    plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
    id 'com.google.gms.google-services'
    }

    def localProperties = new Properties()
    def localPropertiesFile = rootProject.file("local.properties")
    if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader("UTF-8") { reader ->
    localProperties.load(reader)
    }
    }

    def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
    if (flutterVersionCode == null) {
    flutterVersionCode = "1"
    }

    def flutterVersionName = localProperties.getProperty("flutter.versionName")
    if (flutterVersionName == null) {
    flutterVersionName = "1.0"
    }

    android {
    namespace "com.example.firebase_one"
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    compileSdkVersion 34
    }

    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.firebase_one"
    // You can update the following values to match your application needs.
    // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
    minSdk = flutter.minSdkVersion
    targetSdk = 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:33.1.0')
    }


    And this is the content of android/build.gradle file:

    buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
    google()
    mavenCentral()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:7.2.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms.google-services:4.4.2'
    }
    }
    allprojects {
    repositories {
    google()
    mavenCentral()
    }
    }

    rootProject.buildDir = "../build"
    subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
    project.evaluationDependsOn(":app")
    }

    tasks.register("clean", Delete) {
    delete rootProject.buildDir
    }


    I tried adding these codes which is missing:

    buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
    google()
    mavenCentral()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:7.2.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
    }


    This is my main.dart code:

    import 'package:firebase_core/firebase_core.dart';
    import 'package:flutter/material.dart';

    void main() async{
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    runApp(const MyApp());
    }

    class MyApp extends StatelessWidget {
    const MyApp({super.key});

    // This widget is the root of your application.
    @override
    Widget build(BuildContext context) {
    return MaterialApp(
    title: 'Flutter Demo',
    theme: ThemeData(

    colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
    useMaterial3: true,
    ),
    home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
    }
    }

    class MyHomePage extends StatefulWidget {
    const MyHomePage({super.key, required this.title});

    final String title;

    @override
    State<MyHomePage> createState() => _MyHomePageState();
    }

    class _MyHomePageState extends State<MyHomePage> {
    int _counter = 0;

    void _incrementCounter() {
    setState(() {

    _counter++;
    });
    }

    @override
    Widget build(BuildContext context) {

    //

    return Scaffold(
    appBar: AppBar(

    backgroundColor: Theme.of(context).colorScheme.inversePrimary,

    title: Text(widget.title),
    ),
    body: Center(

    child: Column(

    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
    const Text(
    'You have pushed the button this many times:',
    ),
    Text(
    '$_counter',
    style: Theme.of(context).textTheme.headlineMedium,
    ),
    ],
    ),
    ),
    floatingActionButton: FloatingActionButton(
    onPressed: _incrementCounter,
    tooltip: 'Increment',
    child: const Icon(Icons.add),
    ), // This trailing comma makes auto-formatting nicer for build methods.
    );
    }
    }


    What might be the solution?

    Continue reading...

Compartilhe esta Página