Cordova android - How to replace custom build.gradle with generated
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.
Comments
-
Neela almost 2 years
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
-
darewreck over 7 yearsI tried doing this with ext.cdvBuildToolsVersion but it doesn't seem to be working. Is there anyway to determine if it's picking up?
-
piotr_cz about 6 years@darewreck try placing file in
platforms/android/app
subfolder (see my PR for cordova-docs) -
Jose Nobile almost 6 yearsI 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?
-
Gandhi almost 6 years@JoseNobile Could you please elaborate your problem? Not able to get your prob.
-
Gandhi almost 6 years@JoseNobile I guess it should be possible by the initial look.
-
Shivam Pokhriyal over 5 years@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?
-
Áxel Costas Pena about 5 years@Gandhi where to put if I am using Cordova 6? No app directory