1

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.

BRass
  • 3,698
  • 2
  • 28
  • 46

4 Answers4

4

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.

Sandy.....
  • 2,833
  • 2
  • 15
  • 26
  • 2
    That's where my research was leading me too. However, Cordova/Ionic generate this build.gradle file. I'd like to understand why Cordova/Ionic do not generate it properly? It is usually best for Cordova developers to not manually edit the build.gradle file (otherwise future builds step on those edits). – BRass Sep 24 '18 at 13:39
  • It's a nice workaround for any developer working on a local PC, but how do i fix it on my Jenkins/Teamcity Pipeline, which is automaticly generating the whole platforms/android directory as it builds my project? I can't manually change the build.grade file on the pipeline after each nightly build.. – Emil Kaminski Oct 24 '18 at 10:49
2

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+'
    }
}
BRass
  • 3,698
  • 2
  • 28
  • 46
  • Could you update your answer and add the hook definition, especially how you copied the `build-extras.gradle` file over to the `platforms/android` location? – MWiesner Oct 23 '18 at 14:16
  • Did you define it similar to this approach here: https://stackoverflow.com/q/51723145/2849346 ? – MWiesner Oct 23 '18 at 14:29
  • 1
    Sure - I added a couple links to how I landed on that in the answer. – BRass Oct 23 '18 at 15:01
  • Thanks for helping out with this extra information. It helps others who are not that familiar with Ionic/Cordova setups to deal with these issues. – MWiesner Oct 23 '18 at 15:05
0

Below solution worked for me:

follow this step:- 

step 1: cordova plugin add cordova-android-support-gradle-release
step 2: cordova clean android
step 3: ionic cordova build android
Kapil Soni
  • 1,003
  • 2
  • 15
  • 37
-1

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.

Alex Predescu
  • 792
  • 2
  • 7
  • 24
  • 1
    There are multiple options in this post already. One option is to force the use of maven (see Sandy's post). The other option is to force the use of something prior to v26.1.0 (26.0+). – BRass Oct 23 '18 at 12:16
  • The one with switching the order as maven, then jcenter finally worked (Sandy's post) – Alex Predescu Oct 23 '18 at 16:46
  • OK. For reference, normally you wouldn't post an answer like yours, which is effectively a new question (not an answer). – BRass Oct 23 '18 at 18:33