简体   繁体   English

Cordova 无法构建 Android

[英]Cordova fails to build Android

This is after running (to update android):这是运行后( 更新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 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 AndroidManifest.xml

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

And I even tried this in my build.gradle (wich I found in a answer for a related question that it seems to solve it for the QO):我什至在我的build.gradle中尝试了这个(我在一个相关问题的答案中发现它似乎解决了 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:问题是,如果我将所有这些28更改为27 ,那么cordova build android仍然会说 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

One of your plugins is using an Android X dependency, which is not compatible with the regular android support dependencies.您的插件之一是使用 Android X 依赖项,它与常规 android 支持依赖项不兼容。

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.您必须搜索是哪个插件并将其删除或使用未使用 Android X 依赖项的先前版本。

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.或者,使用 Cordova Android X 插件在项目中启用 Android X 并修补插件依赖项和代码使用等效于 ZE84E30B9390CDB6D64.6AB9CDB64

Install cordova-plugin-androidx to enable Android X安装cordova-plugin-androidx以启用 Android X

cordova plugin add cordova-plugin-androidx

Then install cordova-plugin-androidx-adapter to patch existing plugins然后安装cordova-plugin-androidx-adapter来修补现有插件

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.并删除cordova-android-support-gradle-release和任何 gradle 代码,您尝试将支持版本强制为 28,因为它会与 Android X 更改冲突。

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.您安装的任何插件都不支持您的 android.support.v4.app.CoreComponentFactor 因此menifest.xml 无法合并。 remove your plugin and try again and if you need this plugin then check its old version it will help you to run project删除您的插件并重试,如果您需要此插件,请检查其旧版本,它将帮助您运行项目

you just Add two lines in gradle.properties file:您只需在 gradle.properties 文件中添加两行:

android.useAndroidX=true
android.enableJetifier=true

hope this will resolve your issue希望这能解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM