简体   繁体   English

Cordova android - 如何用生成的替换自定义 build.gradle

[英]Cordova android - How to replace custom build.gradle with generated

I have a cordova project, I have added android platform in it.我有一个cordova项目,我在其中添加了android平台。 Now I need to use my build.gradle file instead of the one generated.现在我需要使用我的 build.gradle 文件而不是生成的文件。

In the plugins.xml, I have the below code to do that.在 plugins.xml 中,我有以下代码可以做到这一点。

<framework src="src/android/build.gradle" custom="true" type="gradleReference" />

But while adding plugin, this build.gradle has been put under the package.It looks like this.但是在添加plugin的时候,这个build.gradle已经被放到了package下。看起来是这样的。

// PLUGIN GRADLE EXTENSIONS START
apply from: "com.test.Name/Name-build.gradle"
// PLUGIN GRADLE EXTENSIONS END

And I am getting below error in the build.gradle generated.我在生成的 build.gradle 中遇到了以下错误。

Error:(89, 0) Cannot convert relative path libs to an absolute file.

I need my custom build.gradle replace the auto generated.我需要我的自定义 build.gradle 替换自动生成的。 Please tell me how to specify this in plugin.xml The cordova version I use is 6.1.1请告诉我如何在plugin.xml中指定这个我使用的cordova版本是6.1.1

The following excerpt from official cordova documentation should help you, 官方cordova文档的以下摘录应该对您有所帮助,

Extending build.gradle 扩展build.gradle

If you need to customize build.gradle, rather than edit it directly, you should create a sibling file named build-extras.gradle. 如果需要自定义build.gradle,而不是直接编辑它,则应创建名为build-extras.gradle的兄弟文件。 This file will be included by the main build.gradle when present. 当存在时,主build.gradle将包含此文件。 This file must be placed in the app folder of the android platform directory (/platforms/android/app), so it is recommended that you copy it over via a script attached to the before_build hook. 此文件必须放在android平台目录(/ platforms / android / app)的app文件夹中,因此建议您通过附加到before_build挂钩的脚本将其复制。

Here's an example: 这是一个例子:

// Example build-extras.gradle
// This file is included at the beginning of `build.gradle`
ext.cdvDebugSigningPropertiesFile = '../../android-debug-keys.properties'

// When set, this function allows code to run at the end of `build.gradle`
ext.postBuildExtras = {
    android.buildTypes.debug.applicationIdSuffix = '.debug'
}

Note that plugins can also include build-extras.gradle files via: 请注意,插件还可以通过以下方式包含build-extras.gradle文件:

<framework src="some.gradle" custom="true" type="gradleReference"/>

Check out the offical cordova documentation for more info. 查看官方cordova文档以获取更多信息。 Hope it helps. 希望能帮助到你。

Set a custom gradle file by placing a file called gradle.properties in your Android platform folder (under <your-project>/platforms/android/app/gradle.properties ) and setting the properties in it like so:通过将名为gradle.properties的文件放在您的 Android 平台文件夹(在<your-project>/platforms/android/app/gradle.properties )并在其中设置属性来设置自定义 gradle 文件,如下所示:

 # In <your-project>/platforms/android/app/gradle.properties
 cdvMinSdkVersion=20

However, you can replace individual gradle properties by setting environment variables like so:但是,您可以通过设置环境变量来替换单个 gradle 属性,如下所示:

 $ export ORG_GRADLE_PROJECT_cdvMinSdkVersion=20
 $ cordova build android

Or by using the --gradleArg flag in your Cordova build or run commands, like so:或者在 Cordova 构建或运行命令中使用 --gradleArg 标志,如下所示:

 $ cordova run android -- --gradleArg=-PcdvMinSdkVersion=20

You can also extend build.gradle via a build-extras.gradle file and setting the property like so:您还可以通过 build-extras.gradle 文件扩展 build.gradle 并像这样设置属性:

 // In <your-project>/platforms/android/app/build-extras.gradle
 ext.cdvMinSdkVersion = 20

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

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