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.
In Eclipse, select File > Export. In the window that appears, open Android and select Generate Gradle build files. Select the project you want to export for Android Studio and click Finish.
Solution. To solve this problem you need to open the project/android/settings. gradle file and have to replace the backslash(\) with the frontslash(/) as windows directory structure do not support the backslash(\).
The framework requires the existence of the settings. gradle in a multi-project build, while it's optional for a single-project build. and Gradle is calling the void include(String… projectPaths) method on the Settings instance when creating the build.
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
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With