【问题标题】:Gradle sync error in Android Studio giving error on root projectAndroid Studio中的Gradle同步错误在根项目上给出错误
【发布时间】:2017-10-15 05:47:19
【问题描述】:

当我尝试在 Android Studio 中运行我的应用时,我不断收到此错误

错误:(20, 0) 无法在 org.gradle.api.Project 类型的根项目“pomppyapp”上找到参数 [build_cmskf0wjjh0skzgqp1j9qzll2$_run_closure2@29a3fe65] 的方法 android()。 打开文件

这是我的 build.gradle(项目:pomppyapp)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'
    classpath 'com.google.gms:google-services:3.0.0'

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

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
}
dependencies {
}

还有另一个名为 build.gradle (Module: app) 的文件,其中包含以下内容:

apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "com.pomppyapp.com"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 12
    versionName '1.6'

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        debuggable false
        jniDebuggable false
    }
}

lintOptions {
    checkReleaseBuilds false
    // Or, if you prefer, you can continue to check for errors in release builds,
    // but continue the build even when errors are found:
    abortOnError false
}

productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
compile 'com.google.android.gms:play-services-ads:11.0.4'
compile 'com.pkmmte.view:circularimageview:1.1'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.firebase:firebase-messaging:9.0.0'
compile 'com.balysv:material-ripple:1.0.2'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.android.tools.build:gradle:2.3.0'
}
apply plugin: 'com.google.gms.google-services'

任何帮助将不胜感激,在此先感谢。

【问题讨论】:

    标签: android gradle


    【解决方案1】:

    我认为,您的顶级 gradle 构建文件中的这一部分是错误的:

    android { compileSdkVersion 26 buildToolsVersion '26.0.2' }

    它应该只保留在项目 gradle.build 文件中(在本例中为模块 :app)

    【讨论】:

      【解决方案2】:

      您应该从项目级别 build.gradle 中删除以下这些行,因为其中没有应用 android gradle 插件。

      android {
          compileSdkVersion 26
          buildToolsVersion '26.0.2'
      }
      dependencies {
      }
      

      它应该只在应用了 android gradle 插件的模块级 gradle 文件中。 :app在这种情况下,其中应用了android应用程序gradle插件(apply plugin: 'com.android.application'

      【讨论】:

      • 别忘了给答案点赞,这样其他人也能发现它有用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 2015-06-17
      • 2015-03-02
      • 2015-08-12
      相关资源
      最近更新 更多