如何消除"请在构建文件底部应用google-services插件"警告
消除Google Services插件位置警告
我的应用运行正常,但需要移除以下警告:Please apply google-services plugin at the bottom of the build file.
已尝试将Gradle更新至7.5版本,问题仍未解决。
当前配置文件
Project级build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { id 'com.android.application' version '7.4.1' apply false id 'com.android.library' version '7.4.1' apply false id "com.google.gms.google-services" version "4.3.14" apply false }
App级build.gradle
plugins { id 'com.google.gms.google-services' id 'com.android.application' } android { namespace 'com.ahmedapps.walkthrough_app' compileSdk 33 defaultConfig { applicationId "com.ahmedapps.walkthrough_app" minSdk 21 targetSdk 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_16 targetCompatibility JavaVersion.VERSION_16 } } dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.8.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation 'com.android.volley:volley:1.2.1' implementation 'com.github.bumptech.glide:glide:4.14.2' def lottieVersion = "4.1.0" implementation "com.airbnb.android:lottie:$lottieVersion" implementation platform('com.google.firebase:firebase-bom:31.2.2') implementation 'com.google.firebase:firebase-analytics' implementation 'androidx.core:core-splashscreen:1.0.0-alpha01' implementation 'com.facebook.android:audience-network-sdk:6.12.0' implementation 'com.google.android.gms:play-services-ads:21.5.0' implementation 'com.google.ads.mediation:facebook:6.12.0.0' implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]' }
解决方案
警告的核心原因是Google Services插件需要在Android应用插件之后加载,且必须是plugins块中的最后一个插件。调整App级build.gradle的plugins顺序即可解决:
修改后的App级build.gradle plugins块:
plugins { id 'com.android.application' id 'com.google.gms.google-services' }
原理
Google Services插件需要读取Android插件配置的applicationId、buildTypes等信息来生成Firebase相关的配置文件,因此必须在Android插件初始化完成后再加载,放在plugins块末尾能确保它是最后执行的插件,避免因依赖未初始化导致的警告。
内容的提问来源于stack exchange,提问作者Abde Samad
相关产品推荐
相关产品推荐

