可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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!
回答1:
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()
回答2:
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()
}
}
回答3:
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.
回答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 !
回答5:
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"
}
}
}
回答6:
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
回答7:
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
回答8:
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
回答9:
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
回答10:
I am also getting same error.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have not changed any thing in build.gradle.