android studio error java.lang.NullPointerException: Cannot get property 'kotlin_version' on null object when i try to build

Viewed 541

i just learnt kotlin and im trying to put my skills to practice, i created a new project and even implemented firebase authentication, now i try to creaate a new activity and im getting
java.lang.NullPointerException: Cannot get property 'kotlin_version' on null object

Error on build console. i have tried to get similar questions though none was very directly related to mine.

This is how my top level gradle file looks like:

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

buildscript {
    ext.kotlin_version = '1.3.72'
    repositories {
        google()
        jcenter()        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.google.firebase:perf-plugin:1.3.1'

         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    
    }
}

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

This is my app level gradle file:

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

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.example.findmyapartment"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)


    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8 kotlin_version
        targetCompatibility JavaVersion.VERSION_1_8 kotlin_version
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }


    viewBinding {
        enabled = true
    }


}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7: $kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.3.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.annotation:annotation:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
    implementation 'com.google.firebase:firebase-analytics-ktx:17.4.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.firebase:firebase-auth-ktx:19.3.2'
    implementation 'com.google.firebase:firebase-firestore-ktx:21.5.0'
    implementation 'com.google.firebase:firebase-storage-ktx:19.1.1'
    implementation 'com.google.firebase:firebase-perf:19.0.6'
    implementation 'com.google.firebase:firebase-messaging:20.1.5'
    implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.5'
    implementation "androidx.fragment:fragment-ktx:1.3.0-alpha04"
    debugImplementation "androidx.fragment:fragment-testing:1.3.0-alpha04"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply plugin: 'com.google.gms.google-services'

with that i'm convinced my kotlin configuration is done fine by android studio itself and i havent added any updates or pluggins. i will appreciate if somebody helps me.

0 Answers
Related