指定为非空的参数为空:方法com.android.build.gradle.internal.dsl.BaseAppModuleExtension.compileSdkVersion

Parameter specified as non-null is null: method com.android.build.gradle.internal.dsl.BaseAppModuleExtension.compileSdkVersion

我接手了一个前雇员的项目,过去两天我一直在努力完成它 运行。然而,我今天得到的错误花了整整一天的时间仍然无法解决。 我一直在为子项目之一的 build.gradle 中的 compileSdkVersion 指定非空参数为空。主要 build.gradle 指定了所需的 Sdk 版本,但这仍然会引发错误。

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        mavenCentral()
        jcenter()

    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.25.1'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))


android {
    signingConfigs {
        config {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }
    dataBinding {
        enabled = true
    }
    compileSdkVersion compileSdk
    defaultConfig {
        applicationId "com.cleanaway.driversapp"
        minSdkVersion minSdk
        targetSdkVersion targetSdk
        multiDexEnabled true
        
        versionCode 108400
        versionName "1.84.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.config
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }
    }
    buildTypes {
        debug {
            // Disable fabric build ID generation for debug builds
            ext.enableCrashlytics = false
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    flavorDimensions "product", "mode"
    productFlavors {
        mock {
            applicationIdSuffix = ".mock"
            dimension "mode"
        }
        dev {
            applicationIdSuffix = ".dev"
            dimension "mode"
        }
        prod {
            dimension "mode"
        }
        demo {
            applicationIdSuffix = ".demo"
            dimension "product"
        }
        cleanaway {
            dimension "product"
        }
    }
}

repositories {
    maven { url 'https://maven.fabric.io/public' }
    jcenter()
    //google()
}

kapt {
    correctErrorTypes = true
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation files('libs/evercam-stepglobal-1.0.jar')
    implementation project(':ipcameracontrol')
    implementation project(':cleanawaymodel')
    implementation project(':vehicleapi')
    implementation project(':networkutilities')
    implementation project(':telogisapi')

    //Crashlytics
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
    implementation('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
        transitive = true;
    }

    // Android/Google
    implementation "com.android.support:appcompat-v7:$rootProject.libAndroidSupportVersion"
    implementation "com.android.support:design:$rootProject.libAndroidSupportVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation "com.android.support:recyclerview-v7:$rootProject.libAndroidSupportVersion"
    implementation "com.android.support:cardview-v7:$rootProject.libAndroidSupportVersion"
    implementation "androidx.appcompat:appcompat:1.+"

    //Firebase
    implementation "com.google.firebase:firebase-core:$rootProject.firebaseVersion"
    implementation "com.google.firebase:firebase-storage:$rootProject.firebaseVersion"
    implementation "com.google.firebase:firebase-auth:$rootProject.firebaseVersion"

    // Android architecture components
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    kapt "android.arch.lifecycle:compiler:1.1.1"
    implementation 'android.arch.persistence.room:runtime:1.1.1'
    kapt "android.arch.persistence.room:compiler:1.1.1"
    implementation "android.arch.persistence.room:rxjava2:1.1.1"
    androidTestImplementation "android.arch.core:core-testing:1.1.1"
    implementation 'android.arch.lifecycle:reactivestreams:1.1.1'

    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$rootProject.kotlin_version"

    // Data binding
    kapt 'com.android.databinding:compiler:3.1.4'

    // Crash reporting
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }

    // Injection
    implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
    kapt  "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"

    // Data
    implementation "com.google.code.gson:gson:$rootProject.libGsonVersion"
    implementation "com.squareup.retrofit2:converter-gson:$rootProject.gsonConverterVersion"
    implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
    implementation "com.squareup.okhttp3:okhttp:$rootProject.libOkHttp3Version"
    implementation "com.squareup.picasso:picasso:$rootProject.libPicassoVersion"
    implementation('org.simpleframework:simple-xml:2.7.1') {
        exclude module: 'stax-api'
        exclude module: 'stax'
        exclude module: 'xpp3'
    }

    // Reactive library version 1
    implementation "io.reactivex:rxjava:$rootProject.libRxJavaVersion"
    implementation "io.reactivex:rxandroid:$rootProject.libRxAndroidVersion"

    // Reactive library version 2
    implementation 'io.reactivex.rxjava2:rxjava:2.1.1'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation "io.reactivex.rxjava2:rxkotlin:2.0.0"
    implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

    // Memory leak testing
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

    // Unit tests
    testImplementation 'junit:junit:4.12'
    testImplementation "org.robolectric:robolectric:$rootProject.libRobolectricVersion"

    // Instrumentation tests
    androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.2'
    androidTestImplementation 'com.android.support.test.espresso.idling:idling-concurrent:3.0.2'

    // Mocking
    testImplementation 'org.mockito:mockito-core:2.9.0'

    // Logging
    implementation 'com.jakewharton.timber:timber:4.6.0'

    // Time and Date
    implementation 'joda-time:joda-time:2.9.9'
    implementation files('libs/commons-lang-2.6.jar')
}

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xmaxerrs" << "500" // or whatever number you want
    }
}

apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'

这是子build.gradle的代码。

这是我收到的错误消息。

  • Where: Build file 'D:\xxx\cleanaway-myview-app\driversapp\build.gradle' line: 39

Parameter specified as non-null is null: method com.android.build.gradle.internal.dsl.BaseAppModuleExtension.compileSdkVersion, parameter version

以下字段没有意义:

compileSdkVersion compileSdk
minSdkVersion minSdk
targetSdkVersion targetSdk

我认为有人误解了compileSdkVersion可以替换为compileSdk的说明。因为你需要把实际数字放在那里,例如

compileSdkVersion 31
minSdkVersion 28
targetSdkVersion 31

这是老办法。新方式

compileSdk 31
minSdk 28
targetSdk 31

不确定旧方法是否仍然有效。无论如何,您都需要将实际数字放在那里。您的项目想要哪些取决于您。 compileSdk 和 targetSdk 通常最好使用尽可能高的版本,minSdk 是您要支持的最低 android 版本。

另见