37

After I am running ionic cordova build android I get this error:

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':debugCompileClasspath'.
> Could not find runtime.jar (android.arch.lifecycle:runtime:1.0.0).
  Searched in the following locations:
  https://jcenter.bintray.com/android/arch/lifecycle/runtime/1.0.0/runtime-1.0.0.jar

And it is right. When I go to this URL https://jcenter.bintray.com/android/arch/lifecycle/runtime/1.0.0/runtime-1.0.0.jar I get an 404 Not found error as a JSON.

I don't see any android/ cordova specific versions in that URL so I can't say its from my cordova installation.

Cordova version: 7.1.0

Ionic info:

cli packages: (C:\Users\%User%\AppData\Roaming\npm\node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : not installed // this is strange. I can run cordova in my terminal tho

local packages:

    @ionic/app-scripts : 3.1.8
    Cordova Platforms  : android 6.4.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    Node              : v8.4.0
    npm               : 5.3.0
    OS                : Windows 10

Environment Variables:

    ANDROID_HOME : C:\Users\%User%\AppData\Local\Android\Sdk

Misc:

    backend : pro

Also, I don't have any cordova-android folders in C:\Users\%USER%\.cordova\lib\npm_cache (I don't know if this helps. I saw people talking about this folder)

What's the problem here? Where is that URL coming from? How can I change it and with what can I change it?

If I cannot solve this easily there is one last step to do: remove and install everything again.

Thank you!

noamtm
  • 12,435
  • 15
  • 71
  • 107
Ionel Lupu
  • 2,695
  • 6
  • 29
  • 53

9 Answers9

20

A quick temporary fix is to include the google maven repo in your top level gradle file.

allprojects {
  repositories {
      mavenLocal()
      maven { url 'https://maven.google.com' } // <-- add this!
      jcenter()
Moritz
  • 1,590
  • 13
  • 8
  • Yes it's a great solution and it's logic. Bintray has a problem with the lib, so download from another host. Thanks – Vincent Menant May 28 '18 at 10:55
  • https://jcenter.bintray.com/android/arch/lifecycle/runtime/1.0.0/runtime-1.0.0.jar This is the repo its looking for. Any alternate solution.? – JItendra Rana May 28 '18 at 11:03
  • 1
    @JItendraRana: make sure you edit your-react-native-project/android/build.gradle and add the new line before jcenter and in the allprojects group. – Moritz May 28 '18 at 11:08
  • After trying this, gradle is unable to find following file `https://jcenter.bintray.com/com/android/tools/build/aapt2-proto/0.1.0/aapt2-proto-0.1.0.jar` - some dependency for `react-native-firebase` – David Novák May 28 '18 at 11:59
  • I am working on a react-native project now I can build the project but can't start the app it prompts "Unfortunately, app has stopped" – Piyush Patel May 28 '18 at 12:00
  • The order here is very important. Make sure that `jcenter()` comes **after** `maven`. Otherwise, it will try `jcenter()` first and keep failing. – Joshua Pinter Jun 08 '18 at 20:21
13

For me AIT MANSOUR and Moritz answers didn't work, because I had other dependencies that required jcenter() and jitpack, additionally, for react-native you need the node_modules.

So, my solution for react-native is

allprojects {
    repositories {
        // this is for native modules I'm developing
        mavenLocal()
        // for modules depending on jitpack.io
        maven { url "https://jitpack.io" }
        // add this one
        maven {
            url "https://maven.google.com"
        }
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
        // keep this at the end
        jcenter()
    }
}
Computer's Guy
  • 5,122
  • 8
  • 54
  • 74
  • 2
    This is the only solution that worked for me with react-native. Use npm packages they said, it's easy they said. Wasted HOURS with this!! Thanks octohedron! – Quintonn May 28 '18 at 12:20
  • 1
    Worked like a treat. By ordering your repositories like this you're essentially pulling libraries from Maven first, then your local node_modules directory and then anything that's not in those two will be pulled from jcenter. Thanks! – Joshua Pinter Jun 08 '18 at 20:16
  • Btw, here is a link to a popular Github Issue on the same error: https://github.com/zo0r/react-native-push-notification/issues/748 – Joshua Pinter Jun 08 '18 at 20:25
6

I solved the problem (at least for me).

It seems that the jcenter has some issues providing the libraries for the project(it may be temporary). As people suggested here, you can solve this by getting those libraries from maven.

Go to your build.gradle file (for ionic devs it is in /platforms/android) and add above every line of code where says jcenter() this line maven { url 'https://maven.google.com' }.

For me it was is two places: buildscript and allprojects. At the end the top of your build.gradle file should look like this:

apply plugin: 'com.android.application'

buildscript {
    repositories {
        maven { url "https://maven.google.com" }
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven { url 'https://maven.google.com' }
        jcenter()
    }
}

What it does? It just changes the libraries provider(in this case jcenter) with another one so your app can download them successfully. Every line in there is a libraries provider with fallback.

I don't know why it didn't fallback to maven in the first place because the fallback provider was in my build.gradle file.

Ionel Lupu
  • 2,695
  • 6
  • 29
  • 53
  • It is a temporary fix so we can work. Maybe tomorrow the `jcenter` will be available. – Ionel Lupu May 28 '18 at 12:23
  • I think the reason it doesn't "fallback to maven" is because it's finding a listing in jcenter but it's not finding the needed `.jar` file. So it's "there" but the specific `.jar` file it needs is not, which is different than if jcenter didn't have a listing for it. According to jcenter, they only have the `.aar` file for this library, not the `.jar`. – Joshua Pinter Jun 08 '18 at 20:17
  • In my case, the jcenter () statement was above maven and so my application was crashing. This tip solved the problem! – Eduardo Jun 21 '18 at 17:00
4

This morning I Had the same problem :

    Error:Could not resolve all files for configuration ':app:debugAndroidTestRuntimeClasspath'.

Could not find runtime.jar (android.arch.lifecycle:runtime:1.0.0). Searched in the following locations: https://jcenter.bintray.com/android/arch/lifecycle/runtime/1.0.0/runtime-1.0.0.j

I fixed it this way : On Project repository, i edit build.gradle, i commented jcenter() :

repositories {
   // jcenter()
    maven {
        url "https://maven.google.com"
    }
}

Now the project is building successfully ! Good luck !

AIT MANSOUR Mohamed
  • 809
  • 1
  • 7
  • 20
  • in which gradle app/build.gradle or build.gradle?? – AndyBoy May 29 '18 at 10:59
  • No need to comment it out, as you might require libraries that are only available on `jcenter()`. You can just move it below `maven`. However, if you comment it out and it works, that probably means you can remove `jcenter()` entirely because you're likely not depending on any libraries from that repository. – Joshua Pinter Jun 08 '18 at 20:20
4

In android/build.gradle, change the code as -

   allprojects {
    repositories {
        mavenLocal()
        maven { url 'https://maven.google.com' }
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}
Sidharth Taneja
  • 548
  • 6
  • 7
1

It would appear that the issue is that the pom is listed on jcenter but the jar is missing.

https://jcenter.bintray.com/android/arch/lifecycle/runtime/1.0.0/

Gradle will fail if the metadata is present in a repo but the artifact is missing

https://github.com/gradle/gradle/issues/1120

@Moritz's fix should work by going to maven.google.com first

JonnyH
  • 31
  • 3
1

This is work for me just follow these two step

Step 1: In project build.gradle file just replace the code below

 allprojects {
      repositories {
          mavenLocal()
          maven { url 'https://maven.google.com' }
          jcenter()
//        google()
    }
}

Just comment the google() if exist in your project gradle file.

Step 2: In file gradle-wrapper.properties downgrade the distributionUrl i have just downgrade with the below.

 distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
Maraj Hussain
  • 1,580
  • 10
  • 26
1

A new version of cordova-android (7.1.1) has been released that solves this problem.

So remove current android platform

cordova platform rm android

And add the new platform

cordova platform add android@7.1.1
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
0

I removed android platform and then added it again: to remove:

cordova platform rm android

to add:

cordova platform add android

and all works fine now Note: this version of android didn't install properly this time (did before today!)

cordova platform add android@6.1.0

ati
  • 16
  • 3