Search code examples
javakotlinandroid-studiogradle

Plugin [id: 'kotlin-android', version: '1.7.10'] was not found in any of the following sources in Android Studio for Flutter


I'm currently really struggling with my Android studio Flutter setting. It updated automatically and ever since this moment I'm trying to run the debugging and the emulator again. Right now I receive the error below. Does anyone have Tipps how to solve the Gradle issue? e.g. reinstall or do settings somewhere? I thankful for any advice This is the error:

  • Where: Build file /android/app/build.gradle' line: 15

  • What went wrong: Plugin [id: 'kotlin-android', version: '1.7.10'] was not found in any of the following sources:

  • Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/8.0/userguide/plugin_reference.html for available core plugins)
  • Included Builds (None of the included builds contain this plugin)
  • Plugin Repositories (could not resolve plugin artifact 'kotlin-android:kotlin-android.gradle.plugin:1.7.10') Searched in the following repositories: Google MavenRepo Gradle Central Plugin Repository
   repositories {
       google()
       mavenCentral()
   }
   dependencies {
       classpath 'com.android.tools.build:gradle:8.0.0'
       classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
      
   }
}

plugins {
   id "com.android.application" version "8.0.0"
   id "kotlin-android" version "1.7.10"
  id "dev.flutter.flutter-gradle-plugin"
}

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

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

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

android {
   compileSdkVersion 33
   ndkVersion flutter.ndkVersion

   compileOptions {
       sourceCompatibility JavaVersion.VERSION_17
       targetCompatibility JavaVersion.VERSION_17
   }

   kotlinOptions {
       jvmTarget = '17'
   }

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

   defaultConfig {
       applicationId "com.example.esosba_app"
       minSdkVersion 21
       targetSdkVersion flutter.targetSdkVersion
       versionCode flutterVersionCode.toInteger()
       versionName flutterVersionName
       multiDexEnabled true
   }

   buildTypes {
       release {
           signingConfig signingConfigs.debug // TODO: Hier sollte ein Signatur-Konfigurationsblock angefügt werden.
       }
   }
}

flutter {
   source '../..'
}

dependencies {
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10"

  
}

Solution

  • The plugin id kotlin-android is only for use when the Kotlin Gradle plugin is already on the build classpath. When you are pulling it directly from the repository (as here), then you should use the id org.jetbrains.kotlin.android.

    So apply the Kotlin Android plugin in the plugins block with:

    id "org.jetbrains.kotlin.android" version "1.7.10"
    

    You may like to read my answer last month which discusses the referencing of this plugin in more detail.