2019/07/01現在、Cordova Ver.8.1.2において、「cordova-plugin-crypt-file」プラグインを使用した場合、ビルドにおいて下記のエラーが発生します。
このエラーの回避方法について説明します。
ENOENT: no such file or directory, open ‘C:\xxxxx\yyyyy\platforms\android\src\com\tkyaji\cordova\DecryptResource.java’
前回紹介した方法は、プラグインのインストール時に下記のエラーが発生します。
Failed to fetch plugin https://github.com/tkyaji/cordova-plugin-crypt-file via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: cmd: Command failed with exit code 1 Error output:
npm ERR! code ENOGIT
npm ERR! Error while executing:
npm ERR! undefined ls-remote -h -t https://github.com/tkyaji/cordova-plugin-crypt-file.git
npm ERR!
npm ERR! undefined
npm ERR! No git binary found in $PATH
npm ERR!
npm ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\xxxxx\AppData\Roaming\npm-cache\_logs\2019-07-01T10_49_32_819Z-debug.log
まず、「cordova-plugin-crypt-file」プラグインをインストールします。
|
1 |
cordova plugin add cordova-plugin-crypt-file |
「C:\app\test\plugins\cordova-plugin-crypt-file\hooks」フォルダにある「after_prepare.js」というファイルの34,58行目を修正します。
Before
|
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
findCryptFiles(wwwDir).filter(function(file) { return isCryptFile(file.replace(wwwDir, '')); }).forEach(function(file) { var content = fs.readFileSync(file, 'utf-8'); fs.writeFileSync(file, encryptData(content, key, iv), 'utf-8'); console.log('encrypt: ' + file); }); if (platform == 'ios') { var pluginDir; try { var ios_parser = context.requireCordovaModule('cordova-lib/src/cordova/metadata/ios_parser'), iosParser = new ios_parser(platformPath); pluginDir = path.join(iosParser.cordovaproj, 'Plugins', context.opts.plugin.id); } catch (err) { var xcodeproj_dir = fs.readdirSync(platformPath).filter(function(e) { return e.match(/\.xcodeproj$/i); })[0], xcodeproj = path.join(platformPath, xcodeproj_dir), originalName = xcodeproj.substring(xcodeproj.lastIndexOf(path.sep)+1, xcodeproj.indexOf('.xcodeproj')), cordovaproj = path.join(platformPath, originalName); pluginDir = path.join(cordovaproj, 'Plugins', context.opts.plugin.id); } replaceCryptKey_ios(pluginDir, key, iv); } else if (platform == 'android') { var pluginDir = path.join(platformPath, 'src'); replaceCryptKey_android(pluginDir, key, iv); var cfg = new ConfigParser(platformInfo.projectConfig.path); cfg.doc.getroot().getchildren().filter(function(child, idx, arr) { return (child.tag == 'content'); }).forEach(function(child) { child.attrib.src = '/+++/' + child.attrib.src; }); cfg.write(); } |
After
|
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
findCryptFiles(wwwDir).filter(function(file) { return fs.statSync(file).isFile() && isCryptFile(file.replace(wwwDir, '')); }).forEach(function(file) { var content = fs.readFileSync(file, 'utf-8'); fs.writeFileSync(file, encryptData(content, key, iv), 'utf-8'); console.log('encrypt: ' + file); }); if (platform == 'ios') { var pluginDir; try { var ios_parser = context.requireCordovaModule('cordova-lib/src/cordova/metadata/ios_parser'), iosParser = new ios_parser(platformPath); pluginDir = path.join(iosParser.cordovaproj, 'Plugins', context.opts.plugin.id); } catch (err) { var xcodeproj_dir = fs.readdirSync(platformPath).filter(function(e) { return e.match(/\.xcodeproj$/i); })[0], xcodeproj = path.join(platformPath, xcodeproj_dir), originalName = xcodeproj.substring(xcodeproj.lastIndexOf(path.sep)+1, xcodeproj.indexOf('.xcodeproj')), cordovaproj = path.join(platformPath, originalName); pluginDir = path.join(cordovaproj, 'Plugins', context.opts.plugin.id); } replaceCryptKey_ios(pluginDir, key, iv); } else if (platform == 'android') { var pluginDir = path.join(platformPath, 'app/src/main/java'); replaceCryptKey_android(pluginDir, key, iv); var cfg = new ConfigParser(platformInfo.projectConfig.path); cfg.doc.getroot().getchildren().filter(function(child, idx, arr) { return (child.tag == 'content'); }).forEach(function(child) { child.attrib.src = '/+++/' + child.attrib.src; }); cfg.write(); } |
リリースビルドを実行し、作成されたapkファイルをzipとして解凍して暗号化したファイルを確認します。
対象のファイルを開き、「QTS17KfUkfeQJY8+jO2HKbzRUZs+・・・」のように暗号化されていれば成功です。
![]() |
新品価格 |
![]()







