当前位置: 首页 > 知识库问答 >
问题:

我想连接Firebase,但我有一个错误

乐刚毅
2023-03-14

我想与Firebase连接,但我有一个错误:"无法解析Android应用程序模块gradleconfig.resolvegradle构建问题和/或重新同步."和我检查我的gradle.

apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
    applicationId "dxd.zzz.axy"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 2
    versionName "1.1"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
lintOptions {
    checkReleaseBuilds false
    // Or, if you prefer, you can continue to check for errors in release builds,
    // but continue the build even when errors are found:
    abortOnError false
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.android.gms:play-services-maps:11.0.4'
implementation 'com.google.firebase:firebase-messaging:11.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.mikhaellopez:circularimageview:3.0.2'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.mohamadamin:persianmaterialdatetimepicker:1.2.1'
implementation 'com.android.support:mediarouter-v7:26.1.0'
implementation files('libs/sqliteassethelper-2.0.1.jar')
}

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

共有3个答案

范高刚
2023-03-14

别担心那个警告。如果它构建成功,那么就不会有任何问题。

强才捷
2023-03-14

首先,确保您使用的是最新的谷歌服务版本(项目级别):

classpath 'com.google.gms:google-services:4.0.1'

然后更改代码,还应添加firebase core,如下所示。

apply plugin: 'com.android.application'
android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "dxd.zzz.axy"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 2
        versionName "1.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'

    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.mikhaellopez:circularimageview:3.0.2'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    implementation 'com.mohamadamin:persianmaterialdatetimepicker:1.2.1'
    implementation 'com.android.support:mediarouter-v7:26.1.0'
    implementation files('libs/sqliteassethelper-2.0.1.jar')
}

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

此外,如果您现在想使用其他firebase库,请保持以下最新版本,并始终查看此链接以确保您使用的是最新版本。

    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.google.firebase:firebase-ads:15.0.1'
    implementation 'com.google.firebase:firebase-analytics:16.0.0'
    implementation 'com.google.firebase:firebase-appindexing:15.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-firestore:17.0.1'
    implementation 'com.google.firebase:firebase-functions:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:17.0.0'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.google.firebase:firebase-crash:16.0.0'
    implementation 'com.google.firebase:firebase-invites:16.0.0'
    implementation 'com.google.firebase:firebase-perf:16.0.0'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-config:16.0.0'
池宸
2023-03-14

您应该在应用程序级别gradle中编写最新版本的gms服务请参阅下图

 类似资料: