Android build error: Plugin with id ‘kotlin-android‘ not found.

该博客介绍了如何修复在构建Android项目时遇到的Kotlin Android插件未找到的错误。通过在build.gradle文件中添加'org.jetbrains.kotlin.android'插件的依赖,可以解决此问题。更新后的build.gradle文件应包含最新的Kotlin版本号,例如1.6.21,并执行清理任务以删除构建目录。

Refrence

https://metapx.org/plugin-with-id-kotlin-android-not-found/


To fix the error, you need to add kotlin-gradle-plugin to your build.gradle file as shown below:

plugins {
    id 'com.android.application' version '7.1.2' apply false
    id 'com.android.library' version '7.1.2' apply false
    
    // 添加下面这一句
    id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
    
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The latest Android Studio lists the dependencies using Gradle plugins DSL as shown on Kotlin plugins for Gradle documentation.

PS F:\mom-mls-pda> npx react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 1204 file(s) to forward-jetify. Using 8 workers... info JS server already running. info Installing the app... FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ':react-native-picker_picker'. > Could not resolve all artifacts for configuration ':react-native-picker_picker:classpath'. > Could not resolve com.android.tools.build:gradle:3.2.1. Required by: project :react-native-picker_picker > Could not resolve com.android.tools.build:gradle:3.2.1. > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'. > Could not HEAD 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'. > Connect to dl.google.com:443 [dl.google.com/172.217.26.174] failed: Connection timed out: connect * 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 1m 22s error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring project ':react-native-picker_picker'. > Could not resolve all artifacts for configuration ':react-native-picker_picker:classpath'. > Could not resolve com.android.tools.build:gradle:3.2.1. Required by: project :react-native-picker_picker > Could not resolve com.android.tools.build:gradle:3.2.1. > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'. > Could not HEAD 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'. > Connect to dl.google.com:443 [dl.google.com/172.217.26.174] failed: Connection timed out: connect * 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 1m 22s at makeError (F:\mom-mls-pda\node_modules\execa\index.js:174:9) at F:\mom-mls-pda\node_modules\execa\index.js:278:16 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async runOnAllDevices (F:\mom-mls-pda\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:106:5) at async Command.handleAction (F:\mom-mls-pda\node_modules\@react-native-community\cli\build\index.js:192:9) info Run CLI with --verbose flag for more details. PS F:\mom-mls-pda>
08-12
group 'com.example.cordova_plugin' version '1.0-SNAPSHOT' buildscript { ext.kotlin_version = '1.9.22' repositories { maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/google' } google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:8.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'https://maven.aliyun.com/repository/google' } google() mavenCentral() } } apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { compileSdkVersion 34 namespace 'cordova_plugin' lintOptions { checkReleaseBuilds false // Or, if you prefer, you can continue to check for errors in release builds, // but continue the build even when errors are found: abortOnError false } compileOptions { sourceCompatibility = '17' targetCompatibility = '17' } kotlinOptions { jvmTarget = '17' } sourceSets { main.java.srcDirs += 'src/main/kotlin' main.java.srcDirs += 'src/main/java' test.java.srcDirs += 'src/test/kotlin' test.java.srcDirs += 'src/test/java' } defaultConfig { minSdkVersion 16 } dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation 'org.jetbrains.kotlin:kotlin-test' testImplementation 'org.mockito:mockito-core:5.0.0' implementation 'org.greenrobot:eventbus:3.1.1' implementation 'androidx.appcompat:appcompat:1.2.0' } testOptions { unitTests.all { useJUnitPlatform() testLogging { events "passed", "skipped", "failed", "standardOut", "standardError" outputs.upToDateWhen {false} showStandardStreams = true } } } } Execution failed for task ':cordova_plugin:compileDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction > Compilation error. See log for more details
08-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值