2
votes

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?

2

2 Answers

5
votes

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.

2
votes

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