gpt4 book ai didi

android - 如何防止 Cordova build 命令自动生成 settings.gradle

转载 作者:太空狗 更新时间:2023-10-29 14:05:10 26 4
gpt4 key购买 nike

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

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

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

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

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

因此,由于无法找到我在 settings.gradle 中定义的模块“manager”,构建总是失败。

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

最佳答案

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

来做到这一点

步骤如下:

第 1 步。 在根目录中编辑/制作 project.properties 并将您的模块作为库引用添加到 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 文件中创建一个条目。

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

此外,您的应用 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
}

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

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

第 2 步。 编辑 fs.writeFileSync() 函数(第 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.

关于android - 如何防止 Cordova build 命令自动生成 settings.gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33036614/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com