使用 cordova-android 6.4.0 构建 cordova-plugin-xapkreader



我继承了一个使用cordova-plugin-xapkreader的cordova项目,它似乎是访问扩展(又名OBB(文件的标准插件。我遇到了一个问题,我希望它会影响其他科尔多瓦插件。运行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 项目没有通过修改他们的模板来解决?这可以通过降级构建过程的某些部分来解决吗?

我对科尔多瓦很陌生,所以这一切都很莫名其妙,非常感谢任何帮助!

不幸的是,由于某种原因,钩子似乎不能可靠地工作 - 有时他们这样做,有时他们没有。这感觉可能是由于钩子异步运行引起的竞争条件 在构建过程的其余部分 - 所以有时 gradle 构建有 在修改 gradle 文件之前启动。

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

启示代码如下: - 在钩子的开头创建一个承诺:const deferral = context.requireCordovaModule('q').defer();
- 在钩子末尾返回承诺:


return deferral.promise;
- 在工作完成后解决承诺(文件已写入(:deferral.resolve();