Skip to content

Commit 6c7f4e2

Browse files
authored
doc(android): refactor build-extras.gradle (#1425)
1 parent 749f516 commit 6c7f4e2

File tree

1 file changed

+22
-11
lines changed
  • www/docs/en/dev/guide/platforms/android

1 file changed

+22
-11
lines changed

www/docs/en/dev/guide/platforms/android/index.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ You can set these properties in one of four ways:
477477
cdvMinSdkVersion=20
478478
```
479479
480-
- [Extending `build.gradle`](#extending-buildgradle) with the `build-extras.gradle file
480+
- [Extending `build.gradle`](#extending-buildgradle) with the `build-extras.gradle` file
481481
482482
Create a file named `build-extras.gradle` in the directory `<project-root>/platforms/android/app` with the contents such as:
483483
@@ -487,14 +487,31 @@ You can set these properties in one of four ways:
487487
488488
The latter two options both involve including an extra file in your Android platform folder. In general, it is discouraged to edit the contents of this folder because it is easy for those changes to be lost or overwritten. Instead, these files should be copied into the folder as part of the build command by using the `before_build` [hook script](../../appdev/hooks/index.html).
489489
490-
#### Extending build.gradle
490+
#### Extending `build.gradle`
491491
492-
If you need to customize the `build.gradle` file, rather than edit it directly, it is recommended to create a sibling file named `build-extras.gradle`. This file will be included by the main `build.gradle` script when present. This file must be placed in the `app` folder of the Android's platform directory (`<your-project>/platforms/android/app`). It is recommended to use the `before_build` [hook script](../../appdev/hooks/index.html) to copy this file over.
492+
To customize the `app/build.gradle` file without modifying it directly, create a sibling file named `build-extras.gradle`.
493493
494-
Here's an example:
494+
If this file exists in the `<your-project>/platforms/android/app` directory during the build process, it will be automatically applied by the app's `build.gradle` script.
495+
496+
To automate placing `build-extras.gradle` in the correct location, use the `<resource-file>` element in `config.xml`.
497+
498+
In the example below, the source `build-extras.gradle` is saved in a `res/` directory in the project root. It is then declared in `config.xml` to copy it to the appropriate target location:
499+
500+
```xml
501+
<resource-file src="res/build-extras.gradle" target="app/build-extras.gradle"/>
502+
```
503+
504+
**Note:** The `res/` directory name is just an example. You can use any directory and file name you prefer. However, it's recommended not to place the file inside the `platforms`, `plugins`, or `www` directories. Also, make sure the `target` path matches exactly as shown in the example.
505+
506+
**Note:** Plugin developers can also include a `build-extras.gradle` file, but should use the `<framework>` element in `plugin.xml` instead of `<resource-file>`:
507+
508+
```xml
509+
<framework src="build-extras.gradle" custom="true" type="gradleReference" />
510+
```
511+
512+
**Example `build-extras.gradle`:**
495513
496514
```groovy
497-
// Example build-extras.gradle
498515
// This file is included at the beginning of `build.gradle`
499516
500517
// special properties (see `build.gradle`) can be set and overwrite the defaults
@@ -518,12 +535,6 @@ ext.postBuildExtras = {
518535
}
519536
```
520537
521-
Note that plugins can also include `build-extras.gradle` files via:
522-
523-
```xml
524-
<framework src="some.gradle" custom="true" type="gradleReference" />
525-
```
526-
527538
#### Configuring Gradle JVM Args
528539
529540
To change the Gradle JVM args, the `--jvmargs` flag can be used with both Cordova's `build` and `run` commands. This is mostly useful for controlling how much memory gradle is allowed to use during the build process. It is recommended to allow at least 2048 MB.

0 commit comments

Comments
 (0)