简体   繁体   English

如何从插件覆盖 Cordova 项目的 gradle.properties?

[英]How to override gradle.properties of a Cordova project from a plugin?

I'm developing a Cordova plugin for Android. It uses a couple of dependencies like:我正在为 Android 开发一个 Cordova 插件。它使用了几个依赖项,例如:

com.android.tools.build.gradle:4.1.1

com.google.gms:google-services:3.2.0

So far it looks like (but please correct me if I'm wrong) they're imported properly if I add them to plugin.xml , which in turn inserts them into the project's AndroidManifest.xml like this:到目前为止它看起来像(但如果我错了请纠正我)如果我将它们添加到plugin.xml ,它们将被正确导入,然后将它们插入到项目的AndroidManifest.xml中,如下所示:

<framework src="com.android.tools.build:gradle:4.1.1" />
<framework src="com.google.gms:google-services:3.2.0" />

At least this isn't throwing a build error.至少这不会引发构建错误。 I do get another error though:我确实收到另一个错误:

This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.

And the problem is that a Cordova plugin has no gradle.properties file.问题是 Cordova 插件没有gradle.properties文件。 The Cordova project has one, but changing android.useAndroidX and android.enableJetifier in it manually doesn't seem to help: the build will still throw the same error. Cordova 项目有一个,但手动更改android.useAndroidXandroid.enableJetifier似乎没有帮助:构建仍然会抛出相同的错误。

The question is: How can I tell Cordova to set these values in gradle.properties to true ?问题是:如何告诉 Cordova 将gradle.properties中的这些值设置为true Is there some way to update or overwrite gradle.properties at build time, in a similar way how the contents of plugin.xml are registered in AndroidManifest.xml and a gradle file attached to the plugin gets added to build.gradle ?有没有什么方法可以在构建时更新或覆盖gradle.properties ,类似于plugin.xml的内容如何在AndroidManifest.xml中注册以及附加到插件的 gradle 文件被添加到build.gradle

Turns out it doesn't need overriding.事实证明它不需要覆盖。 In the Cordova project's config.xml the following line should be added:在 Cordova 项目的config.xml中应添加以下行:

<preference name="AndroidXEnabled" value="true" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM