我继承了一个使用cordova-plugin-xapkreader的cordova项目,该项目似乎是访问扩展(aka 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文件)。不幸的是,由于某些原因,挂钩似乎无法可靠地工作-有时可以,有时不能。感觉可能是由于竞争条件所导致的,而该竞争条件是由与其余构建过程异步运行的钩子(Hook)引起的,因此有时在已修改gradle文件之前已开始gradle构建。

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

我对Cordova来说还很陌生,所以这一切令人莫名其妙,我们将不胜感激!

最佳答案



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

相关代码如下:
-在挂钩的开头创建一个 promise :const deferral = context.requireCordovaModule('q').defer(); -在挂钩末尾返回 promise :return deferral.promise; -完成工作后立即兑现 promise (文件已写入):deferral.resolve();

07-24 09:44
查看更多