无法获取类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler对象的未知属性“classpath”。

3

我正在为安卓设备构建Ionic应用。我的gradle版本是3.3。这是我第一次构建安卓应用程序。我遇到了以下错误:

Build file 'E:\FarmApp\smartFarm\platforms\android\build.gradle' line: 33

    * What went wrong:
    A problem occurred evaluating root project 'android'.
    > Could not get unknown property 'classpath' for object of type
    org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

以下是我的 build.gradle 文件部分内容

 buildscript {
repositories {
    mavenCentral()
    jcenter()
}

// Switch the Android Gradle plugin version requirement depending on the
// installed version of Gradle. This dependency is documented at
// http://tools.android.com/tech-docs/new-build-system/version-compatibility
// and https://issues.apache.org/jira/browse/CB-8143
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3',
    classpath 'com.google.gms:google-services:3.1.0'
}
}

 // Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
repositories {
    mavenCentral();
    jcenter()
  }
 }

task wrapper(type: Wrapper) {
gradleVersion = '2.14.1'
}

1
你说你的Gradle版本是3.3,但是在你的代码中有这一行gradleVersion = '2.14.1' - Daniel Bejan
根据 https://bintray.com/android/android-tools/com.android.tools.build.gradle,`2.3.3` 是最新的稳定版本。尝试更改到该版本。 - Daniel Bejan
尝试从Ionic中删除android平台,然后再将其添加回来。 - Daniel Bejan
非常感谢。你救了我的一天。从 Ionic 中删除 Android 平台,然后再次添加它可以解决问题。 - Alex Johnson
很高兴听到进展顺利 :). 如果其他人遇到这个问题,我已经提交了一个答案 :) - Daniel Bejan
显示剩余2条评论
2个回答

26

去掉classpath末尾处的逗号。这对我有效。

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
    classpath 'com.google.gms:google-services:3.1.0'
}

这绝对是正确的答案,我认为当JS/TS开发人员开始使用Flutter并习惯于JSON时,就会出现这种情况。 - Raqha

0
尝试使用以下命令从ionic中删除android平台,然后再次添加它:

   $ ionic platform remove android
   $ ionic platform add android

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接