1

In a Cordova project, I have a file settings.gradle which looks like:

// GENERATED FILE - DO NOT EDIT
include ":"
include ":CordovaLib"

However, manually I want to edit the file and to make it look something like:

// GENERATED FILE - DO NOT EDIT
include ":"
include ":CordovaLib"
include 'manager-A'
project(':manager-A').projectDir = new File('libs/Manager-A')
include 'manager-B'
project(':manager-B').projectDir = new File('libs/Manager-B')

The above script looks good and it can be built successfully using Android studio. However, when I try to execute command line: cordova build android, it cannot be built.

The error is 'manager-A' and 'manager-B' that I manually included earlier cannot be found by the command line. After checking, it turned out that the file that I manually edited was re-generated and it becomes:

// GENERATED FILE - DO NOT EDIT
include ":"
include ":CordovaLib"

I'd like to ask whether it is possible to manually edit the file and that can be built as I explained above using the command line: cordova build android.

Any input is really appreciated!

Nakket
  • 620
  • 7
  • 18
  • There is nothing in gradle that hinders you to edit this file manually. If you experience problems they probably come from cordova. – Henry Dec 16 '15 at 09:15
  • `// GENERATED FILE - DO NOT EDIT` - this first line does not raise your attention? This file is generated, so any changes made in there will be deleted. Also, you already asked the same question [here](http://stackoverflow.com/questions/33036614/how-to-prevent-cordova-build-command-from-auto-generating-settings-gradle). Have you even read the [documentation](https://cordova.apache.org/docs/en/latest/guide/platforms/android/tools.html) in this time? Have you done some [research](http://stackoverflow.com/a/29783734/4908802)? Last link may be helpful to you. – yennsarah Dec 16 '15 at 09:41
  • Looking for similar solution, for adding a payment gateway in cordova project. – Ankit Balyan Dec 30 '15 at 08:21

3 Answers3

2

Yes, I was looking to resolve same problem and found out following solution from this npm cordova-blinkup-plugin's Page. You can edit the settings with as:
1. Open path/to/project/platforms/android/cordova/lib/build.js
2. Edit fs.writeFileSync() function (line 273):

// Write the settings.gradle file.
fs.writeFileSync(path.join(projectPath, 'settings.gradle'),
'// GENERATED FILE - DO NOT EDIT\n' +
'include ":"\n' + settingsGradlePaths.join('') +
'include ":customProject1" +
'include ":customProject2"');

I hope this will help.

Update as suggested in another answer, In newer versions of Cordova you may get file at /path/to/project/platforms/android/cordova/lib/builders/GradleBuilder.js

Ankit Balyan
  • 1,319
  • 19
  • 31
  • 2
    See this answer-comment on this answer that shows the current file: https://stackoverflow.com/a/40717663/252627 – janpio Oct 03 '17 at 17:35
1

I found a better way to add custom include in setting.gradle file.

Make a file project.properties and add the below lines:

target=android-22
android.library.reference.1=CordovaLib
android.library.reference.2=manager-A
android.library.reference.3=manager-B

Now run cordova build android. This will make an entry in your setting.gradle file.

This answers part of the questions of how to include a module. But how to add the libs as below, still need a better way:

project(':manager-A').projectDir = new File('libs/Manager-A')

Can be done with modifying the build.js (Suggested by Sopheak Mongkul). I don't recommend, but it is good till you get a better solution.

janpio
  • 10,645
  • 16
  • 64
  • 107
hirenhcm
  • 93
  • 1
  • 10
0

An update to @ankibalyan's answer: I found that function in path/to/project/platforms/android/cordova/lib/builders/GradleBuilder.js, just in case anybody needed it any more :)

janpio
  • 10,645
  • 16
  • 64
  • 107
Boda
  • 329
  • 2
  • 11