为啥 gradle plugin 3.3.0 不想构建 google-services?

Posted

技术标签:

【中文标题】为啥 gradle plugin 3.3.0 不想构建 google-services?【英文标题】:Why gradle plugin 3.3.0 doesn't want to build google-services?为什么 gradle plugin 3.3.0 不想构建 google-services? 【发布时间】:2019-06-16 17:37:24 【问题描述】:

我正在尝试将我的项目与 gradle:3.3.0同步,但在文件夹中未生成用于 google-services 的结果文件 values.xmlD:\android\workspace\myproject\app\build\generated\res\google-services\debug\values\values.xml

***构建文件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

文件google-services.json位于D:\Android\workspace\myproject\app\google-services.json

应用程序运行后出现错误:

 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)

【问题讨论】:

Can't update to com.google.gms:google-services:4.2.0的可能重复 【参考方案1】:

从*** gradle 文件中移除依赖块:

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

并更新为classpath 'com.android.tools.build:gradle:3.3.0'classpath 'com.google.gms:google-services:4.2.0' 结果,对于 Android Studio 3.3(稳定通道),您的 Gradle 文件应该是这样的

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

【讨论】:

出现错误***.com/questions/54441456/…【参考方案2】:

在项目级 build.gradle 中更新为 classpath 'com.google.gms:google-services:4.2.0'

【讨论】:

同步后> Configure project :app registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection) CONFIGURE SUCCESSFUL in 16s 1 正如你在最后看到的错误1。这是什么意思?

以上是关于为啥 gradle plugin 3.3.0 不想构建 google-services?的主要内容,如果未能解决你的问题,请参考以下文章

在使用 Android Gradle 插件 3.3.0 合并资源期间构建失败

Android Gradle Plugin 测试 apk 构建器是不是会自动对我的测试 apk 进行多重索引?如果是这样,为啥会产生“NoSuchMethodError”

为啥 Gradle 会降级 Grails 3.1 应用程序中的传递依赖项?

AndroidStudio gradle插件和Gradle版本对应表

为啥我的 Gradle 构建失败并出现“未找到插件 [id: 'org.flywaydb.enterprise.flyway', version: '6.5.0']”错误?

Could not find com.android.tools.build:gradle:3.3.0.