Cordova android - How to replace custom build.gradle with generated
Asked Answered
S

2

8

I have a cordova project, I have added android platform in it. Now I need to use my build.gradle file instead of the one generated.

In the plugins.xml, I have the below code to do that.

<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 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.

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

I need my custom build.gradle replace the auto generated. Please tell me how to specify this in plugin.xml The cordova version I use is 6.1.1

Scruff answered 6/5, 2016 at 7:19 Comment(0)
C
21

The following excerpt from official cordova documentation should help you,

Extending build.gradle

If you need to customize build.gradle, rather than edit it directly, you should create a sibling file named build-extras.gradle. This file will be included by the main build.gradle when present. 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.

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:

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

Check out the offical cordova documentation for more info. Hope it helps.

Cherida answered 6/5, 2016 at 8:13 Comment(7)
I tried doing this with ext.cdvBuildToolsVersion but it doesn't seem to be working. Is there anyway to determine if it's picking up?Gules
@Gules try placing file in platforms/android/app subfolder (see my PR for cordova-docs)Greek
I need move maven repository to the first place in all the 3 build.gradle present in cordova android. It can be done extending the build.gradle file?Wester
@JoseNobile Could you please elaborate your problem? Not able to get your prob.Cherida
@JoseNobile I guess it should be possible by the initial look.Cherida
@JoseNobile I have the same problem. Is it possible to update the generated build.gradle? Otherwise everytime I add platforms, I have to manually edit the build.gradle files. How did you resolve your issue?Heteroousian
@Cherida where to put if I am using Cordova 6? No app directoryWalterwalters
S
0

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:

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

However, you can replace individual gradle properties by setting environment variables like so:

 $ 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 run android -- --gradleArg=-PcdvMinSdkVersion=20

You can also extend build.gradle via a build-extras.gradle file and setting the property like so:

 // In <your-project>/platforms/android/app/build-extras.gradle
 ext.cdvMinSdkVersion = 20
Soviet answered 15/12, 2021 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.