某些库更新后,Android平台构建失败

时间:2019-06-21 13:13:42

标签: android cordova ionic-framework

我有一个ionic / cordova项目可以正常工作,我可以像魅力一样构建和运行该应用程序。从两天前开始,发生了一些事情,构建被破坏了。每次命令“ cordova build android ”都会失败,并显示以下错误消息:

> Task :app:transformDexArchiveWithExternalLibsDexMergerForArm64Debug FAILED
D8: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForArm64Debug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
  Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
  Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback

所有开发人员PC均在同一天开始发生此问题,因此我确定这不是特定的系统配置更改。

我想是由于图书馆更新所致。

我的环境信息是:

Ionic:

   ionic (Ionic CLI) : 4.12.0 (/home/gustavo/.nvm/versions/node/v8.9.4/lib/node_modules/ionic)
   Ionic Framework   : ionic1 1.3.1
   @ionic/v1-toolkit : not installed

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 8.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.5.0, (and 14 other plugins)

System:

   Android SDK Tools : 26.1.1 (/home/gustavo/apps/android-studio-running)
   NodeJS            : v8.9.4 (/home/gustavo/.nvm/versions/node/v8.9.4/bin/node)
   npm               : 6.4.1
   OS                : Linux 4.4

Cordova插件列表为:

acidhax.cordova.chromecast 0.0.1-alpha "Cordova ChromeCast"
com.example.hello 0.7.0 "Hello"
com.telerik.plugins.nativepagetransitions 0.6.5 "Native Page Transitions"
cordova-android-support-gradle-release 2.1.0 "cordova-android-support-gradle-release"
cordova-plugin-add-swift-support 1.7.2 "AddSwiftSupport"
cordova-plugin-console 1.1.0 "Console"
cordova-plugin-crosswalk-webview 2.4.0 "Crosswalk WebView Engine"
cordova-plugin-device 1.1.7 "Device"
cordova-plugin-device-name 1.3.5 "Device-Name"
cordova-plugin-fullscreen 1.1.0 "cordova-plugin-fullscreen"
cordova-plugin-inappbrowser 3.0.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 2.5.0 "cordova-plugin-ionic-webview"
cordova-plugin-screen-orientation 1.4.2 "Screen Orientation"
cordova-plugin-sim 1.3.3 "SIM"
cordova-plugin-splashscreen 4.1.0 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"

我尝试逐个删除每个插件,发现删除“ acidhax.cordova.chromecast”时,构建成功完成。

因此,我开始搜索与此插件有关的问题,并发现了一个类似的问题:Passing an Array or List to @Pathvariable - Spring/Java,我按照那里的建议进行操作,但问题仍然存在。

1 个答案:

答案 0 :(得分:0)

这是由于AndroidX插件版本以及几天前Google所做的重大更改所致。

您应该可以通过添加以下插件来解决它:

ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter

然后cordova clean android并重新构建。

请确保拥有Android SDK 28,并且我建议也更新Cordova和ionic。