CORDOVA :添加cordova-plugin-file-opener2插件cordova打包報錯
阿新 • • 發佈:2019-01-07
技術分享 transfer () sans url data head 需要 == 原文:CORDOVA :添加cordova-plugin-file-opener2插件cordova打包報錯
最近在接觸android項目,其中涉及到APP自動更新的問題,當新APP下載成功後需要打開調用cordova.plugins.fileOpener2.open,但是當引用了cordova-plugin-file-opener2插件後,重新打包項目發現報錯;
代碼:
function downloadFile() { $(‘#bbsm‘).css({ ‘height‘ : ‘200px‘, ‘padding-top‘ : ‘20px‘, ‘text-align‘ : ‘center‘, ‘font-size‘ : ‘18px‘, ‘font-weight‘ : ‘bold‘, ‘line-height‘ : ‘180px‘ }); document.getElementById("bbsm").innerHTML = ‘‘ + ‘<div class="progress progress-striped active">‘ + ‘<div id="jdt_div" class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="">‘ + ‘</div>‘ + ‘</div>‘; // 下載路徑 var uri = encodeURI(Mobile_download); var file = cordova.file.externalDataDirectory; // 保存路徑 var fileURL = encodeURI(file + ‘update.apk‘); fileTransfer.download(uri, fileURL, function(entry) { // 下載成功打開文件 cordova.plugins.fileOpener2.open(entry.toURL(), ‘application/vnd.android.package-archive‘).then(function() { }, function(err) { }); }, function(error) { // 下載失敗 }, false, { headers : { "Authorization" : "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" } });
報錯信息如下:
最後通過查找各種資料終於解決了問題,解決方案:
在Android項目中找到platforms\android\app, 創建一個build-extras.gradle,內容為:
configurations.all {
? ? resolutionStrategy {
? ? ? ? force ‘com.android.support:support-v4:27.1.0‘
? ? }
}
如圖:
以上內容若有錯誤,歡迎批評指正。
CORDOVA :添加cordova-plugin-file-opener2插件cordova打包報錯