gpt4 book ai didi

android - Visual Studio 2017 Cordova ;更改 Android 构建的目标文件夹

转载 作者:行者123 更新时间:2023-12-02 14:08:53 26 4
gpt4 key购买 nike

我已经弄清楚如何让 Visual Studio 使用 cordova 7.1.0 进行编译和测试,尽管理论上它应该只适用于 6.3.1 但我还有一个关于 Android 的问题。

Deploy 正在platforms\android\build\outputs\apk 中寻找apk

现在构建将 apk 放入platforms\android\build\outputs\apk\debug

因此,如果我构建它,然后复制 apk,然后告诉 Visual Studio 进行调试,它会起作用,因为它可以在platforms\android\build\outputs\apk 中对 apk 进行优化

所以每次我想测试时,我都必须删除apk,构建它,然后复制它,然后再次构建它以允许Visual Studio部署它。

Visual Studio、项目或注册表中是否有设置可用于更改部署文件夹或构建文件夹以使它们匹配?

最佳答案

我遵循了这里的建议https://stackoverflow.com/a/49270052/9874134但对其进行了一些调整以使其适合我的情况。

The cordova android platform 6.4+ puts the built apk here:

[project]\platforms\android\app\build\outputs\apk\debug\app-debug.apk

Visual Studio seems to be looking for it here:

[project]\platforms\android\build\outputs\apk\app-debug.apk

I added an "after_build" hook that copies the app-debug.apk and output.json files to the folder VS is looking in. I had to manually add the folder structures (for both the location of files being copied and location of hook file). I just added the following file, and the build process picks it up automatically.

下一步与建议有点不同。 “after_build” Hook 将 app-debug.apk 和 app-release 文件复制到 VS 正在查找的文件夹中:

我将copy_android_apk.js放在[project]\scripts\下

[项目]\scripts\copy_android_apk.js

我在 [project]\config.xml 中添加了一个“after_build”钩子(Hook)元素

<platform name="android">
<hook src="scripts/copy_android_apk.js" type="after_build" />
</platform>

copy_android_apk.js 的内容:

#!/usr/bin/env node

module.exports = function (context) {
console.log(" -- manual step -- have to copy apk to this folder because that is where VS is looking for it...");

var fs = require('fs');
var path = require('path');
var rootdir = process.argv[2];

var srcfile = path.join(process.cwd(), "platforms\\android\\app\\build\\outputs\\apk\\debug\\app-debug.apk");
var destfile = path.join(process.cwd(), "platforms\\android\\build\\outputs\\apk\\app-debug.apk");

var destdir = path.dirname(destfile);

//Create the output directory if it doesn't exist
if (!fs.existsSync(destdir)) {
mkdirSyncRecursive(destdir);
}

if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
fs.createReadStream(srcfile).pipe(
fs.createWriteStream(destfile));
}

srcfile = path.join(process.cwd(), "platforms\\android\\app\\build\\outputs\\apk\\release\\app-release.apk");
destfile = path.join(process.cwd(), "platforms\\android\\build\\outputs\\apk\\app-release.apk");

destdir = path.dirname(destfile);
if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
fs.createReadStream(srcfile).pipe(
fs.createWriteStream(destfile));
}

/**
* Splits whole path into segments and checks each segment for existence and recreates directory tree from the bottom.
* If since some segment tree doesn't exist it will be created in series.
* Existing directories will be skipped.
* @param {String} directory
*/
function mkdirSyncRecursive(directory) {
var path = directory.replace(/\\$/, '').split('\\');
for (var i = 1; i <= path.length; i++) {
var segment = path.slice(0, i).join('/');
!fs.existsSync(segment) ? fs.mkdirSync(segment) : null;
}
}
}

关于android - Visual Studio 2017 Cordova ;更改 Android 构建的目标文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49519163/

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