简体   繁体   English

如何防止自动生成settings.gradle的Cordova构建命令

[英]How to prevent Cordova build command from auto-generating settings.gradle

I have created a Cordova App with a custom settings.gradle as folows: 我创建了一个带有自定义settings.gradle的Cordova应用程序,如下所示:

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

and in build.gradle, I can refer to it as: 在build.gradle中,我可以将其称为:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    debugCompile project(path: "CordovaLib", configuration: "debug")
    releaseCompile project(path: "CordovaLib", configuration: "release")
    // SUB-PROJECT DEPENDENCIES END
    compile project(':manager')
}

However, when I execute command 'cordova build android', the file settings.gradle is auto-generated to a default setting which looks like: 但是,当我执行命令'cordova build android'时,文件settings.gradle会自动生成为默认设置,如下所示:

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

As a result, build always failed due to unable to locate module 'manager' that I have defined in settings.gradle. 因此,由于无法找到我在settings.gradle中定义的模块“manager”,构建总是失败。

I wonder if there is any way to prevent build command from duplicating a custom settings.gradle file. 我想知道是否有任何方法可以阻止构建命令复制自定义的settings.gradle文件。

Today i faced the same problem and by spending hours i found that we can do this by change in project.properties 今天我遇到了同样的问题,花了几个小时我发现我们可以通过project.properties的变化来做到这一点

Below are the steps: 以下是步骤:

Step-1. 第1步。 Edit/Make project.properties in root directory and add your module as library reference after CordovaLib : 在根目录中编辑/生成project.properties并在CordovaLib之后将模块添加为库引用:

target=android-25
android.library.reference.1=CordovaLib
android.library.reference.2=libraryModule1
android.library.reference.3=libraryModule2

Step-2. 第2步。 Run cordova build android . 运行cordova build android This will make an entry in your setting.gradle file. 这将在您的setting.gradle文件中生成一个条目。

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

Also your app build.gradle will look like this: 您的app build.gradle也将如下所示:

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
}

For project(':manager').projectDir = new File('libs/ConnectManager') this kind of setting there is no easy way i found but you can achieve in this way: 对于project(':manager').projectDir = new File('libs/ConnectManager')这种设置没有我找到的简单方法,但你可以用这种方式实现:

Step-1. 第1步。 /path/to/project/platforms/android/cordova/lib/builders/GradleBuilder.js /path/to/project/platforms/android/cordova/lib/builders/GradleBuilder.js

Step-2. 第2步。 Edit fs.writeFileSync() function(Line-100) 编辑fs.writeFileSync()函数(Line-100)

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

// Update dependencies within build.gradle.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM