Ionic NFC cordova plugin_not_installed

Discussão em 'Angular' iniciado por Manuel Sureda, Novembro 12, 2024.

  1. Apparently my app does not recognize the NFC plugin or it does not know how to install it correctly.

    I'm trying to make an app with angular Ionic + capacitor. One of the components must be able to read NFC messages.

    Since I am a student and I have no previous experience working with Ionic and my experience with Angular is very limited, I will try to comment step by step on what I did.

    Searching the internet I found this: https://www.npmjs.com/package/@awesome-cordova-plugins/nfc

    so I did the following:

    npm install @awesome-cordova-plugins/nfc
    npm install @awesome-cordova-plugins/core

    and in NfcReaderComponent I try the following:

    import { NFC } from '@awesome-cordova-plugins/nfc/ngx';
    ...
    constructor(
    private nfc: NFC, <--
    private ticketService: TicketService,
    private transportService: TransportService,
    private router: Router
    ) { }
    ...


    Now when I try to open said component this error appears:

    ERROR NullInjectorError: NullInjectorError: No provider for [object Object]!
    at NullInjector.get (core.mjs:1660:27)
    at R3Injector.get (core.mjs:3106:33)
    at R3Injector.get (core.mjs:3106:33)
    at R3Injector.get (core.mjs:3106:33)
    at ChainedInjector.get (core.mjs:16754:36)
    at lookupTokenUsingModuleInjector (core.mjs:5747:39)
    at getOrCreateInjectable(core.mjs:5795:12)
    at Module.ɵɵdirectiveInject (core.mjs:11331:19)
    at NodeInjectorFactory.NfcReaderComponent_Factory [as factory] (nfc-reader.component.ts:25:32)
    at getNodeInjectable (core.mjs:6007:44)


    i also get this error on android studio: plugin_not_installed

    link to the repo: https://github.com/ManuSureda/SUBD-T

    I think I'm not installing or provisioning the plugin correctly, but I don't really understand how to fix this.

    Update:

    Apparently I needed to install phonegap-nfc too

    npm i phonegap-nfc


    now it lets me inject NFC into app.module.ts

    ...
    import { NFC } from '@awesome-cordova-plugins/nfc/ngx';

    @NgModule({
    declarations: [AppComponent],
    imports: [...],
    providers: [
    ...
    NFC
    ],
    bootstrap: [AppComponent],
    })
    export class AppModule {}


    with 'ionic serve' seems to work just fine but i share this warning just in case that it matters: Native: tried calling NFC.enabled, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

    now the new problem is:

    when i try to run the app through android studio i got this error:

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':capacitor-cordova-android-plugins:compileDebugJavaWithJavac'.

    Compilation failed; see the compiler error output for details.
    ​
    • Try:

    Run with --info option to get more log output. Run with --scan to get full insights.
    ​
    • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':capacitor-cordova-android-plugins:compileDebugJavaWithJavac'.<30 internal lines> Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details. <149 internal lines>

    Task :capacitor-cordova-android-plugins:compileDebugJavaWithJavac FAILED C:\Users\Manuel\Desktop\Seminario-UTN\Frontend\SUBD-transport\android\capacitor-cordova-android-plugins\src\main\java\com\chariotsolutions\nfc\plugin\NfcPlugin.java:550: error: cannot find symbol nfcAdapter.setNdefPushMessage(p2pMessage, getActivity()); ^ symbol: method setNdefPushMessage(NdefMessage,Activity) location: variable nfcAdapter of type NfcAdapter
    ​

    Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\Users\Manuel\Desktop\Seminario-UTN\Frontend\SUBD-transport\android\capacitor-cordova-android-plugins\src\main\java\cordova\plugins\Diagnostic.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 9 errors

    Continue reading...

Compartilhe esta Página