Closed gougou168 closed 5 years ago
@gougou168 联系我的qq:281674669
感谢开发者-刚哥, 已经解决了。
如果新版本不存在这个问题请忽略。 解决方法:
1、下载插件到本地
2、修改插件目录里面的cordova-plugin-wechat-develop\scripts下面的android-install.js
3、安装插件cordova plugin add D:\ionic4x_release\cordova-plugin-wechat-develop --variable wechatappid=wx143214xxxxxxx
android-install.js代码如下
#!/usr/bin/env node
module.exports = function (context) {
var path = require('path'),
fs = require('fs'),
shell = require('shelljs'),
semver = require('semver'),
// var path = context.requireCordovaModule('path'),
// fs = context.requireCordovaModule('fs'),
// shell = context.requireCordovaModule('shelljs'),
// semver = context.requireCordovaModule('semver'),
projectRoot = context.opts.projectRoot,
plugins = context.opts.plugins || [];
// The plugins array will be empty during platform add
if (plugins.length > 0 && plugins.indexOf('cordova-plugin-wechat') === -1) {
return ;
}
var ConfigParser = null;
try {
ConfigParser = context.requireCordovaModule('cordova-common').ConfigParser;
} catch(e) {
// fallback
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser');
}
var config = new ConfigParser(path.join(context.opts.projectRoot, "config.xml")),
packageName = config.android_packageName() || config.packageName();
// replace dash (-) with underscore (_)
packageName = packageName.replace(/-/g , "_");
console.info("Running android-install.Hook: " + context.hook + ", Package: " + packageName + ", Path: " + projectRoot + ".");
if (!packageName) {
console.error("Package name could not be found!");
return ;
}
// android platform available?
if (context.opts.cordova.platforms.indexOf("android") === -1) {
console.info("Android platform has not been added.");
return ;
}
var targetDir = path.join(projectRoot, "platforms", "android", "src", packageName.replace(/\./g, path.sep), "wxapi");
if (!fs.existsSync(targetDir)) {
targetDir = path.join(projectRoot, "platforms", "android", "app", "src", "main", "java", packageName.replace(/\./g, path.sep), "wxapi");
}
console.info("targetDir:"+targetDir);
// var engines = config.getEngines();
// engines.forEach(function(item,index) {
// if(item.name == 'android') {
// var sepc = item.spec.replace('~','').replace('^','');
// console.log(sepc);
// if (semver.gte(sepc,'7.0.0')) {
// console.info("Android platform Version above 7.0.0");
// targetDir = path.join(projectRoot, "platforms", "android", "app", "src", "main", "java", packageName.replace(/\./g, path.sep), "wxapi");
// }
// }
// });
console.log(targetDir);
var targetFiles = ["EntryActivity.java", "WXEntryActivity.java", "WXPayEntryActivity.java"];
if (['after_plugin_add', 'after_plugin_install'].indexOf(context.hook) === -1) {
// remove it?
targetFiles.forEach(function (f) {
try {
fs.unlinkSync(path.join(targetDir, f));
} catch (err) {}
});
} else {
// create directory
shell.mkdir('-p', targetDir);
// sync the content
targetFiles.forEach(function (f) {
fs.readFile(path.join(context.opts.plugin.dir, 'src', 'android', f), {encoding: 'utf-8'}, function (err, data) {
if (err) {
throw err;
}
data = data.replace(/^package __PACKAGE_NAME__;/m, 'package ' + packageName + '.wxapi;');
fs.writeFileSync(path.join(targetDir, f), data);
});
});
}
};
@gougou168 嗯,代码我已经提交上来了,问题我先关掉了。
最新版本的cordova 最新版本的cordova-plugin-wechat 微信支付完成后闪退
重新编译很多次
已经按照下面方法操作还是不行。说明:cordova9.0中目录和下面稍微有些区别
检查项目目录下 platforms/android/app/src/com/jasonz/demo ,其中com/jasonz/demo为你的报名路径下 是否存在wxapi文件夹,并且是否该文件夹下是否存在EntryActivity.java , WXEntryActivity.java , WXPayEntryActivity.java这三个文件。如果没有这个目录和3个文件,新建一个wxapi目录,把plugins/cordova-plugin-wechat/src/android 下的这3个文件拷贝到wrapi目录下,并且修改文件内容的第一行package __PACKAGE_NAME__ 为你的报名,例如:package com.jasonz.demo 即可。