1

Apologies for the dramatic title but am having lots of frustrations around ionic and local notifications. I had built an app using ionic 2 which was using local notifications. I have upgraded to ionic3 and have tried everything but cannot get local notifications to work.

The latest version of local notifications do not support ionic so I have to use an earlier version 0.8.4 or 0.8.5. But trying to install these versions throws errors. I have tried everything including starting a clean ionic3 project and installing the local notifications. (for eg I tried following this http://masteringionic.com/blog/2018-01-09-adding-local-notifications-to-an-ionic-framework-mobile-app/)

Nothing is working. Not sure how we are meant to use Ionic as a production framework without having local notifications??

Has anyone got this working or got any advice?

Thanks

Update: Lately even just trying to install the local notification is failing

Failed to install 'de.appplant.cordova.plugin.local-notification': CordovaError: Failed to fetch plugin cordova-plugin-app-event via registry

Update: I have made a little progress. I played around some more and decided to look at another older ionic project i have that uses local notifications. it was using a specific version of local notifications so I went and installed that specific version.

npm install @ionic-native/local-notifications@3.12.1

After doing that I could run ionic build and it completed without failures!! Good news!. Bad news - when I run ionic serve it launches the app but with a white screen and a console error of: I get an error that says

polyfills.js:3 Unhandled Promise rejection: No provider for LocalNotifications! ; Zone: ; Task: Promise.then ; Value: Error: No provider for LocalNotifications!

Even though i HAVE added it to my list of providers in my app module.

When I try run an android build I get the error below. I am officially out of ideas. Any help???

FAILURE: Build failed with an exception. What went wrong: Execution failed for task ':transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper; BUILD FAILED Total time: 29.376 secs Error: cmd: Command failed with exit code 1 Error output: FAILURE: Build failed with an exception. Execution failed for task ':transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper;

Gotts
  • 2,274
  • 3
  • 23
  • 32
  • Have you tried something here ? https://github.com/katzer/cordova-plugin-local-notifications/issues/1345. Especially npm version or --nofetch ? – e666 Aug 21 '18 at 15:29
  • yes tried that too. The adding of the plugin works with --nofetch but then the build breaks. If anyone can come up with steps to get this all working in a clean ionic3 project it would be very helpful. I am stuck! – Gotts Aug 21 '18 at 19:31
  • Can you provide the build error that you get ? – e666 Aug 22 '18 at 14:50
  • I added some details to the question based on some developments but I am still out of luck! – Gotts Aug 29 '18 at 14:23
  • Any good news ? @Gotts In Ionic 4 they were working in dev.apk and now in build doesn't give an error but the pages don't open ... To test I just put constructor( private localNot: LocalNotifications) and not using yet localNot and stop open the page. If I remove opens the page. – Inês Gomes May 06 '19 at 18:44
  • Possible duplicate of [Multiple dex files define Lorg/apache/cordova/BuildHelper](https://stackoverflow.com/questions/46562289/multiple-dex-files-define-lorg-apache-cordova-buildhelper) – Khurshid Ansari May 07 '19 at 11:20
  • Its absolutely not a duplicate of that question. Trying to get local notifications to work had resulted in various issues including that one (which I had tried resolving the same way) but thats not the main point of my question. – Gotts May 07 '19 at 11:54
  • @InêsGomes i did make some progress. See my suggested answer below – Gotts May 07 '19 at 11:54

2 Answers2

1

In Package.json I upgraded

 "@ionic-native/local-notifications": "^5.5.1"

and is working now.

I did

$npm i -g npm-check-updates
$npm-check-updates -u
$npm install

But upgrade everything with lost of errors. So I did rollback from package.json and package-lock.json

And then decided to change manually only in package.json

"@ionic-native/local-notifications": "^5.5.1"

Then did:

$npm install

Note: $npm-check-updates -u. gave me a list like this:

 @angular/common                           ^7.2.2  →  ^7.2.14 
 @angular/core                             ^7.2.2  →  ^7.2.14 
 @angular/forms                            ^7.2.2  →  ^7.2.14 
 @angular/http                             ^7.2.2  →  ^7.2.14 
 @angular/platform-browser                 ^7.2.2  →  ^7.2.14 
 @angular/platform-browser-dynamic         ^7.2.2  →  ^7.2.14 
 @angular/router                           ^7.2.2  →  ^7.2.14 
 @angular/service-worker                   ^7.2.8  →  ^7.2.14 
 @ionic-native/camera                      ^5.2.0  →   ^5.5.1 
 @ionic-native/core                        ^5.0.0  →   ^5.5.1 
 @ionic-native/device                      ^5.3.0  →   ^5.5.1 
 @ionic-native/file                        ^5.2.0  →   ^5.5.1 
 @ionic-native/file-path                   ^5.2.0  →   ^5.5.1 
 @ionic-native/ionic-webview               ^5.2.0  →   ^5.5.1 

 @ionic-native/local-notifications         ^5.2.0  →   ^5.5.1 

 @ionic-native/native-audio                ^5.2.0  →   ^5.5.1 
 @ionic-native/network                     ^5.2.0  →   ^5.5.1 
 @ionic-native/power-management            ^5.4.0  →   ^5.5.1 
 @ionic-native/splash-screen               ^5.0.0  →   ^5.5.1 
 @ionic-native/status-bar                  ^5.0.0  →   ^5.5.1 
 @ionic/angular                            ^4.1.0  →   ^4.3.1 
 cordova-android                            7.1.4  →    8.0.0 
 cordova-android-support-gradle-release    ^2.0.1  →   ^3.0.0 
 cordova-plugin-filepath                    1.5.1  →    1.5.4 
 cordova-plugin-ionic-webview              ^3.1.2  →   ^4.0.1 
 cordova-sqlite-storage                     3.1.0  →    3.2.0 
 core-js                                   ^2.5.4  →   ^3.0.1 
 ionic-selectable                          ^4.4.0  →   ^4.4.1 
 rxjs                                      ~6.3.3  →   ~6.5.1 
 zone.js                                  ~0.8.29  →   ~0.9.1 
 @angular-devkit/architect                ~0.12.3  →  ~0.13.8 
 @angular-devkit/build-angular            ~0.13.0  →  ~0.13.8 
 @angular-devkit/core                      ~7.2.3  →   ~7.3.8 
 @angular-devkit/schematics                ~7.2.3  →   ~7.3.8 
 @angular/cli                              ~7.3.1  →   ~7.3.8 
 @angular/compiler                         ~7.2.2  →  ~7.2.14 
 @angular/compiler-cli                     ~7.2.2  →  ~7.2.14 
 @angular/language-service                 ~7.2.2  →  ~7.2.14 
 @ionic/angular-toolkit                    ~1.4.0  →   ~1.5.1 
 @types/jasmine                            ~2.8.8  →  ~3.3.12 
 @types/jasminewd2                         ~2.0.3  →   ~2.0.6 
 @types/node                             ~10.12.0  →  ~12.0.0 
 codelyzer                                 ~4.5.0  →   ~5.0.1 
 jasmine-core                             ~2.99.1  →   ~3.4.0 
 karma                                     ~3.1.4  →   ~4.1.0 
 karma-coverage-istanbul-reporter          ~2.0.1  →   ~2.0.5 
 karma-jasmine                             ~1.1.2  →   ~2.0.1 
 karma-jasmine-html-reporter               ^0.2.2  →   ^1.4.2 
 protractor                                ~5.4.0  →   ~5.4.2 
 ts-node                                   ~8.0.0  →   ~8.1.0 
 tslint                                   ~5.12.0  →  ~5.16.0 
 typescript                                ~3.1.6  →   ~3.4.5 

So I could decide what to upgrade

Inês Gomes
  • 4,313
  • 1
  • 24
  • 32
  • i didnt realize you had posted an answer. I will maybe give this a try. right now it seems simpler just leaving ionic-native out of it and accessing the cordova library directly – Gotts May 07 '19 at 11:56
0

In the end, I resorted to using the Cordova plugin directly without using the ionic native layer. As a result, I was able to use a fork of the local-notifications which so far has been working fine in all devices - android and ios.

I simply added this Cordova plugin as per my packages.json

"cordova-plugin-local-notification": "git+https://github.com/Steffaan/cordova-plugin-local-notifications.git",

Then my code looks something like this...

import {Platform} from 'ionic-angular';
import { environment } from '../../environments/environment.prod';
declare var cordova;

@Injectable()
export class Notifications {

    localNotifications: any;

    constructor(public storage: Storage,   public platform: Platform, public settings: Settings) {
            this.localNotifications = cordova.plugins.notification.local;
    }

    getAllNotifications(): Promise<any[]> {

      return new Promise(resolve => {
         this.localNotifications.getAll(resolve);
       });

    }
etc...
user9088454
  • 1,076
  • 1
  • 15
  • 45
Gotts
  • 2,274
  • 3
  • 23
  • 32