我现在有一些其他人,他们提出了这样的问题,但所有这些解决方案都不适用于我。我只在项目中添加了twitter sdk。 请帮帮我
Android gradle build错误:(9,0)未找到Gradle DSL方法: '编译()'
获取错误“未找到Gradle DSL方法:'compile()'”同步Build.Gradle
我的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
}
答案 0 :(得分:1)
我猜你的根build.gradle
和应用build.gradle
之间的混乱。
至少应该从应用程序的Gradle配置classpath 'com.android.tools.build:gradle:2.3.3'
中删除dependencies { ... }
(通常是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'
}
答案 1 :(得分:1)
First 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'
}
第二次build.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
}