paulobunga / c72-rfid-scanner

RFID Scanner module for Chainway C72 Scanner
12 stars 5 forks source link

Attempt to invoke virtual method 'java.lang.String com.rscja.deviceapi.entity.UHFTAGInfo.getEPC()' on a null object reference #34

Open Morton4idps opened 1 year ago

Morton4idps commented 1 year ago

"react-native": "0.71.3"

Test Android device is Google Pixel 6 (Android 13)

I don't have the c72 device yet, but I want to test it can be work first. I use sample code will show the error.

If click fun scanSingleTag show error: Attempt to invoke virtual method 'java.lang.String com.rscja.deviceapi.entity.UHFTAGInfo.getEPC()' on a null object reference

on a null object reference means it can be work ? Or just because I don't have the c72 device for testing ?

Here is part of the code from sample code:

import C72RfidScanner from 'c72-rfid-scanner';

  useEffect(() => {
    const scanner = C72RfidScanner;
    scanner.initializeReader();
    scanner.powerListener(powerListener);
    scanner.tagListener(tagListener);
    return () => scanner.deInitializeReader();
  }, []);

  const scanSingleTag = async () => {
    try {
      let result = await C72RfidScanner.readSingleTag();
      showAlert('SUCCESS', `The result is ${result}`);
      console.log(result);
    } catch (error) {
     // show object is null error
      console.log(error.message);
      showAlert('FAILED', error.message);
    }
  };

  return (
        <View style={{marginVertical: 20}}>
            <Button
              style={{margin: 10}}
              onPress={() => scanSingleTag()}
              title="Read Single Tag"
            />
          </View>
  );

Here is what I try step flow:

Step1: Can't install the package.

npm install c72-rfid-scanner --save

It will show error ERESOLVE unable to resolve dependency tree

截圖 2023-02-22 下午6 42 56

Step2: If use yarn

yarn add c72-rfid-scanner

build the project on Android will show error

Plugin with id 'maven' not found.

then change the code apply plugin: 'maven' to apply plugin: 'maven-publish' on node_modules/c72-rfid-scanner/android/build.gradle

build the project will show error

A problem occurred configuring project ':c72-rfid-scanner'.
> Configuration with name 'compile' not found.

Step3: then paste the code subprojects on android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
    }
    repositories {
        google()
        mavenCentral()
    }
    subprojects { subproject ->
        if(project['name'] == 'c72-rfid-scanner'){    
            project.configurations { compile { } }
    }
}
    dependencies {
        classpath("com.android.tools.build:gradle:7.3.1")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}

build project will show error Could not find method mavenDeployer() for arguments

Step4: commented out the code on node_modules/c72-rfid-scanner/android/build.grade

task installArchives(type: Upload) {
    configuration = configurations.archives
    repositories.mavenDeployer {
        // Deploy to react-native-event-bridge/maven, ready to publish to npm
        repository url: "file://${projectDir}/../android/maven"
        configureReactNativePom pom
    }
}

then build the project successfully and test the code.

seba-aguila commented 1 year ago

I have the c72 device and I get the same error when I try to read a single tag. I don't know what to do since I'm a beginner on android studio. Just to let you know, I also had the same error as you at trying to install the library, I just used npm install c72-rfid-scanner --force and then did the steps you pointed out above.

marcoamt commented 4 months ago

hi, you have to update the library, I'm currently using DeviceAPI_ver20231208_release.aar instead of .jar preinstalled in the module.