【问题标题】:Cordova fails to build AndroidCordova 无法构建 Android
【发布时间】:2020-02-18 19:09:54
【问题描述】:

这是运行后(到updateandroid):

cordova plugin save
cordova platform remove android
cordova platform add android

这是我得到的错误,我认为是版本值没有正确合并。

    * 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.

我一直有这个问题并深入研究了几天。

让我们看看,我只会分享我认为相关的内容,但如果需要更多信息……请告诉我:

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"/>

我什至在我的 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'
            }
        }
    }
}

问题是,如果我将所有这些 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

所以我真的不知道接下来要尝试什么......有什么想法吗?

这是完整的回复:

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

【问题讨论】:

  • 你试过把 android.useAndroidX=true android.enableJetifier=true 放在你的 gradle.properties 中
  • @Swayangjit 谢谢!我试过了,现在回复是Execution failed for task ':app:compileDebugJavaWithJavac'.。还有其他想法吗?
  • 你能发布请完整的日志吗?
  • @Swayangjit 我在问题中发布了我以前的完整日志,这是完整的日志,包括您对gradle.properties 的建议,它明显更大:hastebin.com/pumozasiti.shell 希望它有助于找到问题。谢谢
  • 在您的 config.xml 中添加 跨度>

标签: android cordova gradle build


【解决方案1】:

您的一个插件正在使用 Android X 依赖项,该依赖项与常规的 android 支持依赖项不兼容。

您必须搜索是哪个插件并将其删除或使用未使用 Android X 依赖项的先前版本。

或者,使用在项目中启用 Android X 的 Cordova Android X 插件,并为 Android X 等效项修补插件依赖项和代码使用。

安装cordova-plugin-androidx以启用Android X

cordova plugin add cordova-plugin-androidx

然后安装cordova-plugin-androidx-adapter 来修补现有插件

cordova plugin add cordova-plugin-androidx-adapter

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

【讨论】:

  • 感谢您的宝贵时间,请原谅我的延误。好的,我安装了两个插件并评论了这一行 &lt;!-- variable name="ANDROID_SUPPORT_VERSION" value="28.+" /--&gt; 响应略有变化,但错误相同。我 rm 并再次添加了平台,所以我相信其他 gradles 配置已经消失了。有什么想法吗?
  • 新的错误是什么?你卸载了 cordova-android-support-gradle-release 吗?
  • 嗨,不,我没有,只是评论了上面的行。我怎么能做到? cordova plugin remove cordova-android-support-gradle-release?这是“新”日志:pastebin.com/edMrP1dG
  • 我试过这个命令,它确实删除了插件,这是cordova preparecordova build android之后的日志:pastebin.com/JitAm0sQ
  • 设置 minSDK 将其添加到 config.xml &lt;preference name="android-minSdkVersion" value="19" /&gt;
【解决方案2】:

您安装的任何插件都不支持您的 android.support.v4.app.CoreComponentFactor,因此 menifest.xml 无法合并。 删除您的插件并重试,如果您需要此插件,请检查其旧版本,它将帮助您运行项目

【讨论】:

  • 谢谢!问题是我不知道插件是什么......这是我的插件列表。有什么想法吗? pastebin.com/VLEefWiW
【解决方案3】:

你只需在 gradle.properties 文件中添加两行:

android.useAndroidX=true
android.enableJetifier=true

希望这能解决您的问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多