Search code examples
androidfirebasegradlegoogle-play-servicesandroid-gradle-plugin-3.3.0

Why gradle plugin 3.3.0 doesn't want to build google-services?


I'm trying to Sync my project with gradle:3.3.0 , but in result file values.xml for google-services is not generated in folder: D:\Android\workspace\myproject\app\build\generated\res\google-services\debug\values\values.xml

Top level build file build.gradle:

 apply plugin: 'kotlin'

    buildscript {
        ext.kotlin_version = '1.3.11'
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.3.0'
            classpath 'com.google.gms:google-services:4.1.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
          }
    }

    allprojects {
        repositories {
            mavenLocal()
            google()
            jcenter()
            mavenCentral()
            maven { url "https://jitpack.io" }
        }

        configurations.all {
            exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jre7'
        }
    }

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    }

    compileKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
    compileTestKotlin {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }

app/build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    ...
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "com.google.firebase:firebase-database:16.0.5"
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation "com.google.firebase:firebase-auth:16.1.0"
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.5'
}

apply plugin: 'com.google.gms.google-services'

google-services.json

File google-services.json is located in D:\Android\workspace\myproject\app\google-services.json

In result after run of app the error occurs:

 01-23 10:31:31.578 30044-30073/E/FA: GoogleService failed to initialize, status: 10, Missing google app id value from from string resources with name google_app_id.
01-23 10:31:31.578 30044-30073/E/FA: Missing google_app_id. Firebase Analytics disabled. See 
01-23 10:31:33.758 30044-30044/ E/AndroidRuntime: FATAL EXCEPTION: main
    Process: , PID: 30044
    java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process . Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.4:240)
        at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)

Solution

  • Remove dependencies block from top-level gradle file:

    dependencies {
            implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
        }
    

    And update to classpath 'com.android.tools.build:gradle:3.3.0' and classpath 'com.google.gms:google-services:4.2.0' In result your Gradle Files should be Like This For Android Studio 3.3 (stable channel)

    build.gradle(project:yourProject)

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
        ext.kotlin_version = '1.3.11'
        repositories {
            google()
            jcenter()
    
            // Add repository
            maven {
                url 'https://maven.fabric.io/public'
            }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.3.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.2.0'
            classpath 'io.fabric.tools:gradle:1.26.1'
    
    
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
    
            // Add repository
            maven {
                url 'https://maven.google.com/'
            }
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    build.gradle(Module:app)

    apply plugin: 'com.android.application'
    
    apply plugin: 'kotlin-android'
    
    apply plugin: 'kotlin-android-extensions'
    
    apply plugin: 'kotlin-kapt'
    
    apply plugin: 'com.google.gms.google-services'
    
    apply plugin: 'io.fabric'
    
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    
    
    
    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "sanaebadi.info.teacherhandler"
            minSdkVersion 15
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    
        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE-FIREBASE.txt'
            exclude 'META-INF/NOTICE'
    
        }
    
        dataBinding {
            enabled = true
        }
    }
    
    dependencies {
        def room_version = "2.1.0-alpha03"
        def lifecycle_version = "2.0.0"
    
    
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
        implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test:runner:1.1.1'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    
        implementation 'androidx.cardview:cardview:1.0.0'
        implementation 'com.google.android.material:material:1.1.0-alpha02'
        implementation 'androidx.recyclerview:recyclerview:1.0.0'
    
    
    
        //Firebase
        implementation 'com.google.firebase:firebase-core:16.0.6'
        implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
        implementation 'com.google.firebase:firebase-messaging:17.3.4'
        implementation 'com.google.firebase:firebase-storage:16.0.5'
        implementation 'com.google.firebase:firebase-auth:16.1.0'
        implementation 'com.google.android.gms:play-services-auth:16.0.1'
        implementation 'com.google.firebase:firebase-database:16.0.5'
    }
    

    gradle-wrapper.properties

    #Tue Jan 15 07:24:23 EST 2019
    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip