I have an Ionic 3 app that has built fine on dev machines for quite a while. Today we tried a new machine and it doesn't build there. It is using an older cordova-android version (6.1.2), but I would think it would still build. The error I'm seeing is below:
> ionic cordova build android
...
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not find support-v4.jar (com.android.support:support-v4:26.1.0).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/support-v4/26.1.0/support-v4-26.1.0.jar
One other piece of background info. This project had an issue with conflicting android support version requirements from multiple plugins, which required us to use a build-extras.gradle
file to force everything to com.android.support:support-v4:26+
. That was many months ago so it shouldn't be related, but I thought I should add it in case it helps.
You have to do some modifications in your build.gradle file inside platforms/android as follows:
allprojects {
repositories {
mavenCentral()
maven { url 'https://maven.google.com' } //add this code
jcenter()
}
}
It's essential for new versions of google libraries. They moved their libraries out of the android SDK to the maven repo.
I'm sure I could adjust the build.gradle file that Cordova generates to fix this. However, that would get stepped on by Cordova on every Dev machine. I found a different work-around.
I previously had to mess with the com.android.support
library because different plugins required different versions, and they didn't play well with each other. My approach was to add a build-extras.gradle file (via a hook, see here (option 2) which eventually leads to here) with the contents below. That worked (until fairly recently).
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:26+'
}
}
From what I can tell, something is different about the 26.1.0 version of this library. It seems like it's not available in the same repository or something? Regardless, swapping to an earlier version (below) works. Notice the real change is from 26+
to 26.0+
(which should pull in 26.0.2). This builds fine again.
configurations.all {
resolutionStrategy {
force 'com.android.support:support-v4:26.0+'
}
}
This happened to me as well, today. It compiled two days ago and now the build fails. I did not change anything to the project or config. It may be because google moved their libraries to maven but what can we do about this?
WARNING: Module 'com.android.support:support-v4:26.1.0' depends on one or more Android Libraries but is a jar
BUILD FAILED
Total time: 2.87 secs FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring root project 'android'.
Could not find support-v4.jar (com.android.support:support-v4:26.1.0). Searched in the following locations: https://jcenter.bintray.com/com/android/support/support-v4/26.1.0/support-v4-26.1.0.jar
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. cmd: Command failed with exit code 1 Error output: FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring root project 'android'.
Could not find support-v4.jar (com.android.support:support-v4:26.1.0). Searched in the following locations: https://jcenter.bintray.com/com/android/support/support-v4/26.1.0/support-v4-26.1.0.jar
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
来源:https://stackoverflow.com/questions/52451055/ionic-3-android-build-error-could-not-find-support-v4-jar