问题
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!
回答1:
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
回答2:
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.
回答3:
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 :)
来源:https://stackoverflow.com/questions/34307879/is-it-possible-to-manually-edit-settings-gradle-file