error: annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations)

Pedram Davoodi :

I'm new to android and I build my first test project in android studio but get this error

Java compiler

error: annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)

how should i fix it?

This is the Error

And this is my gradle

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

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        // 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
}

Vivekanandan :

I also had the same issue, the problem was that mysourceCompatibility and targetCompatibility in compileOptions were pointing to kotlin_version set them to your correct java versions in your project level build.gradle file.

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "x.y.z"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    buildToolsVersion = '28.0.3'
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=305457&siteId=1