Firebase:无法解析Android应用程序模块的Gradle配置

bot*_*tus 12 android gradle firebase

我一直在尝试在我的android项目中设置firebase.问题是,我一直得到这个错误:无法解析android应用程序模块的Gradle配置...我真的无法解决它.

我见过很多人遇到这个错误,但似乎他们可以通过升级他们的构建工具版本或更新google-services来解决它.我已经做了所有这些,到目前为止还没能使它工作.

这是我的gradle脚本:

apply plugin: 'com.android.application'

android {
signingConfigs {
    AndroidAppPro {
    }
}
compileSdkVersion 25
buildToolsVersion '26.0.0'
useLibrary 'org.apache.http.legacy'
defaultConfig {
    applicationId "com.critizr.pro"
    minSdkVersion 14
    targetSdkVersion 25
    versionCode 9
    versionName "1.5.1"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
productFlavors {
    preprod {
        applicationId "com.cr.pro"
        buildConfigField 'boolean', 'IS_PROD', 'false'
        buildConfigField 'String', 'HOST', '"https://myurl.com/"'
    }
    prod {
        applicationId "com.cr.pro"
        buildConfigField 'boolean', 'IS_PROD', 'true'
        buildConfigField 'String', 'HOST', '"https://myurl/"'
    }
}
packagingOptions {
     exclude 'META-INF/DEPENDENCIES.txt'
     exclude 'META-INF/LICENSE.txt'
     exclude 'META-INF/NOTICE.txt'
     exclude 'META-INF/NOTICE'
     exclude 'META-INF/LICENSE'
     exclude 'META-INF/DEPENDENCIES'
     exclude 'META-INF/notice.txt'
     exclude 'META-INF/license.txt'
     exclude 'META-INF/dependencies.txt'
     exclude 'META-INF/LGPL2.1'
   }
Run Code Online (Sandbox Code Playgroud)

}

dependencies {
compile project(':lib-viewflow')

// new libs
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:cardview-v7:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'

compile 'com.google.android.gms:play-services-gcm:11.0.2'
compile 'com.google.android.gms:play-services-maps:11.0.2'
//compile 'com.google.android.gms:play-services-analytics:11.0.1'

compile 'org.apache.httpcomponents:httpclient:4.1'
compile 'org.apache.httpcomponents:httpmime:4.1'

compile 'com.joshdholtz.sentry:sentry-android:1.5.0'
compile 'com.borax12.materialdaterangepicker:library:1.6'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.cloudinary:cloudinary-core:1.2.2'
compile 'com.cloudinary:cloudinary-android:1.2.2'
compile 'com.loopj.android:android-async-http:1.4.5'
}
 apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)

第二个:

 buildscript {
repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}
 dependencies {
    classpath 'com.android.tools.build:gradle:2.3.1'
    classpath 'com.google.gms:google-services:3.1.0'
}
}

allprojects {
repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

小智 25

对我来说,通过删除jCenter 的警告工作

jCenter()  remove it..
Run Code Online (Sandbox Code Playgroud)


son*_*que 14

验证构建选项卡,并确保那里没有警告。

Firebase Assistant 似乎对任何Gradle 信息、警告或错误都非常敏感。

对我来说,这是来自 gradle 的一个简单的“信息”,不再需要 databinding.enabled :

 DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.
Run Code Online (Sandbox Code Playgroud)

删除 Firebase 助手后,效果很好。


Flo*_*her 12

导航组件的 safeargs 插件也可能导致此问题。为了修复它,我暂时id 'androidx.navigation.safeargs.kotlin'从应用程序级build.gradle文件中删除,然后将其添加回来。


Ala*_*aie 11

要在Android Studio v3.1上解决此问题(不确定以前的版本),只需像这样编辑应用程序的build.gradle:

  • 寻找: apply plugin: 'com.google.gms.google-services'然后将其删除然后同步.现在,您将能够毫无问题地使用Firebase助手.

  • 这个答案是正确的,但解释得不好。其实发生这个错误的原因是因为你在连接之前将admob应用程序添加到你的应用程序中,你需要删除aply插件以便再次重启。记住不需要删除任何其他依赖项或 json 文件 (6认同)

小智 5

我认为你的一些依赖是它的背后。只需转到您的 build.gradle(模块应用程序)并注释掉其中的大部分或全部(以找出哪个),再次同步现在忽略所有错误,如果成功则再次尝试连接到 firebase 然后您可以返回到您的 build.gradle 并取消注释它们以修复错误。

希望这可以帮助


Onu*_*Var 5

评论出来apply plugin: io.fabric对我有用。因此,请检查gradle文件中的依赖项。


小智 5

我遇到了一个问题viewBinding。按照谷歌的说明进行操作,一切正常。

android {
    ...
    buildFeatures {
        viewBinding true
    }
}
Run Code Online (Sandbox Code Playgroud)