skip to Main Content

I am getting error whenever I am trying to make an apk of the program saying I need a newer version of gradle. I went and changed my gradle file but it is still giving me the same error.

Error: Your project requires a newer version of the Kotlin Gradle plugin.                                 │
│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then update the  │
│ version number of the plugin with id "org.jetbrains.kotlin.android" in the plugins block of            │
│ D:Ebexsofthomecoandroidsettings.gradle.                                                            │
│                                                                                                        │
│ Alternatively (if your project was created before Flutter 3.19), update                                │
│ D:Ebexsofthomecoandroidbuild.gradle                                                                │
│ ext.kotlin_version = '<latest-version>'

My gradle file

buildscript {
    ext.kotlin_version = '2.0.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

Another error it is giving me is

Error: A problem occurred evaluating project ‘:app’.

Could not find method Properties() for arguments [] on project ‘:app’ of type org.gradle.api.Project.

The gradle.build file where it is showing is

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 34
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.quomodosoft.online.homeco"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 21
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }


}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

How do i fix the errors and make the apk?

2

Answers


  1. Chosen as BEST ANSWER

    The problem was solved. I had to copy and paste the whole android folder from an older (working) version of the project and now it is working fine.


  2. settings.gradle

    pluginManagement {
        def flutterSdkPath = {
            def properties = new Properties()
            file("local.properties").withInputStream { properties.load(it) }
            def flutterSdkPath = properties.getProperty("flutter.sdk")
            assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
            return flutterSdkPath
        }()
    
        includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
    
        repositories {
            google()
            mavenCentral()
            gradlePluginPortal()
        }
    }
    
    plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        id "com.android.application" version "7.3.0" apply false
        id "org.jetbrains.kotlin.android" version "1.9.20" apply false
    }
    
    include ":app"
    

    build.gradle

    buildscript {
        ext.kotlin_version = '1.9.20'
        repositories {
            google()
            mavenCentral()
        }
    
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.android.tools.build:gradle:7.3.0'
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    tasks.register("clean", Delete) {
        delete rootProject.buildDir
    }
    

    In app-> build.gradle : This at top

    plugins {
        id "com.android.application"
        id "kotlin-android"
        id "dev.flutter.flutter-gradle-plugin"
    }
    ```
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search