Getting "Failed to apply plugin [id 'kotlin-android']" when trying Flutter hello world code
8,174
Okay, found solution here: https://github.com/react-native-community/react-native-webview/issues/1407#issuecomment-634436481
I had to edit the <project-folder>/android/app/build.gradle
file. I've replaced the line
ext.kotlin_version = '1.3.50'
with this
ext.kotlin_version = '1.3.72'
and then ran flutter run
.
Author by
sarwar47
Updated on December 23, 2022Comments
-
sarwar47 over 1 year
I was trying the hello world code of flutter. I was following the official doc from here.
Flutter Version: flutter_linux_1.20.1-stable
I've created flutter project and hit run:
flutter create myapp cd myapp flutter run
But it threw this error message:
Launching lib/main.dart on R40 in debug mode... FAILURE: Build failed with an exception. * Where: Build file '/home/sjs/flutter-projects/myapp/android/app/build.gradle' line: 25 * What went wrong: A problem occurred evaluating project ':app'. > Failed to apply plugin [id 'kotlin-android'] > Could not create an instance of type org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension. > Could not generate a decorated class for class org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension. > org/jetbrains/kotlin/gradle/plugin/KotlinTarget * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 18s Running Gradle task 'assembleDebug'... Running Gradle task 'assembleDebug'... Done 22.1s Exception: Gradle task assembleDebug failed with exit code 1
Here is the build.gradle file located in '/home/sjs/flutter-projects/myapp/android/app/':
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" android { compileSdkVersion 28 sourceSets { main.java.srcDirs += 'src/main/kotlin' } lintOptions { disable 'InvalidPackage' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.myapp" minSdkVersion 16 targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }
Here is the
flutter doctor -v
output:[✓] Flutter (Channel stable, 1.20.1, on Linux, locale en_US.UTF-8) • Flutter version 1.20.1 at /home/sjs/flutter • Framework revision 2ae34518b8 (2 days ago), 2020-08-05 19:53:19 -0700 • Engine revision c8e3b94853 • Dart version 2.9.0 [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at /home/sjs/Android/Sdk • Platform android-30, build-tools 30.0.1 • Java binary at: /home/sjs/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Android Studio (version 4.0) • Android Studio at /home/sjs/android-studio • Flutter plugin version 48.0.2 • Dart plugin version 193.7361 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] Connected device (1 available) • R40 (mobile) • 00114604032517 • android-arm • Android 9 (API 28) • No issues found!