如何处理“无法找到()项目方法Android的:应用程序“类型org.gradle.api.Project的”错误

问题描述 投票:3回答:2

我收到以下错误ERROR: Could not find method android() for arguments [build_9fawur68cjcg5sfkvki95w8sr$_run_closure1@30cec325] on project ':app' of type org.gradle.api.Project.

我不知道为什么我得到这个错误,我尝试了很多其他的事情,看看我是否能得到它的工作。虽然它从来不会。

应用级gradle这个已经修改多次均未解决问题。项目一级gradle这个不正确的工作之一。

应用程序的gradle水平

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "net.troop59.LoginFirebase"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-core:16.0.6'
    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'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:28.0.0'

    //add this line
    compile 'com.google.firebase:firebase-auth:16.1.0'
}
apply plugin: "com.google.gms.google-services"

项目的gradle水平

// Top-level build file where you can add configuration options common to all sub-projects/modules.
        buildscript {
            repositories {
                google()
                jcenter()

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

                // NOTE: Do not place your application dependencies here; they belong
                // in the individual module build.gradle files
            }
        }
allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
android android-gradle
2个回答
1
投票

你缺少的行

apply plugin: 'com.android.application'

在您的应用程序级build.gradle文件的最开始。

More info

一个example on github

你也应该在项目级build.gradle这种依赖关系:

dependencies {
    ...
    classpath 'com.android.tools.build:gradle:3.3.0'
    ...
}

更新#1

您必须添加谷歌库:

allprojects {
    repositories {
        google()
        jcenter()
    }
}

0
投票
  • 正如我不能添加评论,所以我会补充回答
  • 你也应该
  • 每次编译更改为实现
  • 然后验证高速缓存和重新启动(如下)
  • [
© www.soinside.com 2019 - 2024. All rights reserved.