我想在云端google firebse教程中使用firebase制作To Do Android应用程序。这是我得到的错误

时间:2017-06-03 07:14:43

标签: android-studio firebase firebase-realtime-database

这是mybuild.gradle文件。

apply plugin: 'com.google.gms.google-services'
//apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.example.bosnia.todoapp"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.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'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-database:9.0.2'

}

所以我想让android做基于firebase的应用程序云,我有这个错误问题。

因此默认代码为apply plugin: 'com.android.application'我将其替换为apply plugin: 'com.google.gms.google-services',这是错误代码。这是我的错误Could not find method android() for arguments [build_e0nio0g58fflcu8rkqyodi904$_run_closure1@41701092] on project ':app' of type org.gradle.api.Project.

2 个答案:

答案 0 :(得分:0)

'com.android.application'是您应用程序的关键插件。根据{{​​3}},您应该在项目中添加'com.google.gms.google-services'而不是替换。

请尝试以下操作:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.example.bosnia.todoapp"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.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'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-database:9.0.2'

}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

答案 1 :(得分:0)

添加apply plugin com.google.gms.... 在应用程序级别build.gradle文件的底部