I am getting the following error suddenly while building Ionic 3 app for Android.
Could not find org.jetbrains.kotlin:ko
None of the above worked for me. I ended up removing the google-services plugin and add it.
cordova plugin rm cordova-support-google-services
cordova plugin add cordova-support-google-services
In my case I had the same error first, then a whole bunch of other packages (org.ow2.asm:asm-analysis:4.0@jar, etc...) that could also not be resolved.
The problem was that I upgraded Gradle to v5 (to be able to support the new version of Crashlytic). Doing so, I upgraded the repository to Google(), and deleted the old maven { url ... } entries.
But I also deleted jcenter(), which was still required for a lot of nodes.
Now my repository section looks like this:
buildscript {
repositories {
maven { url "$rootDir/../node_modules/react-native/android" }
google() // Google Maven repository
jcenter()
}
//...
So if someone else is reading this but was not happy with the current accepted solution of downgrading Gradle, check if you have jcenter().
Ps.: I realize this is an old issue but I recently found it while searching on google.
The problem lies in the cordova-support-google-services plugin for Cordova.
This plugin's build.gradle
looks like this as of today (October 24th, 2019):
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:4.2.0'
}
More exactly the problem lies in this dependency:
classpath 'com.android.tools.build:gradle:+'
That is an extremely brittle way of specifying dependencies. The '+' sign here means "fetch the most recent version available in the repo".
If a newer version is published in the repo, and it breaks the build, then everyone with this plugin has their projects broken.
This happened today. The broken version that is being fetched is com.android.tools.build:gradle:4.0.0
. It requires some Kotlin stuff.
That is why you need to ALWAYS freeze dependencies to reliably build your project. Never trust the newer stuff. This dependency compiles fine just as it did yesterday:
classpath 'com.android.tools.build:gradle:3.5.1'
For those using Cordova or Ionic, you can make a quick fix to be able to build the project by freezing the dependency in the file:
<projectroot>/platforms/android/cordova-support-google-services/<project>-build.gradle
This is not a definitive solution though. If you reinstall the android platform via Cordova the error will show up again. The project maintainer should either freeze the dependency or fix it to support gradle 4.0.0. In the meantime just use a fixed fork of this plugin.
cordova-support-google-services was updated today to version 1.3.2 which changes the classpath from
classpath 'com.android.tools.build:gradle:+'
to
classpath 'com.android.tools.build:gradle:3.+'
which seems to fix the kotlin error
I got mine to build successfully by doing the following:
I edited platforms->android->cordova-support-google-services->myAppName-build.gradle
and changed
maventCentral()
to
maven { url "https://maven.google.com" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
That solved the kotlin error then I was getting a different error that I resolved by changing
classpath 'com.google.gms:google-services:4.2.0'
to
classpath 'com.google.gms:google-services:4.1.0'
It then built successfully.
As a further temporary fix to follow-up on the suggestion from @MisterSmith, use a hook to re-apply the lock:
<hook src="scripts/fix_android_dep.sh" type="after_platform_add"/>
with this overly wordy bash code:
#!/usr/bin/env bash
## temporary fix for android studio EAP issue
## SOURCE: https://stackoverflow.com/a/58536638/56545
if [ -d "platforms/android/cordova-support-google-services" ]; then
file="platforms/android/cordova-support-google-services/app-build.gradle"
from="classpath 'com.android.tools.build:gradle:+'"
to="classpath 'com.android.tools.build:gradle:3.5.1'"
change=`sed "s/$from/$to/" < "$file"`
echo "$change" > "$file"
fi
in my project i fix like this.(my project in kotlin)
buildscript{
repositories {
google()
jcenter()
......
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
}
allprojects {
repositories {
google()
jcenter()
......
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
}