skip to Main Content

I’ve written a mobile app in flutter/dart. For the app, the flutter_nfc_kit is required. The latest version of the package is added to the pubspec.yaml file with flutter_nfc_kit: ^3.3.3 under dependencies. The problem is now that when I importing the package to the dart file (with import 'package:flutter_nfc_kit/flutter_nfc_kit.dart';), the build fails.

Here is minialistic code that causes the error:

import 'package:flutter/material.dart';
//import 'package:flutter_nfc_kit/flutter_nfc_kit.dart'; // uncommenting will case the error

void main() => runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(),
    ),
));

This is the error I get, when building the project:

../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_nfc_kit-3.3.3/lib/flutter_nfc_kit.dart:146:30: Error: The method 'toHexString' isn't defined for the class 'Uint8List'.
 - 'Uint8List' is from 'dart:typed_data'.
Try correcting the name to the name of an existing method, or defining a method named 'toHexString'.
    return NDEFRawRecord(id?.toHexString() ?? '', payload?.toHexString() ?? '',
                             ^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_nfc_kit-3.3.3/lib/flutter_nfc_kit.dart:146:60: Error: The method 'toHexString' isn't defined for the class 'Uint8List'.
 - 'Uint8List' is from 'dart:typed_data'.
Try correcting the name to the name of an existing method, or defining a method named 'toHexString'.
    return NDEFRawRecord(id?.toHexString() ?? '', payload?.toHexString() ?? '',
                                                           ^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_nfc_kit-3.3.3/lib/flutter_nfc_kit.dart:147:15: Error: The method 'toHexString' isn't defined for the class 'Uint8List'.
 - 'Uint8List' is from 'dart:typed_data'.
Try correcting the name to the name of an existing method, or defining a method named 'toHexString'.
        type?.toHexString() ?? '', this.tnf);
              ^^^^^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_nfc_kit-3.3.3/lib/flutter_nfc_kit.dart:154:38: Error: The method 'toBytes' isn't defined for the class 'String'.
Try correcting the name to the name of an existing method, or defining a method named 'toBytes'.
        raw.typeNameFormat, raw.type.toBytes(), raw.payload.toBytes(),
                                     ^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_nfc_kit-3.3.3/lib/flutter_nfc_kit.dart:154:61: Error: The method 'toBytes' isn't defined for the class 'String'.
Try correcting the name to the name of an existing method, or defining a method named 'toBytes'.
        raw.typeNameFormat, raw.type.toBytes(), raw.payload.toBytes(),
                                                            ^^^^^^^
../../../AppData/Local/Pub/Cache/hosted/pub.dev/flutter_nfc_kit-3.3.3/lib/flutter_nfc_kit.dart:155:58: Error: The method 'toBytes' isn't defined for the class 'String'.
Try correcting the name to the name of an existing method, or defining a method named 'toBytes'.
        id: raw.identifier == "" ? null : raw.identifier.toBytes());
                                                         ^^^^^^^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:UsersPublicProgramsflutterbinflutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 22s
Exception: Gradle task assembleDebug failed with exit code 1

Here are some info regarding the versions:

  • Android Studio version: 2022.3.1 Patch 2
  • SDK: Android API 34, extension level 7 Platform (got from File->Project Structure…-> Project)
  • ext.kotlin_version = 1.9.12 (got from build.grandle)
  • Grandle version: com.android.tools.build:gradle:7.3.0 (got from build.grandle)
  • distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip (got from grandle-wrapper.properties)

Please let me know if I am missing something.

We have also tried to build the project on another windows 11 PC. The issue still exists.
And we have found out that flutter_nfc_kit was build for the kotlin_version=1.6.0, where changing did still result in the error.

Do you have any suggestions?

Thanks,
Mario.

2

Answers


  1. Chosen as BEST ANSWER

    It is probably not the best (or any) solution, but for me it solved my problem. As I do not need any NDEF functionality, I just changed the the code, which cannot be found by the build tools. E.g. instead of raw.type.toBytes(), I just used any string. As said, no real solution, but it solved my problem.

    Thanks for any contribution.


  2. Do you happened to have uuid [https://pub.dev/packages/uuid] in your dependencies?

    If yes, you can try to downgrade it to uuid: ^3.0.7

    4.0.0 and above might have caused this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search