'how to add to settings.gradle in cordova
This is the same question I am to new to comment on it to see if he found a answer
Cordova is generating a new settings.gradle file when you run "cordova build android" I have attempted using a script to modify this file using hooks after _prepare before_compile. but no matter what i do this file is recreated. Has anyone solved this problem? is there another way to add a module to the android project? besides using the settings.gradle
I knwo next to nothing about java or Gradle so any in-site would be great.
Solution 1:[1]
You can include or exclude dependency using build-extras.gradle
file. This file can be added along with build.gradle
file in the same location using before_build
hook action.
Request you to check Official Cordova documentation for more info on the same. Also check out this example which explains exclusion of duplicate modules. The same can be extended for module inclusion as well.
Updated: I do understand that the question is about settings.gradle and I m talking about build.gradle. That's because as far as i know, there is no way of directly manipulating settings.gradle with the exception of through build.gradle as its explained in the example link. Also i suggest you to have a look at this gradle thread which explains adding dependency via build.gradle file.
But if you are still looking for a solution to manipulate settings.gradle, you gotta edit build.js file in android platform as suggested in this post which is more of a quick fix or tweak.
I hope it helps.
Solution 2:[2]
You can do this by change in project.properties
Below are the steps:
Step-1. Edit/Make project.properties
in root directory and add your module as library reference after CordovaLib
:
target=android-25
android.library.reference.1=CordovaLib
android.library.reference.2=libraryModule1
android.library.reference.3=libraryModule2
Step-2. Run cordova build android
. This will make an entry in your setting.gradle
file.
//GENERATED FILE - DO NOT EDIT
include ":"
include ":CordovaLib"
include ":libraryModule1"
include ":libraryModule2"
Also your app build.gradle
will look like this:
dependencies {
----
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: "CordovaLib", configuration: "debug"))
releaseCompile(project(path: "CordovaLib", configuration: "release"))
debugCompile(project(path: "libraryModule1", configuration: "debug"))
releaseCompile(project(path: "libraryModule1", configuration: "release"))
debugCompile(project(path: "libraryModule2", configuration: "debug"))
releaseCompile(project(path: "libraryModule2", configuration: "release"))
----
// SUB-PROJECT DEPENDENCIES END
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 | Raphaël Balet |