【问题标题】:Gradle DSL method not found: 'compile()' using Twitter sdk未找到 Gradle DSL 方法:使用 Twitter sdk 的“compile()”
【发布时间】:2017-10-13 06:48:06
【问题描述】:

我现在有其他一些人,他们提出了这种问题,但所有这些解决方案都对我不起作用。我只在项目中添加了 twitter sdk,没有其他内容。 请帮帮我

Android gradle build Error:(9, 0) Gradle DSL method not found: '编译()'。

同步 Build.Gradle 时出现错误“找不到 Gradle DSL 方法:'compile()'”

我的build.gradle 代码在这里

buildscript {
    repositories {
        jcenter()

    }
    dependencies {


        classpath 'com.android.tools.build:gradle:2.3.3'
            compile 'com.twitter.sdk.android:twitter:3.1.1'
            compile 'com.twitter.sdk.android:twitter-mopub:3.1.1'
            compile 'com.twitter.sdk.android:twitter-core:3.1.1'
            compile 'com.twitter.sdk.android:tweet-ui:3.1.1'
            compile 'com.twitter.sdk.android:tweet-composer:3.1.1'
            compile 'com.twitter.sdk.android:twitter-mopub:3.1.1'

        }

    }

    allprojects {
        repositories {
            jcenter()

        }
    }

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

    }

【问题讨论】:

    标签: android twitter android-gradle-plugin


    【解决方案1】:

    我猜你在你的根 build.gradle 和应用程序的 build.gradle 之间搞混了。

    您至少应该从应用程序 Gradle 配置的 dependencies { ... } 中删除 classpath 'com.android.tools.build:gradle:2.3.3'(通常是 app/build.gradle)。 然后你应该检查你的根build.gradle。它应该看起来像:

    // 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'
            // 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
    }
    

    然后您需要将以下依赖项添加到应用程序的 Gradle 配置(通常为 app/build.gradle)中,如 official docs 中所述

    dependencies {
      compile 'com.twitter.sdk.android:twitter:3.1.1'
      compile 'com.twitter.sdk.android:twitter-mopub:3.1.1'
    }
    

    【讨论】:

    • 您至少有 2 个build.gradle 文件。你能发第二个build.gradle吗?
    • 谢谢你解决了我的问题。问题是我没有第二个 build.grade (不知道为什么)。所以我建立了一个新项目并且它有效,我将发布漏洞代码。
    【解决方案2】:

    第一个 build.gradle

     apply plugin: 'com.android.application'
    
        android {
            compileSdkVersion 26
            buildToolsVersion "25.0.3"
            defaultConfig {
                applicationId "com.twitter.ratz.william.test"
                minSdkVersion 19
                targetSdkVersion 26
                versionCode 1
                versionName "1.0"
                testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            }
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
            }
        }
    
        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
                exclude group: 'com.android.support', module: 'support-annotations'
            })
            compile 'com.android.support:appcompat-v7:26.+'
            compile 'com.android.support.constraint:constraint-layout:1.0.0-beta3'
            compile 'com.twitter.sdk.android:twitter:3.1.1'
            compile 'com.twitter.sdk.android:twitter-mopub:3.1.1'
            testCompile 'junit:junit:4.12'
        }
    

    第二次构建.gradle

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.3'
    
            // 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-19
      • 2015-02-21
      • 2015-03-24
      • 2017-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多