无法将 android 第三方扫描仪库加载到我的本机应用程序中 [英] unable to load an android third party scanner library into my react native app

查看:54
本文介绍了无法将 android 第三方扫描仪库加载到我的本机应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将条码扫描器的 SDK 集成到我的 react-native 应用程序中,但我不断收到错误消息:

I need to integrate the SDK of a barcode scanner into my react-native app but I keep getting an error:

Couldn't load XXX from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.mobile-1.apk"],nativeLibraryDirectories=[/data/aoo-lib/com.mobile-1, /system/lib]]]: findLibrary returned null

我做了什么:

  1. 我下载了 SDK 的 .jar 文件并放入了 app/libs

我在build.gradle中添加了这一行来获取SDK的路径

I added this line in the build.gradle to get the path of the SDK

dependencies {
  ...
  implementation fileTree(include: ['*.jar'], dir: 'libs')
}

  1. 我创建了 native 模块 以便能够加载 SDK
  1. I created the native module to be able to load the SDK

这是我在 CodeBarre.java 中的原生模块代码:

Here is my native module code in CodeBarre.java:

package com.myApp;


import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;


import java.util.Map;
import java.util.HashMap;
import android.util.Log;

import com.zebra.adc.decoder.BarCodeReader; // that's the scanner SDK

public class CodeBarre extends ReactContextBaseJavaModule {

public CodeBarre(ReactApplicationContext reactContext) {
  super(reactContext);

}

private static final String TAG = "BarcodeSdkDemo";


@Override
public String getName() {
  return "CodeBarre";
}

// here's how i'm trying to load the SDK
@ReactMethod
public void initScanner(Callback cb) {
  try {
      System.loadLibrary("IAL");
      System.loadLibrary("SDL");
      System.loadLibrary("barcodereader44"); // Android 4.4
      Log.i(TAG, "Barcode scanner drivers loaded");
      cb.invoke("Barcode scanner drivers loaded");
  } catch (Exception e) {
      Log.e(TAG, "error static initialization  block", e);
      cb.invoke(e.toString(), null);
  }
 }
}

  1. 这是 react-native 方面:

  ...
  componentDidMount() {
    // Access the function created in the java module
    NativeModules.CodeBarre.initScanner((err ,name) => {
      console.log(err, name);
    });
  }

  1. 这是我得到的错误:

  1. Here is the error that I'm getting:

这是我放在/app/libs 中的 .jar 文件:

Here's the .jar file that I put in /app/libs:

应用文件夹中的build.gradle:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
  entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

android {
  compileSdkVersion rootProject.ext.compileSdkVersion
  buildToolsVersion rootProject.ext.buildToolsVersion

  defaultConfig {
     applicationId "com.mobile"
     minSdkVersion rootProject.ext.minSdkVersion
     targetSdkVersion rootProject.ext.targetSdkVersion
     versionCode 4
     versionName "0.1"
  }

  signingConfigs {
    release {
      if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
          storeFile file(MYAPP_RELEASE_STORE_FILE)
          storePassword MYAPP_RELEASE_STORE_PASSWORD
          keyAlias MYAPP_RELEASE_KEY_ALIAS
          keyPassword MYAPP_RELEASE_KEY_PASSWORD
         }
      }
     }
     splits {
      abi {
       reset()
       enable enableSeparateBuildPerCPUArchitecture
       universalApk false  // If true, also generate a universal APK
       include "armeabi-v7a", "x86", "arm64-v8a"
     }
    }

    buildTypes {
      release {
         minifyEnabled enableProguardInReleaseBuilds
         proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
         signingConfig signingConfigs.release
       }
      }
      // applicationVariants are e.g. debug, release
         applicationVariants.all { variant ->
         variant.outputs.each { output ->
      // For each separate APK per architecture, set a unique version code as described here:
      // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
      def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3]
      def abi = output.getFilter(OutputFile.ABI)
      if (abi != null) {  // null for the universal-debug, universal-release variants
          output.versionCodeOverride =
                versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
     }
    }
  }
 }

    dependencies {
     implementation project(':react-native-device-info')
     implementation project(':react-native-vector-icons')
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
     implementation "com.facebook.react:react-native:+"  // From node_modules
    }

    // Run this once to be able to run the application with BUCK
    // puts all compile dependencies into folder libs for BUCK to use
     task copyDownloadableDepsToLibs(type: Copy) {
       from configurations.compile
       into 'libs'
     }

  • 这里是如何加载SDK的说明:

  • And here are the instruction of how to load the SDK:

    推荐答案

    专业提示:在就依赖相关问题寻求帮助时,始终包括您的成绩文件.

    Pro tip: ALWAYS include your grade files when asking help for dependency-related issues.

    该消息意味着您的应用无法找到本机库.在 android 世界中,这意味着 C 库,而不是 java 库.在安卓世界,你有:

    That message means your app can't locate native libraries. In the android world, that means C libraries, not java libraries. In the android world, you have:

    -Java 库:JAR 文件.与 Java 世界中的其他任何地方几乎相同.

    -Java libraries : JAR files. Pretty much the same as anywhere else in the java world.

    -Android 库:AAR 文件.Zip 文件的结构不仅会暴露 JVM 字节码,还会暴露相关的 XML 文件,例如清单文件,以及 .so 文件(取决于 gradle 插件版本).

    -Android libraries: AAR files. Zip files with a structure exposing not only JVM bytecode, but also relevant XML files, like the manifest file, and, depending on the gradle plugin version, .so files.

    -本地库:SO 文件.由您的代码调用的 C 程序.

    -Native libraries : SO files. C programs to be summoned by your code.

    你得到的文件是一个普通的 jar.如您所见,它不包含您需要的 .so 文件(IAL"、SDL"、barcodereader44").如果 SDK 提供者给了你一个 jar 文件,他们也必须给你一组上述的 .so 文件.您需要在构建中包含这些.以下答案显示了如何手动执行此操作:如何在 Android Studio 中包含 *.so 库?

    The file you got is a regular jar. As you can see, it does not contain the .so files you need ( "IAL", "SDL", "barcodereader44"). If the SDK provider gave you a jar file, they also had to give you a set of said .so files. You'll need to include those in the build. The following answer shows how to do it manually: How to include *.so library in Android Studio?

    如果您缺少 .so 文件,请向 SDK 提供商询问.它们可能看起来像这些:

    If you are lacking the .so files, ask them to the SDK provider. They may look like these ones:

    https://github.com/LeiHuangZ/ScanServiceNew/tree/master/se4710/src/main/jniLibs/arm64-v8a

    请记住,每个处理器架构都需要不同的 .so 文件集.

    Keep in mind you'll need different .so file sets for each processor architecture.

    根据SDK的包名,我猜他们没有发给你的文件是这个:https://github.com/LeiHuangZ/ScanServiceNew/blob/master/se4710/src/main/jniLibs/jniLibs.rar

    Based on the package name of the SDK, I'm guessing the file they haven't sent you is this one: https://github.com/LeiHuangZ/ScanServiceNew/blob/master/se4710/src/main/jniLibs/jniLibs.rar

    在您等待他们的答复时,请尝试使用这些答复.请记住,他们没有提供适用于 x86 的版本,因此请仅针对 arm 和 armv7 调整您的 apk 拆分.

    While you wait for an answer from them, try with this ones. Keep in mind they aren't providing a version for x86, so adjust your apk split only for arm and armv7.

    Google 缓存是您的朋友.您正在使用 Famoco 的 SDK,对吗??

    Google cache is your friend. You are working with Famoco's SDK, right??

    https://webcache.googleusercontent.com/search?q=cache:iJQugfLm27wJ:https://help.famoco.com/开发人员/示例代码/fx300-imager/+&cd=2&hl=en&ct=clnk&gl=us

    问题是,他们的 SDK 是为他们的设备设计的.C 库是其中的一部分.我猜您要么是在使用非 famoco 设备进行测试,要么有人只是向您发送了 SDK,假设它可以工作,但它不会,除非他们向您发送 C 文件或 famoco 设备.事实上,Famoco 的测试项目声明:

    The thing is, their SDK is meant for THEIR devices. The C libraries are part of them. I guess you are either testing with a non-famoco device, or somebody just sent you the SDK assuming it would work, and it will not, unless they send you the C files, or a famoco device. In fact, Famoco's test project states:

    /*** 此应用程序测试 FX300 上的条码扫描器.* 它依赖于包含共享库的图像:* 系统/库/*/

    /** * This app tests the barcode scanner on FX300. * It relies on the image containing the shared libraries in: * system/lib/ */

    伙计,你得到了答案.要么购买 Famoco FX300,要么放弃 sdk.

    So mate, you got your answer. Either get a Famoco FX300, or ditch the sdk.

    这篇关于无法将 android 第三方扫描仪库加载到我的本机应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆