85

I am getting the following error suddenly while building Ionic 3 app for Android.

Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.60-eap-25

We have one solution from Android Studio here but after I did change in my build.gradle with the following code I am still getting the error.

buildscript {
    repositories {
        ...
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
    }
}

allprojects {
    repositories {
        ...
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
    }
}

My build.gradle file looks like this after I updated my Cordova and added the above solution.

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
    }

    dependencies {
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
    }

    //This replaces project.properties w.r.t. build settings
    project.ext {
      defaultBuildToolsVersion="28.0.3" //String
      defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
      defaultTargetSdkVersion=28 //Integer - We ALWAYS target the latest by default
      defaultCompileSdkVersion=28 //Integer - We ALWAYS compile with the latest by default
    }
}

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

Still the same error.

Laurel
  • 5,965
  • 14
  • 31
  • 57
Tapas Mukherjee
  • 2,088
  • 1
  • 27
  • 66

9 Answers9

77

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.

Mister Smith
  • 27,417
  • 21
  • 110
  • 193
  • As we are talking about a temporary solution, this is the quickest and explanatory solution for me. Thanks – Tapas Mukherjee Oct 24 '19 at 17:43
  • I have a question though. If my app is already built and it is installed in phone, can using the '+' in dependencies break of effect the app? There are lot of dependencies in an app and it is difficult to maintain the version of all of them. – Tapas Mukherjee Oct 24 '19 at 17:46
  • for a temporary base, this solution is best. Thanks – Abhishek Pandya Oct 25 '19 at 04:55
  • 1
    I compile my app using Phonegap Build; I get the same error, although I do not have included the plugin 'cordova-support-google-services'. Any suggestions? In particular, how can I fix this in my config.xml file? – pmkruyen Oct 26 '19 at 09:46
  • 1
    @peterk here a fix for phonegap build https://community.adobe.com/t5/PhoneGap/Android-build-error-quot-Could-not-find-org-jetbrains-kotlin/td-p/10691079 – r1si Oct 26 '19 at 11:12
  • 3
    The plugin cordova-support-google-services has already released a new version ^1.3.2, where he freezes the dependencies fixing the problem. The answers should be update to reflect this. – le0diaz Nov 07 '19 at 04:35
  • For ionic then just remove platform android, then remove the plugin (then it will not complain about conflicts), then reinstall again and it will work – Stefan Rein Nov 13 '19 at 15:07
30

EDIT 10/28/19:

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

Original Answer

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.

DanielRead
  • 2,288
  • 1
  • 23
  • 34
  • had to change << to doLast in platforms/android/app/build.gradle, according to https://stackoverflow.com/a/55793096/2393822 – umadesign Oct 24 '19 at 11:50
  • 2
    @JimBergman I got the kotlin URL from the official Android Studio website: reference https://androidstudio.googleblog.com/2019/10/android-studio-40-canary-1-available.html – DanielRead Oct 24 '19 at 15:27
  • 1
    Scroll down to section titled "Known issue for Missing Kotlin Maven repo" – DanielRead Oct 24 '19 at 15:28
  • @DanielRead thanks I see that now. Still don't think referencing files in bintray.com is the way to workaround the problem. The solution by Mister Smith above is much better. – Jim Bergman Oct 24 '19 at 16:45
  • Not sure if this error is exclusive to **google-services** – IgorGanapolsky Oct 24 '19 at 20:50
  • The edited answer should be the correct answer; the plugin has been updated. Manually changing generated build files is not a solution when you are using automated builds. – Johan Nov 01 '19 at 14:32
  • 1
    To update the plugin, run: `cordova plugin rm cordova-support-google-services --force && cordova plugin add cordova-support-google-services` – Klemens Zleptnig Nov 06 '19 at 11:37
  • The Kotlin EAP maven repository part was very important. Thanks – Mehdi Haghgoo Nov 09 '19 at 13:58
  • !! Heads up - just changing the `classpath` to `3+` did the trick for me (works with both the `.` and without) – Jacksonkr Nov 20 '19 at 17:18
29

Here is the solution.

The problem was exactly the maven repository (here), but the issue was with the build.gradle from the cordova-support-google-services plugin, so I added the required line and everything is ok now, I've already created a pull request to the original repo (here). But in the meantime you can do what I did, just replace in the package.json the current versión with my repo:

Before:

...
"cordova-support-google-services": "^1.3.1",
...

After:

...
"cordova-support-google-services": "https://github.com/LuisEGR/cordova-support-google-services.git",
...

after that you will have to:

  • Remove folders platforms and plugins
  • run npm install

This is a temporal solution while the pull request to the main repo gets accepted and the npm package updated

and that's it, now you can build your project again.


I'm using Ionic 4, and some plugins require cordova-support-google-services, in case you don't have it in your package.json the error could be with another plugin, if so please add the package.json so we can find out which one is the problem.


UPDATE 24/OCT:

I've changed the solution in my repo as many of you suggested, now the solution consinst just in fixing the dependency: from: com.android.tools.build:gradle:+ to classpath com.android.tools.build:gradle:3.+, this is already in my repo if you want to see what's changed

Luis Gonzalez
  • 531
  • 5
  • 16
7

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' }
   }
}
Ven Ren
  • 1,584
  • 1
  • 13
  • 24
6

Solution for ionic v3 and cordova

@Mister Smith solution solved my problem

you have to go to the file

platforms/android/cordova-support-google-services

then

Replace

classpath 'com.android.tools.build:gradle:+'

by

classpath 'com.android.tools.build:gradle:3.5.1'

@Alternative solution I have found is to

setup kotlin in your system :)
Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
  • It works. Thank you. I think we can set the version same to the version from build.gradle file – Nguyen Tran Nov 07 '19 at 08:26
  • 1
    @NguyenTran I think setting up Kotlin in your system with the android studio is the most advanced and best solution if you want to use the latest Gradle, otherwise, stick to the older version gradle supported by your project. or look for the best gradle support for ionic v3. – Sayed Mohd Ali Nov 07 '19 at 08:31
5

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
Greg Haygood
  • 958
  • 8
  • 11
3

I had to add maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } both into the top-level build.gradle and into the app module build.gradle. In both cases both into the buildscripts.repositories and in allprojects.repositories

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
2

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

  • This is the only answer that actually solved the issue. Removing and adding the plugin corrects everything that should be corrected on the build.gradle file. – Felipe Ferri Nov 18 '19 at 18:35
0

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.

FMaz008
  • 11,161
  • 19
  • 68
  • 100