【问题标题】:Gradle sync error after android update (compileSdkVersion is not specified)android更新后Gradle同步错误(compileSdkVersion未指定)
【发布时间】:2019-03-28 08:51:25
【问题描述】:

我有一个项目。它在更新版本 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'

还有:

    // 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 sync failed: Cause: compileSdkVersion is not specified 但是,它已经没有帮助了。那么,任何人都可以帮助我吗?

【问题讨论】:

  • 为什么apply plugin: 'com.android.application' 里面有allprojects {}?
  • 我认为这是我们寻找的重点。在我评论这一行之后。重建工作良好
  • 很高兴听到你终于成功了。
  • 是的。 Anw,非常感谢你,当花太多时间帮助我时,大声笑

标签: java android android-studio androidx


【解决方案1】:
  1. 将 targetSdkVersion 更改为 28 并将所有 compile 更改为 implementation
  2. 确保您的顶级 build.gradle 配置了正确的 google() 存储库。例如。

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

我的相关答案在这里:https://stackoverflow.com/a/51151050/8034839

【讨论】:

  • 见鬼。我忘记了。但是,在我改变之后。它仍然是错误的。有什么理想吗?
  • 可以用您更新的build.gradle 和app/build.gradle 更新您的问题吗?
  • hmm,不能是...或者移动这个maven { url "https://maven.google.com" }成为repositories两个地方的第一个
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-29
  • 1970-01-01
  • 2019-06-25
  • 2019-07-18
  • 2023-01-26
  • 1970-01-01
  • 2015-03-02
相关资源
最近更新 更多