Android更新后出现Gradle同步错误(未指定compileSdkVersion)

3

我有一个项目。在更新版本3.2.1之前,它的工作非常好。当尝试同步gradle项目时,我遇到了一些错误,但我可以解决。但我有一个问题找不到解决方法。这是我的build.gradle文件。

apply plugin: 'com.android.application'

android {
compileSdkVersion 28

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

buildToolsVersion '28.0.3'
useLibrary 'org.apache.http.legacy'

defaultConfig {
    applicationId "com.xxx.xxx"
    minSdkVersion 15
    targetSdkVersion 28
    multiDexEnabled true
    versionCode 7x
    versionName "1.0.7x"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
    exclude group: 'com.squareup.okhttp3', module: 'okhttp'
}
lintOptions {
    checkReleaseBuilds false
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation files('libs/json_simple-1.1.jar')
implementation('com.omertron:themoviedbapi:4.2') {
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    exclude module: 'junit'
}
implementation 'com.android.support:multidex:1.0.3'
implementation files('libs/okhttp-3.8.1.jar')
implementation files('libs/okio-1.13.0.jar')
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
//noinspection UseOfBundledGooglePlayServices
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.googlecode.libphonenumber:libphonenumber:7.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.wang.avi:library:2.1.3'
implementation 'com.baoyz.swipemenulistview:library:1.3.0'
implementation 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
implementation 'javax.mail:mail:1.5.0-b01'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.github.orangegangsters:swipy:1.2.3@aar'
implementation 'io.michaelrocks:libphonenumber-android:8.9.0'
implementation 'com.github.joielechong:countrycodepicker:2.1.5'
testImplementation 'junit:junit:4.12'
implementation files('libs/xxx.jar')
}

apply plugin: 'com.google.gms.google-services'

And :

    // Top-level build file where you can add configuration options common to 
     all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.1.0'
    }
}

allprojects {
    apply plugin: 'com.android.application'
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        maven{
            url "https://jitpack.io"
        }
        google()
    }
}

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

顺便提一下,我找到了这个链接: Gradle同步失败:原因是未指定compileSdkVersion 但是,它已经没有帮助了。所以,有人可以帮助我吗?


1
为什么你在 allprojects {} 中使用了 apply plugin: 'com.android.application' - shizhen
我认为这就是我们要找的重点。在我注释掉这行代码之后,重新构建工作正常。 - TheZero
很高兴听到你终于让它工作了。 - shizhen
是的。不过,非常感谢你花了这么多时间帮助我,哈哈。 - TheZero
1个回答

1
  1. change targetSdkVersion to 28 and change all your compile to implementation
  2. make sure that your top level build.gradle has the proper google() repo configured. E.g.

    repositories {
        google() // be the first one. 
        jcenter()
    }
    

我的相关答案在这里:https://dev59.com/e1UK5IYBdhLWcg3w9jnb#51151050


哎呀,我忘记了。但是,即使我更改了它,它仍然出错。有什么好的想法吗? - TheZero
你能否更新你的问题并提供更新后的 build.gradleapp/build.gradle 文件? - shizhen
嗯,不能这样做...或者将这个 maven { url "https://maven.google.com" } 移动到 repositories 的两个位置中的第一个。 - shizhen

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