13

I am trying to place advertising in my flutter app, this is proving to be almost more complicated for me than creating the app itself (I am a newbie dev starting with flutter).

I get an error when I try to launch my app that says the following: [!] Your project requires a newer version of the Kotlin Gradle plugin. Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then update C:\Users\User\Desktop\Dev\adtest\android\build.gradle: ext.kotlin_version = '' Exception: Gradle task assembleDebug failed with exit code 1

The problem seems simple, I have to update the field suggested by the console. My surprise is that the field ext.kotlin_version = " ", does not exist in my build.grade file on android/build.gradle. Neither does the buildscript { } apatagate exist that should contain it. I have android Studio installed, Flutter updated, I work with visual studio code, everything is apparently correct, except for this.

Thanks for your help.

bluehat77
  • 143
  • 1
  • 1
  • 5

8 Answers8

17

Add ext.kotlin_version and kotlin dependency in <app>/android/build.gradle file.

buildscript {
    ext.kotlin_version = '1.5.0' //use latest
    ...
}

dependencies { 
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    ...
}
noam aghai
  • 1,364
  • 3
  • 18
  • 30
ZeroZero1
  • 214
  • 1
  • 4
7

Official Website link for getting latest version you can see <project_name>/android/build.gradle

buildscript {
ext.kotlin_version = '1.6.21'
repositories {
    google()
    jcenter()
}

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

}

You can find here

amirul
  • 380
  • 4
  • 11
2

Copy and paste. ext.kotlin_version = '1.4.32' On location: android/

VelozX
  • 21
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 07 '22 at 10:21
  • This solution works perfectly. The info in the answer is to be posted in build.gradle. With time this might be updated, just find the latest Kotlin version. – Huthaifa Muayyad Jan 17 '22 at 11:45
2

Kotlin releases Here you can find latest kotlin version. Just copy and paste version to your android/build.gradle

Pranav Dave
  • 393
  • 5
  • 7
1

Update kotlin version to '1.4.32'.

Copy and paste ext.kotlin_version = '1.4.32' On Project-level build.gradle(/build.gradle)

JuniorBOMB
  • 336
  • 1
  • 3
  • 11
1

visit this site to get the latest version of the kotlin gradle: https://kotlinlang.org/docs/gradle.html#plugin-and-versions

Then, go to <project_name>/android/build.gradle and NOT <project_name>/android/app/build.gradle

buildscript {

ext.kotlin_version = '1.6.21' //use latest version

}

Carl Py
  • 21
  • 2
0

Step 1: Open your project on android studio and go to Tools->kotlin->"Configure kotlin plugin updates", update and ensure you apply changes.

Step 2: navigate to your flutter project_folderName/android/build.grade file and change

buildscript {

ext.kotlin_version = 'the version you updated to'

}

step 3: build and debug your project.

-1

I was facing the same error and resolved it by this method. I hope this will also for you. Just follow these steps

  • open your terminal
  • run -> dart pub outdated (it will show you all outdated versions of the project)
  • run -> dart pub upgrade --major-versions
  • restart your android studio
Syed Vkax
  • 16
  • 2