在更新到Android Studio 3.1时,我收到此错误
Android Gradle插件无法识别SourceSet'defaultConfig'。也许你拼错了什么?
构建gradle
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.google.gms:google-services:3.1.1'
// classpath 'com.android.tools.build:gradle:2.3.3'
//classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
apply plugin: 'android'
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'com.github.barteksc:android-pdf-viewer:2.7.0'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.google.android.gms:play-services-gcm:12.0.1'
}
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
//buildToolsVersion "21.1.2"
// useLibrary 'org.apache.http.legacy'
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
defaultConfig {
applicationId "com.mpathway.xxxx"
minSdkVersion 14
targetSdkVersion 27
versionCode 2
versionName "2.0"
}
// Move the tests to tests/java, tests/res, etc...
// instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
}
apply plugin: 'com.google.gms.google-services'
我在编译时收到警告,即使我删除了defaultconfig错误
有人可以帮我解决这个问题吗?让我知道如何替换它 谢谢
答案 0 :(得分:1)
您有多个defaultConfig
个关闭。理想情况下,只有一个。
无论如何,defaultConfig
直接位于android
闭包内,而不是sourceSets
闭包内。