cordova-plugin-background-upload
cordova-plugin-background-upload copied to clipboard
Unable to build
Have had this plugin working for a while but recently ran into an issue where I cannot get my app to build anymore. I created a fresh app and tried to build with just this plugin and I'm still failing.
Cordova cli version 11.0.0 Android version 10.1.1 Plugin version 2.0.7
Error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find net.gotev:uploadservice:3.5.2.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/net/gotev/uploadservice/3.5.2/uploadservice-3.5.2.pom
- https://repo.maven.apache.org/maven2/net/gotev/uploadservice/3.5.2/uploadservice-3.5.2.pom
Required by:
project :app
> Could not find net.gotev:uploadservice-okhttp:3.5.2.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/net/gotev/uploadservice-okhttp/3.5.2/uploadservice-okhttp-3.5.2.pom
- https://repo.maven.apache.org/maven2/net/gotev/uploadservice-okhttp/3.5.2/uploadservice-okhttp-3.5.2.pom
Required by:
project :app
> Could not find com.sromku:simple-storage:1.2.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/sromku/simple-storage/1.2.0/simple-storage-1.2.0.pom
- https://repo.maven.apache.org/maven2/com/sromku/simple-storage/1.2.0/simple-storage-1.2.0.pom
Required by:
project :app
Package.json
{
"name": "com.test.app",
"displayName": "test-app",
"version": "1.0.0",
"description": "A sample Apache Cordova application that responds to the deviceready event.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"ecosystem:cordova"
],
"author": "Apache Cordova Team",
"license": "Apache-2.0",
"devDependencies": {
"cordova-android": "^10.1.1",
"cordova-plugin-androidx": "^1.0.2",
"cordova-plugin-androidx-adapter": "^1.1.0",
"cordova-plugin-background-upload": "^1.1.0"
},
"cordova": {
"platforms": [
"android"
],
"plugins": {
"cordova-plugin-background-upload": {}
}
},
"dependencies": {}
}
gradle.properties
cdvMinSdkVersion = 30
compileSdkVersion = 30
cdvMinSdkVersion = 30
org.gradle.jvmargs=-Xmx2048m
android.useAndroidX=true
android.enableJetifier=true
@albertleao your plugin version is actually 1.1.0 in your example even though you specified that you are using plugin version 2.0.7 I too have been getting the same error when moving to Cordova Android 10. I found that cordova plugin add cordova-plugin-background-upload@latest actually installs 1.1.0. I used cordova plugin add https://github.com/spoonconsulting/cordova-plugin-background-upload.git#2.0.3 and it gave me the latest stable build, however, I get the same error above but with version net.gotev:uploadservice:4.0.0 and net.gotev:uploadservice-okhttp:4.0.0
Yep, got it.
I created a branch and updated the framework source for both frameworks that were not found.
<framework src="net.gotev:uploadservice:4.5.5" />
<framework src="net.gotev:uploadservice-okhttp:4.5.5" />
The problem now is that the com.sromku:simple-storage:1.2.1 framework dependency can't be found. Looks like gradle isn't looking at the correct repo. trying to figure that out now.
Try building off this guy and at least the first 2 errors are gone
https://github.com/albertleao/cordova-plugin-background-upload/commit/e62f996143ee2130637d63b2092be7d49c6ded8f
My new package.json
{
"name": "com.test.app",
"displayName": "test-app",
"version": "1.0.0",
"description": "A sample Apache Cordova application that responds to the deviceready event.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"ecosystem:cordova"
],
"author": "Apache Cordova Team",
"license": "Apache-2.0",
"devDependencies": {
"@spoonconsulting/cordova-plugin-background-upload": "git+https://github.com/albertleao/cordova-plugin-background-upload.git#e62f996143ee2130637d63b2092be7d49c6ded8f",
"cordova-android": "^10.1.1",
"cordova-plugin-androidx": "^1.0.2",
"cordova-plugin-androidx-adapter": "^1.1.0",
"cordova-plugin-file": "^6.0.2"
},
"cordova": {
"platforms": [
"android"
],
"plugins": {
"@spoonconsulting/cordova-plugin-background-upload": {}
}
},
"dependencies": {}
}
I see @zafirskthelifehacker had a pull request to simply remove the simple storage framework. I have no idea whether or not this works. Going to give it a shot
https://github.com/spoonconsulting/cordova-plugin-background-upload/pull/171
And the answer to that question is no
test-app/platforms/android/app/src/main/java/com/spoon/backgroundfileupload/ManagerService.java:21: error: package com.sromku.simple.storage does not exist
Looks like this repo might be SOL if there's not a decent mirror for the simple storage library
What do we thing an alternative is?
I will spend some more time tonight and tomorrow. At this point I'd love to hear from the maintainers as it seems that anyone who clears out or starts a new android project is hosed. I was unable to get gradle to point to other repositories that may have the required framework.
Hi @albertleao, Please make sure the plugin name is prefix with @spoonconsulting. See example below.
{
"name": "com.test.app",
"displayName": "test-app",
"version": "1.0.0",
"description": "A sample Apache Cordova application that responds to the deviceready event.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"ecosystem:cordova"
],
"author": "Apache Cordova Team",
"license": "Apache-2.0",
+ "dependencies": {
+ "@spoonconsulting/cordova-plugin-background-upload": "2.0.7"
+},
"devDependencies": {
"cordova-android": "^10.1.1",
"cordova-plugin-androidx": "^1.0.2",
"cordova-plugin-androidx-adapter": "^1.1.0",
- "cordova-plugin-background-upload": "^1.1.0",
},
"cordova": {
"platforms": [
"android"
],
"plugins": {
- "cordova-plugin-background-upload": {}
+ "@spoonconsulting/cordova-plugin-background-upload": {}
}
},
"dependencies": {}
I had upgraded to using Gradle 7.1.1 (from 5.6.3) and found repositories.gradle had changed from:
ext.repos = { google() jcenter() }
to
ext.repos = { google() mavenCentral() }
Had read about JCenter shutdown and impact on Gradle builds, is this part of the issue? https://blog.gradle.org/jcenter-shutdown#:~:text=The%20Gradle%20Build%20Init%20plugin,used%20as%20an%20example%20repository.&text=Gradle%20itself%20has%20no%20inherent,other%20repository%20of%20your%20choice.
@hughknaus it built this way?
Yeah, it built that way... I didn't modify it any way. We have experimented with adding jcenter() back in but not fully convinced that it solves everything... still trying to get a build through our CI/CD system.
I readded jcenter to my gradle repositories and am still getting the error.
Our whole goal has been to upgrade to SDK Version 30, far from our ideal path, we updated cordova-android to 10.1.1 (11 for CLI), went back to 1.1.0 for cordova-plugin-background-upload, added jcenter() to repositories.gradle, and also had to add cdvMinSdkVersion=24 cdvCompileSdkVersion=30 compileSdkVersion=30 to gradle.properties utilizing a before_build hook (because we were getting errors that they couldn't be found). We're running Bumblebee 2021.1.1 Patch 1 with Gradle 7.2 and Android Gradle plugin 7.1.1.
We successfully built, but we are now having issues in the app so not a win per se.
We tried 2.0.3 without and with @spoonconsulting as @dinitri-ragoo suggested but to no avail (hesitant to go beyond what is "latest stable version" for a production app but at this point willing to try just about anything).
@dinitri-ragoo for your successful builds with the cordova-plugin-background-upload, can you provide the following versions you are using in your build process:
- Android Cordova
- Gradle
- Android Gradle plugin
- cordova-plugin-background-upload
- Android SDK version
Working with @hughknaus, we've found we have to add the jCenter() repo back into repositories.gradle in order to get past the errors specified above for the following: net.gotev:uploadservice:3.5.2 net.gotev:uploadservice-okhttp:3.5.2 com.sromku:simple-storage:1.2.0
These are needed with cordova-plugin-background-upload@latest which I believe translates to version v1.1.0
My gradle.repositories:
ext.repos = {
google()
jcenter()
mavenCentral()
}
build.gradle
buildscript {
apply from: 'CordovaLib/cordova.gradle'
apply from: 'repositories.gradle'
repositories repos
dependencies {
classpath "com.android.tools.build:gradle:${cordovaConfig.AGP_VERSION}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${cordovaConfig.KOTLIN_VERSION}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
def hasRepositoriesGradle = file('repositories.gradle').exists()
if (hasRepositoriesGradle) {
apply from: 'repositories.gradle'
} else {
apply from: "${project.rootDir}/repositories.gradle"
}
repositories repos
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Running cordova plugin ls yields the following
cordova-plugin-androidx-adapter 1.1.0 "cordova-plugin-androidx-adapter"
cordova-plugin-androidx 1.0.2 "cordova-plugin-androidx"
cordova-plugin-background-upload 1.1.0 "Cordova Background Upload Plugin"
Still running into issues finding all packages now:
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find net.gotev:uploadservice:3.5.2.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/net/gotev/uploadservice/3.5.2/uploadservice-3.5.2.pom
- https://repo.maven.apache.org/maven2/net/gotev/uploadservice/3.5.2/uploadservice-3.5.2.pom
Required by:
project :app
> Could not find net.gotev:uploadservice-okhttp:3.5.2.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/net/gotev/uploadservice-okhttp/3.5.2/uploadservice-okhttp-3.5.2.pom
- https://repo.maven.apache.org/maven2/net/gotev/uploadservice-okhttp/3.5.2/uploadservice-okhttp-3.5.2.pom
Required by:
project :app
> Could not find com.sromku:simple-storage:1.2.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/sromku/simple-storage/1.2.0/simple-storage-1.2.0.pom
- https://repo.maven.apache.org/maven2/com/sromku/simple-storage/1.2.0/simple-storage-1.2.0.pom
Required by:
project :app
If you could share how you got it to build it would be much appreciated.
Hello @albertleao @hughknaus @bruffster,
Make sure that you are using SDK 31 and also v2.0.7 of the plugin.
cordova: 10.0.0 (CLI) cordova-android: 10.1.1 Gradle: 7.1.1 cordova-plugin-background-upload: 2.0.7 Android SDK Version: 30.0.3 Java Version: 11
We are targeting SDK version 31 in the config.xml:
<preference name="android-targetSdkVersion" value="31" />
Also make sure you have jcenter()
Regards, Zafir Spoon Consulting LTD
@zafirskthelifehacker when you say "Also make sure you have jcenter()" is there a recommended way of adding it? I can manually do that locally but that wont work when someone else installs from source or our CICD goes to build it. How would you recommend adding jcenter() back in and to which files?
@zafirskthelifehacker Followed your advice. Are you having to use --force to install the plugin? We get this:
Failed to install '@spoonconsulting/cordova-plugin-background-upload': Error: There was a conflict trying to modify attributes with
@schematical to add jcenter() in we are using a before_build hook to overwrite /platforms/android/app/repositories.gradle
@zafirskthelifehacker @dinitri-ragoo we are also seeing errors in logs when trying to upload an image on Android 11+ (Android 10 is working though):
2022-02-10 09:43:31.886 8432-8533/appname D/SERVER: Handling local request: http://localhost/83-es2015.811b6353bcb7a5829b14.js 2022-02-10 09:43:31.894 8432-8533/appname D/SERVER: Handling local request: http://localhost/svg/cloud.svg 2022-02-10 09:43:31.968 8432-8563/appname W/AssetFilesystem: Asset manifest not found. Recursive copies and directory listing will be slow. 2022-02-10 09:43:31.986 8432-8472/appname D/EGL_emulation: app_time_stats: avg=200.95ms min=11.76ms max=5099.04ms count=28 2022-02-10 09:43:32.374 8432-8603/appname W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'java.util.List com.sromku.simple.storage.Storage.getFiles(java.lang.String, com.sromku.simple.storage.helpers.OrderType)' on a null object reference 2022-02-10 09:43:32.374 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.getUploadHistory(FileTransferBackground.java:288) 2022-02-10 09:43:32.375 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.upload(FileTransferBackground.java:171) 2022-02-10 09:43:32.375 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.execute(FileTransferBackground.java:148) 2022-02-10 09:43:32.376 8432-8603/appname W/System.err: at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98) 2022-02-10 09:43:32.376 8432-8603/appname W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:146) 2022-02-10 09:43:32.376 8432-8603/appname W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) 2022-02-10 09:43:32.377 8432-8603/appname W/System.err: at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) 2022-02-10 09:43:32.378 8432-8603/appname W/System.err: at android.os.MessageQueue.nativePollOnce(Native Method) 2022-02-10 09:43:32.378 8432-8603/appname W/System.err: at android.os.MessageQueue.next(MessageQueue.java:335) 2022-02-10 09:43:32.378 8432-8603/appname W/System.err: at android.os.Looper.loopOnce(Looper.java:161) 2022-02-10 09:43:32.378 8432-8603/appname W/System.err: at android.os.Looper.loop(Looper.java:288) 2022-02-10 09:43:32.379 8432-8603/appname W/System.err: at android.os.HandlerThread.run(HandlerThread.java:67) 2022-02-10 09:43:32.379 8432-8603/appname D/FileTransferBG: adding upload 8ef9cfa1-d9da-41bb-8132-1411265f2aa3 2022-02-10 09:43:32.380 8432-8603/appname W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.sromku.simple.storage.Storage.createFile(java.lang.String, java.lang.String, java.lang.String)' on a null object reference 2022-02-10 09:43:32.381 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.createUploadInfoFile(FileTransferBackground.java:250) 2022-02-10 09:43:32.381 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.upload(FileTransferBackground.java:184) 2022-02-10 09:43:32.382 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.execute(FileTransferBackground.java:148) 2022-02-10 09:43:32.382 8432-8603/appname W/System.err: at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98) 2022-02-10 09:43:32.382 8432-8603/appname W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:146) 2022-02-10 09:43:32.382 8432-8603/appname W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) 2022-02-10 09:43:32.382 8432-8603/appname W/System.err: at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) 2022-02-10 09:43:32.383 8432-8603/appname W/System.err: at android.os.MessageQueue.nativePollOnce(Native Method) 2022-02-10 09:43:32.383 8432-8603/appname W/System.err: at android.os.MessageQueue.next(MessageQueue.java:335) 2022-02-10 09:43:32.383 8432-8603/appname W/System.err: at android.os.Looper.loopOnce(Looper.java:161) 2022-02-10 09:43:32.383 8432-8603/appname W/System.err: at android.os.Looper.loop(Looper.java:288) 2022-02-10 09:43:32.384 8432-8603/appname W/System.err: at android.os.HandlerThread.run(HandlerThread.java:67) 2022-02-10 09:43:32.385 8432-8603/appname D/FileTransferBG: Upload failed. Image added to pending list 2022-02-10 09:43:32.385 8432-8603/appname W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.sromku.simple.storage.Storage.isFileExist(java.lang.String, java.lang.String)' on a null object reference 2022-02-10 09:43:32.386 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.updateStateForUpload(FileTransferBackground.java:259) 2022-02-10 09:43:32.386 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.upload(FileTransferBackground.java:216) 2022-02-10 09:43:32.386 8432-8603/appname W/System.err: at com.spoon.backgroundFileUpload.FileTransferBackground.execute(FileTransferBackground.java:148) 2022-02-10 09:43:32.387 8432-8603/appname W/System.err: at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98) 2022-02-10 09:43:32.387 8432-8603/appname W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:146) 2022-02-10 09:43:32.387 8432-8603/appname W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) 2022-02-10 09:43:32.387 8432-8603/appname W/System.err: at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) 2022-02-10 09:43:32.388 8432-8603/appname W/System.err: at android.os.MessageQueue.nativePollOnce(Native Method) 2022-02-10 09:43:32.388 8432-8603/appname W/System.err: at android.os.MessageQueue.next(MessageQueue.java:335) 2022-02-10 09:43:32.388 8432-8603/appname W/System.err: at android.os.Looper.loopOnce(Looper.java:161) 2022-02-10 09:43:32.388 8432-8603/appname W/System.err: at android.os.Looper.loop(Looper.java:288) 2022-02-10 09:43:32.389 8432-8603/appname W/System.err: at android.os.HandlerThread.run(HandlerThread.java:67) 2022-02-10 09:43:32.389 8432-8603/appname W/PluginManager: THREAD WARNING: exec() call to FileTransferBackground.startUpload blocked the main thread for 19ms. Plugin should use CordovaInterface.getThreadPool().
I got it to build but now I am not getting the callback to fire at the end. Possibly related to https://github.com/spoonconsulting/cordova-plugin-background-upload/issues/109 ?
Logcat would make me think the upload was successful(and the file is uploaded) but no callback.
2022-02-10 15:43:36.488 32285-3099/com.rocksolidstabilization.dispatch.v2.dev D/TEST: cdvfile://localhost/files/2022-2-10-debug.log: 80
2022-02-10 15:43:37.827 32285-32285/com.rocksolidstabilization.dispatch.v2.dev D/CordovaBackgroundUpload: eventLabel='Uploader onSuccess' uploadId='564' response=''
2022-02-10 15:43:37.827 32285-32285/com.rocksolidstabilization.dispatch.v2.dev D/CordovaBackgroundUpload: eventLabel='Uploader delete pending upload' uploadId='564'
2022-02-10 15:43:37.831 32285-32285/com.rocksolidstabilization.dispatch.v2.dev D/CordovaBackgroundUpload: eventLabel='Uploader delete pending upload' deleted_count=1
2022-02-10 15:43:37.833 32285-32285/com.rocksolidstabilization.dispatch.v2.dev I/Sugar: UploadEvent saved : 15
2022-02-10 15:43:37.833 32285-32285/com.rocksolidstabilization.dispatch.v2.dev D/CordovaBackgroundUpload: eventLabel='Uploader onCompleted' uploadId='564'
Further testing, I'm running into the same issue in #179 using 2.0.7, I have declare var FileTransferManager: any; in my file, I'm checking that the platform is ready and I get ...FileTransferManager is not defined
Through debugging on an emulator found that I don't see @spoonconsulting/cordova-plugin-background-upload in the /top/localhost/plugins folder where all the other Cordova plugins are, not sure why...

Everything seems to be working for me when using cordova-plugin-file-transfer 2.0.0-dev "File Transfer"
Found that in the package.json this package had to be moved higher in the list of plugins and I'm now able to build and run.
@hughknaus How's it going for you? My upload is working on android but none of my callbacks are ever being fired. When you say you moved it higher in the package.json, are you installing this plugin via npm or via the cordova plugin add command?
I have all the callbacks working. I did have to thoroughly change our implementation since we are coming from v1.1. We of course had been using the .on method which no longer exists and the callback is now injected into the .init method. Not to mention you also need to implement the new .acknowledgeEvent method. There is some strangeness with errorCodes and the switching from v1 to v2 when you have events in cache, the README says to expect a 500 error but we found that it always returns 0 and looking at their source i didn't see how we would ever get a 500.
Regaring plugin installation, I used cordova plugin [add|rm] ... --save but in the "plugins": {} section of the package.json it would always place the plugin at the bottom of the list. I found a random, unrelated StackOverflow post that suggested order of plugins can matter. So I manually move it to the top of the list and that was the breakthrough fo us. I experimented a little with it's placement in the list and I believe that it has to be above cordova-plugin-file-transfer and maybe above cordova-plugin-file.
I'm now running into issues with it when upgrading the iOS side from cordova-ios 5.1.1 to 6.2.0. This plugin (and it's the only plugin) throws an explicit error message that it requires CocoaPods for our project to build on our build server. CocoaPods install was trivial but still haven't gotten the iOS side to completely build, other factors at play though so still working on the iOS side.

Thank you so much for the info Hugh. I believe we had better luck with ios just working. Once I get android working I will give some feedback
@hughknaus Got my ios to build and upload, but none of the callbacks are working. I fixed my callback issue on android by ensure i called .destroy() after every upload.