尝试配置firebase时,Gradle构建失败,并且项目错误编译?

时间:2016-09-29 01:36:46

标签: android gradle build.gradle

一切正常但是当我尝试将Firebase配置为gradle时,应用程序级gradle文件中会引发以下错误。我不确切地知道错误发生的位置,但错误日志显示最后一行的错误"应用插件:' com.google.gms.google-services' "



Could not get unknown property 'compile' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.




这个代码。



buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'


    }
}
apply plugin: 'com.android.application'

apply plugin: 'io.fabric'




repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.xxx.yyy.zzz"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"

        manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                onesignal_app_id               : "",
                                onesignal_google_project_number: ""]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])

  

    compile('com.crashlytics.sdk.android:answers:1.3.10@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:crashlytics:2.6.4@aar') {
        transitive = true;
    }


compile
    'com.onesignal:OneSignal:3.+@aar'compile
    'com.google.android.gms:play-services-gcm:9.4.0'compile
    'com.google.android.gms:play-services-location:9.4.0'compile
    'com.android.support:appcompat-v7:24.2.0'compile
    'com.google.firebase:firebase-core:9.4.0'testCompile 'junit:junit:4.12'
}



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




4 个答案:

答案 0 :(得分:2)

您已将compile 用作财产,但它不是一个。
你需要传递一个字符串参数。

更改

compile
    'com.onesignal:OneSignal:3.+@aar'compile
    'com.google.android.gms:play-services-gcm:9.4.0'compile
    'com.google.android.gms:play-services-location:9.4.0'compile
    'com.android.support:appcompat-v7:24.2.0'compile
    'com.google.firebase:firebase-core:9.4.0'testCompile 'junit:junit:4.12'

compile 'com.onesignal:OneSignal:3.+@aar'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.google.firebase:firebase-core:9.4.0'
testCompile 'junit:junit:4.12'

答案 1 :(得分:1)

我在android studio =>中从插件添加firebase时遇到此错误"刀具" = GT; "火力地堡"

无法获取未知属性'编译'对于类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandle

的对象

解决方案是:

请检查您的build.gradle文件

并在新行

上检查文本格式编译
compile 'com.onesignal:OneSignal:3.+@aar'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'

答案 2 :(得分:0)

确保您在顶级 classpath 'com.google.gms:google-services:3.0.0'中添加了build.gradle

您的build.gradle如下所示:

dependencies {
    ...
    classpath 'com.google.gms:google-services:3.0.0'
}

答案 3 :(得分:0)

不要忘记在项目应用文件夹中添加 google-service.json 文件。 粘贴在那里并使项目失效