2

I am trying to ask the user permission before accessing their camera. I use the ionic diagnostic plugin for this. The app builds fine on Phonegap build before adding the diagnostic plugin. After adding plugin I get the following error through Phonegap build:

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':processDebugManifest'.

    Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(26.0.0-alpha1) from [com.android.support:support-v4:26.0.0-alpha1] AndroidManifest.xml:27:9-38 is also present at [com.android.support:appcompat-v7:25.3.1] AndroidManifest.xml:27:9-31 value=(25.3.1). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:25:5-27:41 to override

I installed the plugin using the following:

$ ionic cordova plugin add cordova.plugins.diagnostic
$ npm install --save @ionic-native/diagnostic

And in my config.xml I have the following:

<preference name="android-minSdkVersion" value="16" />
<preference name="android-targetSdkVersion" value="23" />

<plugin name="cordova.plugins.diagnostic" spec="^3.6.5"/>

Does anyone have an idea as to what I'm doing wrong here?

sebaferreras
  • 44,206
  • 11
  • 116
  • 134
Kavo
  • 543
  • 1
  • 6
  • 16

2 Answers2

5

I think that error is not related to the diagnostic plugin. A few days ago I updated my support repository and the same error started to show up on my end. According to this SO answer the issue is because:

Some libraries depend on version "X or newer" of Android support libraries so Gradle dependency resolution grabs whatever is the newest available ignoring you actually have a precise version specified in your dependencies block.

This is not what you want. You want all support libraries with same version and major version has to match compile SDK version.

So in order to solve it, go to the build.gradle file, located in projectName/platforms/android/build.gradle and add the following at the end of the file:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.3.1'
            }
        }
    }
}

You can replace the version with whatever it is you're using, but given the error you posted, 25.3.1 seems like the correct version to be used.

sebaferreras
  • 44,206
  • 11
  • 116
  • 134
2

Based on the answer by @sebaferreras, I've created a plugin which wraps the Gradle config and allows it to be pulled into a Cordova project dynamically (which really helps if you use CI for your builds): cordova-android-support-gradle-release.

Basically, just add it to your project and it will force any specified support library versions to the latest major release (currently v25):

cordova plugin add cordova-android-support-gradle-release
DaveAlden
  • 30,083
  • 11
  • 93
  • 155
  • Added the plugin. But still get the same error unfortunately. I don't seem to see the gradle-release plugin in the config.xml file after adding. Is this expected? – Kavo Jun 17 '17 at 12:33
  • Building locally or Phonegap Build? – DaveAlden Jun 17 '17 at 12:36
  • `I don't seem to see the gradle-release plugin in the config.xml file after adding. Is this expected?` Depends on your `cordova` version: v7 saves it automatically; – DaveAlden Jun 17 '17 at 12:38
  • I am using Phonegap Build. And Cordova 6.3.1. I was under the impression that Phonegap Build will not see the plugin if it is not listed in the `config.xml` file. And because the build fails, I can't tell for sure if the `gradle-release` plugin is picked up by Phonegap. Certainly not listed in the log. – Kavo Jun 17 '17 at 12:48
  • Also I added the diagnostic plugin to a brand new project, and it built fine on Phonegap Build. Could the diagnostic plugin be clashing with another plugin that I have in my actual project? – Kavo Jun 17 '17 at 13:29
  • 2
    Yes that's exactly the problem - they are specifying different versions of the Android Support libraries. Hence the need for the `gradle-release` plugin. – DaveAlden Jun 17 '17 at 13:32
  • That's amazing @DaveAlden, thanks a lot for this plugin (and for all your plugins!) :) – sebaferreras Jun 18 '17 at 07:36
  • 1
    Awesome! If only it hadn't taken me so long to find this. Thanks Dave & @sebaferreras – Gabe O'Leary Jul 24 '17 at 22:44
  • @GabeO'Leary glad to hear that it helped :) – sebaferreras Jul 25 '17 at 06:24