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

时间:2018-05-03 14:32:59

标签: android cordova gradle

我继承了一个使用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项目没有通过修改他们的模板修复?这是我可以通过降级构建过程的某些部分来解决的问题吗?

我对Cordova很陌生,所以非常莫名其妙,非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

  

不幸的是,由于某些原因,挂钩似乎无法可靠地工作   -有时会,有时却不会。感觉可能是由于挂钩异步运行导致的竞争条件   在其余的构建过程中-因此有时gradle构建具有   在可以修改gradle文件之前开始。

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

相关代码如下:
 -在挂钩的开头创建一个承诺:
from threading import Thread ... def times_pressed(): global count count+=1 if count >= 10: # Code to be executed when "water is low" message = "Water is over and it needs to be changed." thread = Thread( target = lambda: Send_Email( email='tmpaccount@gmail.com', # Gmail new account password='test@123', # Its password to='Your email address', # Receiver's email subject='Water is Low', # Subject of mail message=message ) # The message you want ) thread.start() show_press['text'] = 'You pressed the Button {} times'.format(count) ...
 -在挂钩末尾返回承诺:
const deferral = context.requireCordovaModule('q').defer();
 -完成工作(写文件)后,兑现承诺:
return deferral.promise;