首页 > 解决方案 > 使用cordova-android 6.4.0 构建cordova-plugin-xapkreader

问题描述

我继承了一个使用cordova-plugin-xapkreader 的cordova 项目,它似乎是用于访问扩展(又名OBB)文件的标准插件。我遇到了一个问题,我希望它会影响其他cordova插件。运行时出现以下错误cordova build android

Configuration 'compile' in project ':' is deprecated. Use 'implementation' instead.
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
Configuration 'compile' in project ':com.flyingsoftgames.xapkreader:downloader_library' is deprecated. Use 'implementation' instead.
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
Configuration 'debugCompile' in project ':com.flyingsoftgames.xapkreader:downloader_library' is deprecated. Use 'debugImplementation' instead.
Configuration 'releaseCompile' in project ':com.flyingsoftgames.xapkreader:downloader_library' is deprecated. Use 'releaseImplementation' instead.
Configuration 'compile' in project ':com.flyingsoftgames.xapkreader:library' is deprecated. Use 'implementation' instead.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':debugCompileClasspath'.
   > Could not resolve project :com.flyingsoftgames.xapkreader:library.
     Required by:
         project : > project :com.flyingsoftgames.xapkreader:downloader_library
      > Project :com.flyingsoftgames.xapkreader:downloader_library declares a dependency from configuration 'debugCompile' to configuration 'debug' which is not declared in the descriptor for project :com.flyingsoftgames.xapkreader:library.

这已被其他人报告为插件论坛上的错误,但解决方法并不可靠:

https://github.com/agamemnus/cordova-plugin-xapkreader/issues/116

问题似乎是 gradle 希望您现在使用implementation而不是compiledebugCompile。插件的 gradle 文件是由 cordova 基于 cordova-android 中的模板生成的。建议的解决方法是在从 cordova 挂钩运行的脚本中修改模板(或生成的 gradle 文件)。不幸的是,由于某种原因,这些钩子似乎不能可靠地工作——有时可以,有时不能。这感觉可能是由于钩子与构建过程的其余部分异步运行导致的竞争条件 - 所以有时 gradle 构建在 gradle 文件可以修改之前已经开始。

有没有人知道如何正确解决这个问题?有谁知道为什么这不是 cordova-android 项目没有通过修改他们的模板来解决的更广泛的问题?我可以通过降级构建过程的某些部分来解决这个问题吗?

我对科尔多瓦很陌生,所以这一切都令人困惑,非常感谢任何帮助!

标签: androidcordovagradle

解决方案


不幸的是,由于某种原因,这些钩子似乎不能可靠地工作——有时可以,有时不能。这感觉可能是由于钩子与构建过程的其余部分异步运行导致的竞争条件 - 所以有时 gradle 构建在 gradle 文件可以修改之前已经开始。

我认为这可以通过让钩子返回一个承诺来解决,这样你可以确保构建的其余部分不会并行运行。我在 github 问题上发布了我正在使用的代码。

相关的代码如下:
- 在钩子的开头创建一个承诺:
const deferral = context.requireCordovaModule('q').defer();
- 在钩子的结尾返回承诺:
return deferral.promise;
- 一旦工作完成(文件被写入)解决承诺:
deferral.resolve();


推荐阅读