Home > Software engineering >  Please help me with the error on my android studio gradle
Please help me with the error on my android studio gradle

Time:07-01

The error I have is as following Build file 'C:\Users\beant\AndroidStudioProjects\Assignment2\app\build.gradle' line: 20

A problem occurred evaluating project ':app'.

Could not find method compileOptions() for arguments [build_6n6x43n1zzaoft7p0zvdqvss8$_run_closure2@6e0f90a8] on project ':app' of type org.gradle.api.Project.

Here's the code

 plugins {
     id 'com.android.application'} android {
   compileSdk 32

defaultConfig {
    applicationId "com.example.assignment2"
    minSdk 21
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    }


compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}


dependencies {

implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'}

CodePudding user response:

It seems compileOptions is not in the android {}

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    } 
}

CodePudding user response:

Try this code inside your module level gradle file:

 plugins {
     id 'com.android.application'} 
android {
   compileSdk 32

defaultConfig {
    applicationId "com.example.assignment2"
    minSdk 21
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    


compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

compileOptions must come under android{}.

  • Related