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

标签 android gradle build.gradle

一切正常,但当我尝试将 Firebase 配置为 gradle 时,应用程序级 gradle 文件中会引发以下错误。我不知道错误发生的确切位置,但错误日志显示最后一行“apply plugin: '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'

最佳答案

您已将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'

关于android - 尝试配置 firebase 时,Gradle 构建失败,并出现项目编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39760037/

相关文章:

java - Android 模拟器错误,控制台错误日志重复错误

java - *** java.lang.instrument ASSERTION FAILED *** : "!errorOutstanding" with message transform method call failed? 的含义/原因是什么

android - android:gradle:依赖版本相同

android-studio - 为任务 ':app:mergeDebugResources' 构建 Gradle 失败

android - 失败 : Build failed with an exception

android - 如何在我的 Android 11 应用中隐藏状态栏?

java - Android 带有数字的字符串资源

java - 布局显示不正确

android - 找不到与 com.google.android.gms :strict-version-matcher-plugin:[15. 0.0、16.0.0 匹配的任何版本)

android - 使用变量时的 Gradle 库版本建议