Toni Michel Caubet
Toni Michel Caubet

Reputation: 20163

Cordova fails to build Android

This is after running (to update android):

cordova plugin save
cordova platform remove android
cordova platform add android

This is the error I get, which I think is that version values are not being merged properly.

    * What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-35:19 to override.

I've been having this issue and digging into for a few days.

Lets see, I'll share only what I think is relevant but if any more info is needed. just let me know:

config.xml

<platform name="android">
        <allow-intent href="market:*" />
        <preference name="android-minSdkVersion" value="19" />
        <preference name="android-targetSdkVersion" value="28" />
        ...
</platform>

<plugin name="cordova-android-support-gradle-release" spec="^3.0.1">
    <variable name="ANDROID_SUPPORT_VERSION" value="28.+" />
</plugin>

AndroidManifest.xml

<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28"/>

And I even tried this in my build.gradle (which I found in a answer for a related question that it seems to solve it for the QO):

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

The thing is if I change all this 28's for 27 then cordova build android will still say 28:

cordova-android-support-gradle-release: Wrote custom version '28.+' to /Users/myuser/Proyectos/localhost/cordova/my-app/platforms/android/app/build.gradle
cordova-android-support-gradle-release: Wrote custom version '28.+' to /Users/myuser/Proyectos/localhost/cordova/my-app/platforms/android/cordova-android-support-gradle-release/my-cordova-android-support-gradle

So I don't really know what to try next.. any thoughts?

This is the full response:

cordova build android
cordova-android-support-gradle-release: Android platform: V7+
cordova-android-support-gradle-release: Wrote custom version '28.+' to /Users/toniweb/Proyectos/localhost/cordova/my-app/platforms/android/app/build.gradle
cordova-android-support-gradle-release: Wrote custom version '28.+' to /Users/toniweb/Proyectos/localhost/cordova/my-app/platforms/android/cordova-android-support-gradle-release/my-cordova-android-support-gradle-release.gradle
Running command: /Users/toniweb/Proyectos/localhost/cordova/my-app/hooks/after_prepare/030_remove-permissions.js /Users/toniweb/Proyectos/localhost/cordova/my-app
cordova-android-support-gradle-release: Android platform: V7+
cordova-android-support-gradle-release: Wrote custom version '28.+' to /Users/toniweb/Proyectos/localhost/cordova/my-app/platforms/android/app/build.gradle
cordova-android-support-gradle-release: Wrote custom version '28.+' to /Users/toniweb/Proyectos/localhost/cordova/my-app/platforms/android/cordova-android-support-gradle-release/my-cordova-android-support-gradle-release.gradle
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/Users/toniweb/Library/Android/sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app

> Configure project :app
+-----------------------------------------------------------------
| cordova-android-support-gradle-release: 28.+
+-----------------------------------------------------------------

> Task :app:preBuild UP-TO-DATE
> Task :CordovaLib:preBuild UP-TO-DATE
> Task :CordovaLib:preDebugBuild UP-TO-DATE
> Task :CordovaLib:checkDebugManifest UP-TO-DATE
> Task :CordovaLib:processDebugManifest UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :CordovaLib:compileDebugAidl NO-SOURCE
> Task :app:compileDebugAidl NO-SOURCE
> Task :CordovaLib:packageDebugRenderscript NO-SOURCE
> Task :app:compileDebugRenderscript UP-TO-DATE
> Task :app:checkDebugManifest UP-TO-DATE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:prepareLintJar UP-TO-DATE
> Task :app:generateDebugSources UP-TO-DATE
> Task :CordovaLib:compileDebugRenderscript UP-TO-DATE
> Task :CordovaLib:generateDebugBuildConfig UP-TO-DATE
> Task :CordovaLib:generateDebugResValues UP-TO-DATE
> Task :CordovaLib:generateDebugResources UP-TO-DATE
> Task :CordovaLib:packageDebugResources UP-TO-DATE
> Task :CordovaLib:generateDebugRFile UP-TO-DATE
> Task :CordovaLib:prepareLintJar UP-TO-DATE
> Task :CordovaLib:generateDebugSources UP-TO-DATE
> Task :CordovaLib:javaPreCompileDebug UP-TO-DATE
> Task :CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
> Task :CordovaLib:processDebugJavaRes NO-SOURCE
> Task :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:mainApkListPersistenceDebug UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE

> Task :app:processDebugManifest FAILED
/Users/toniweb/Proyectos/localhost/cordova/my-app/platforms/android/app/src/main/AndroidManifest.xml:22:18-91 Error:
    Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-35:19 to override.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-35:19 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
22 actionable tasks: 1 executed, 21 up-to-date
/Users/toniweb/Proyectos/localhost/cordova/my-app/platforms/android/gradlew: Command failed with exit code 1 Error output:
/Users/toniweb/Proyectos/localhost/cordova/my-app/platforms/android/app/src/main/AndroidManifest.xml:22:18-91 Error:
    Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-35:19 to override.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
    is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
    Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-35:19 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

Upvotes: 2

Views: 2317

Answers (3)

MurugananthamS
MurugananthamS

Reputation: 2405

you just Add two lines in gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

hope this will resolve your issue

Upvotes: 0

Arslan Yasin
Arslan Yasin

Reputation: 61

There is any of you installed plugin which is not support with your android.support.v4.app.CoreComponentFactor therefor menifest.xml is unable to merge. remove your plugin and try again and if you need this plugin then check its old version it will help you to run project

Upvotes: 0

jcesarmobile
jcesarmobile

Reputation: 53301

One of your plugins is using an Android X dependency, which is not compatible with the regular android support dependencies.

You'll have to search which plugin is that and remove it or use a previous version that didn't use an Android X dependency.

Alternatively, use the Cordova Android X plugins that enable Android X in the project and patch plugin dependencies and code usage for the Android X equivalent.

Install cordova-plugin-androidx to enable Android X

cordova plugin add cordova-plugin-androidx

Then install cordova-plugin-androidx-adapter to patch existing plugins

cordova plugin add cordova-plugin-androidx-adapter

And remove cordova-android-support-gradle-release and any gradle code where you try to force the support version to 28 as it will conflict with the Android X changes.

Upvotes: 5

Related Questions