NativeScript / nativescript-background-http

Background Upload plugin for the NativeScript framework
Apache License 2.0
102 stars 50 forks source link

App crash upon running the uploadFile() function #188

Closed johnRosalin closed 5 years ago

johnRosalin commented 5 years ago

Make sure to check the demo app(s) for sample usage

I followed the documentation on how to implement this.

Make sure to check the existing issues in this repository

I have not found a similar issue with this error I am encountering

If the demo apps cannot help and there is no issue for your problem, tell us about it

Here is the error code that I get.

An uncaught Exception occurred on "pool-6-thread-1" thread.
java.lang.NoSuchMethodError: No direct method <init>(Landroid/content/Context;Ljava/lang/String;)V in class Landroid/support/v4/app/NotificationCompat$Builder; or its super classes (declaration of 'android.support.v4.app.NotificationCompat$Builder' appears in /data/app/org.nativescript.<project-name>-HISZFFfYBByn6TeN9KmHyA==/base.apk)
at net.gotev.uploadservice.UploadTask.createNotification(UploadTask.java:453)
at net.gotev.uploadservice.UploadTask.run(UploadTask.java:145)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)

Which platform(s) does your issue occur on ?

Please, provide the following version numbers that your issue occurs with:

Here is my package.json file content

{
  "nativescript": {
    "id": "org.nativescript.<project-name>",
    "tns-ios": {
      "version": "4.2.0"
    },
    "tns-android": {
      "version": "4.2.0"
    }
  },
  "description": "<project-name> NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "repository": "<fill-your-repository-here>",
  "scripts": {
    "lint": "tslint \"app/**/*.ts\""
  },
  "dependencies": {
    "@angular/animations": "~6.1.0",
    "@angular/common": "~6.1.0",
    "@angular/compiler": "~6.1.0",
    "@angular/core": "~6.1.0",
    "@angular/forms": "~6.1.0",
    "@angular/http": "~6.1.0",
    "@angular/platform-browser": "~6.1.0",
    "@angular/platform-browser-dynamic": "~6.1.0",
    "@angular/router": "~6.1.0",
    "email-validator": "^2.0.4",
    "google-libphonenumber": "^3.1.14",
    "nativescript-angular": "~6.1.0",
    "nativescript-appinfo": "^0.4.1",
    "nativescript-background-http": "^3.3.1",
    "nativescript-fingerprint-auth": "^6.2.0",
    "nativescript-mediafilepicker": "^2.0.14",
    "nativescript-permissions": "^1.2.3",
    "nativescript-pulltorefresh": "^2.1.1",
    "nativescript-ripple": "^2.1.0",
    "nativescript-social-login": "^4.0.1",
    "nativescript-sqlite": "^2.2.1",
    "nativescript-theme-core": "~1.0.4",
    "nativescript-ui-autocomplete": "^3.9.0",
    "nativescript-ui-chart": "^3.9.0",
    "nativescript-ui-dataform": "^3.7.2",
    "nativescript-ui-sidedrawer": "~4.2.0",
    "reflect-metadata": "~0.1.10",
    "rxjs": "~6.2.0",
    "tns-core-modules": "~4.2.0",
    "zone.js": "~0.8.18"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~6.1.0",
    "@ngtools/webpack": "~6.1.0",
    "angular-router-loader": "^0.8.5",
    "angular2-router-loader": "^0.3.5",
    "angular2-template-loader": "^0.6.2",
    "codelyzer": "~4.3.0",
    "nativescript-dev-sass": "~1.6.0",
    "nativescript-dev-typescript": "~0.7.0",
    "nativescript-dev-webpack": "^0.15.1",
    "nativescript-worker-loader": "^0.9.1",
    "ts-loader": "^4.5.0",
    "tslint": "~5.11.0",
    "typescript": "~2.7.2"
  },
  "readme": "NativeScript Application"
}

Please, tell us how to recreate the issue in as much detail as possible.

I tried many ways to reproduce this error, and I have narrowed it down to this. I noticed that this error will occur when my project has the nativescript-social-login plugin installed.

Is there any code involved ?

here is the method to start the file upload

// Upload selected file
uploadSelectedFile() {
    if (!this.selectedFiles || (this.selectedFiles && this.selectedFiles.length < 1)) {
        alert({
            title: "Error!",
            message: "Please select a file to upload.",
            okButtonText: "OK"
        });

        return;
    }

    let file = this.selectedFiles[0].path;
    let url = 'http://10.33.1.114:3000';
    let name = file.substr(file.lastIndexOf('/') + 1);

    let session = bghttp.session('image-upload');
    let request = {
        url: url,
        method: 'POST',
        headers: {
            'Content-Type': 'application/octet-stream'
        },
        description: `Uploading ${name}`
    };

    let task = session.uploadFile(file, request);

    task.on("progress", this.progressHandler);
    task.on("error", this.errorHandler);
    task.on("responded", this.respondedHandler);
    task.on("complete", this.completeHandler);
    task.on("cancelled", this.cancelledHandler);
}

private progressHandler = (e) => {
    alert("uploaded " + e.currentBytes + " / " + e.totalBytes);
}

private errorHandler = (e) => {
    alert("received " + e.responseCode + " code.");
    var serverResponse = e.response;
}

private respondedHandler = (e) => {
    alert("received " + e.responseCode + " code. Server sent: " + e.data);
}

private completeHandler = (e) => {
    alert("received " + e.responseCode + " code");
    var serverResponse = e.response;
}

private cancelledHandler = (e) => {
    alert("upload cancelled");
}
tbozhikov commented 5 years ago

Hi @johnRosalin, here's a thread about an issue that looks very similar to yours. Maybe a removal of nativescript-social-login (if you don't use it), or some change in app.gradle can fix that? Let us know if this helps.

johnRosalin commented 5 years ago

I actually needed the social-login plugin for my app so I tried updating the app.gradle and it fixed the crash issue. thank you so much!