如何防止Cordova build命令自动生成settings.gradle [英] How to prevent Cordova build command from auto-generating settings.gradle

查看:188
本文介绍了如何防止Cordova build命令自动生成settings.gradle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了具有自定义settings.gradle的Cordova应用程序,如下所示:

I have created a Cordova App with a custom settings.gradle as folows:

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

在build.gradle中,我可以将其称为:

and in build.gradle, I can refer to it as:

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')
}

但是,当我执行命令"cordova build android"时,文件settings.gradle会自动生成为默认设置,如下所示:

However, when I execute command 'cordova build android', the file settings.gradle is auto-generated to a default setting which looks like:

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

结果,由于找不到我在settings.gradle中定义的模块经理",构建始终失败.

As a result, build always failed due to unable to locate module 'manager' that I have defined in settings.gradle.

我想知道是否有任何方法可以防止build命令复制自定义settings.gradle文件.

I wonder if there is any way to prevent build command from duplicating a custom settings.gradle file.

推荐答案

今天,我遇到了同样的问题,花了几个小时,我发现我们可以通过更改 project.properties

Today i faced the same problem and by spending hours i found that we can do this by change in project.properties

以下是步骤:

第1步.在根目录中编辑/制作project.properties,并在CordovaLib之后将您的模块添加为库引用:

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

第2步..运行cordova build android.这将在您的setting.gradle文件中创建一个条目.

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"

您的应用程序build.gradle也将如下所示:

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
}

对于project(':manager').projectDir = new File('libs/ConnectManager')这种设置,我找不到简单的方法,但是可以通过以下方式实现:

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:

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

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

步骤2.编辑fs.writeFileSync()函数(第100行)

Step-2. Edit fs.writeFileSync() function(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.

这篇关于如何防止Cordova build命令自动生成settings.gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆