android-studio - 在 org.gradle.api.internal.artifacts.dsl.dependencies 类型的对象上找不到参数 [目录 'libs'] 的方法实现()

标签 android-studio android-gradle-plugin

在我的 Android Studio 项目中安装 dart 和 flutter 后,我遇到了失败的等级构建问题。我尝试创建一个新的 Flutter 应用程序,但它一直在构建,所以我不得不停止它。在重新启动 Android Studio 时,我的成绩拒绝为我拥有的每个现有项目构建。

错误信息

Gradle sync failed: This Gradle plugin requires a newer IDE able to request IDE model level 3. For Android Studio this means version 3.0+
                Consult IDE log for more details (Help | Show Log)

app.gradle
apply plugin: 'com.android.application'

android {
signingConfigs {
}
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
    minSdkVersion 19
    targetSdkVersion 28
    multiDexEnabled true
    versionName '3.1'
    testInstrumentationRunner 
  "android.support.test.runner.AndroidJUnitRunner"
    android {
        defaultConfig {

        }
    }
    versionCode 1
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.firebase:firebase-config:11.0.2'
androidTestImplementation('com.android.support.test.espresso:espresso- 
core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
implementation 'com.google.firebase:firebase-auth:11.0.2'
implementation 'com.google.firebase:firebase-core:11.0.2'
implementation 'com.google.firebase:firebase-database:11.0.2'
implementation 'com.google.android.gms:play-services-maps:11.0.2'
implementation 'com.google.android.gms:play-services-location:11.0.2'
implementation 'com.google.android.gms:play-services:11.0.2'
implementation 'com.google.firebase:firebase-storage:11.0.2'
implementation 'com.github.bumptech.glide:glide:3.8.0'
implementation 'com.firebase:geofire-android:2.1.1'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.github.jd-alexander:library:1.1.0'
implementation 'me.biubiubiu.justifytext:library:1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
    google()
    jcenter()
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.3.1'
    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()
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}
}


task clean(type: Delete) {
delete rootProject.buildDir
}

gradle-wrapper.properties
#Thu Feb 21 22:53:26 WAT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

最佳答案

首先,您的 行不正确应用程序 build.gradle(基于你的问题),正确的应该是这样的:

apply plugin: 'com.android.application'
// You don't need a repository here

android {
  signingConfigs {
  }
  compileSdkVersion 28
  buildToolsVersion '28.0.3'
  defaultConfig {
    minSdkVersion 19
    targetSdkVersion 28
    multiDexEnabled true
    versionName '3.1'
    testInstrumentationRunner
    "android.support.test.runner.AndroidJUnitRunner"
    android {
      defaultConfig {
      }
    }
    versionCode 1
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'),
          'proguard-rules.pro'
    }
  }
  productFlavors {
  }
}

dependencies {
  implementation fileTree(include: ['*.jar'], dir: 'libs')

  androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
  })


  implementation 'com.android.support:appcompat-v7:28.0.0'
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'

  implementation 'me.biubiubiu.justifytext:library:1.1'
  implementation 'de.hdodenhof:circleimageview:2.2.0'
  implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
  testImplementation 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

那么你需要更新你的 build.gradle因为 implementation仅适用于 android build.gradle 3.0 版。 :
buildscript {
repositories {
    google()
    jcenter()
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.3.1'
    classpath 'com.google.gms:google-services:4.2.0'
}
}

allprojects {
repositories {
    jcenter()
    mavenCentral()
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
 }
}


task clean(type: Delete) {
delete rootProject.buildDir
}   

您还需要将 gradle 版本更新为 4.1

详情请到Android Gradle plugin release notes

关于android-studio - 在 org.gradle.api.internal.artifacts.dsl.dependencies 类型的对象上找不到参数 [目录 'libs'] 的方法实现(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54846722/

相关文章:

java - Android Studio Java JDK 错误

android - 如何找出编译 'com.android.support:design:23.1.1'

java - 从 Eclipse 迁移到 Android Studio 问题

android - 找不到 Play 服务广告标识符

android - 哪个 android studio 版本有 Android 5.1(API 级别 22)?

Android:- 如何在 6.0 操作系统以下的分词器 android TextView 中添加连字符 "-"

android - java.util.zip.ZipException Android Studio

android - :app:dexDebug on adding libGoogleAnalyticsServices

java - Android Studio 无法在 Mac OS Snow Leopard 上打开 - java.lang.NoClassDefFoundError : java. awt.Toolkit

android - 迁移到 androidx 后错误膨胀类 androidx.appcompat.widget.FitWindowsFrameLayout