如何在Android的React-native中包含".jar"文件? [英] How to include '.jar' files in the React-native for Android?

查看:121
本文介绍了如何在Android的React-native中包含".jar"文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的英语不好.

我是FRONT-END开发人员.

I'm a FRONT-END developer.

现在,我们需要一个可以使用蓝牙打印机的应用程序,并使用Android的React-Native进行编码.

Now we need an App can use Bluetooth Printer, coding with React-Native for Android.

打印机的制造商提供了一个SDK文件,扩展名为"jar".

The Printer's manufacturer provided a SDK file,extension is 'jar'.

请告诉我如何在React-Native中使用此SDK?那么如何导入JSX文件呢?

Please tell me how to use this SDK in the React-Native? then how to import in the JSX files?

推荐答案

使用build.gradle文件将*.jar添加到项目中:

Adding *.jar to the Project is done by using build.gradle file:

  • 如果要将jar文件添加到项目中,Facebook已经代表您完成了!
    只需将libs文件夹与您的jar文件添加到项目的android/app目录,即可享受!
  • If you want to add a jar file to the project, Facebook had already done on your behalf!
    Just add a libs folder into the android/app directory of the project with your jar file and enjoy!

  • 如果要将jar文件添加到native-module,则将compile fileTree(dir: "libs", include: ["*.jar"])行添加到本机模块的build.gradle文件的dependencies部分中.
  • If you want to add a jar file to a native-module then add the line of compile fileTree(dir: "libs", include: ["*.jar"]) into the dependencies part of build.gradle file of the native-module.

示例1:

okhttp-3.4.1.jar 文件添加到lib文件夹后,我还将该软件包名称添加到依赖项部分,如下所示:

After I added okhttp-3.4.1.jar file into the lib folder, I also add that package name to the dependencies part as the following:

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile 'com.facebook.react:react-native:0.19.+'
}

示例2:

如果我需要另一个在Maven回购中找到的软件包,我必须按如下所示将其添加到依赖项块中(例如,我想添加fresco):

If I need another package -that is found in Maven repo- I have to add into dependencies block as following (for instance I wanna add fresco):

dependencies {
    compile 'com.facebook.fresco:fresco:1.9.0'
}

然后Gradle将找到并安装依赖库壁画我.

Then Gradle will find and install dependency library Fresco for me.

通常,每个Android项目都已经有Maven存储库. build.gradle文件中的配置,该文件位于项目文件夹的顶部. 例如:

Usually, every Android project has already Maven repo. configurations in build.gradle file which is found in top of folder of the project. For example:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

示例3:

(我从未尝试过,但是应该可以使用)
如果我有一个drawee-debug.aar文件,可以按照例1的说明将其放入lib文件夹中,即可将其添加到我的项目中,然后必须按以下方式更改fileTree行:

(I have never tried this however it should be worked)
If I have an drawee-debug.aar file I can add it into my project by putting it into lib folder as directed on Example-1 then I have to change fileTree line as following:

compile fileTree(dir: "libs", include: ["*.jar", "*.aar"])  // "*.aar" is added

示例4:

(示例3的替代方法)
如果我还有一个drawee-debug.aar文件,也可以按照例1的说明将其放入lib文件夹中,即可将其添加到我的项目中,然后我必须进行更改并添加以下几行:

(alternate way of Example-3)
If I have an drawee-debug.aar file also I can add it into my project by putting it into lib folder as directed on Example-1 then I have to change and add some lines as following:

dependencies {
    compile (name:'drawee-debug', ext:'aar')
}

allprojects {
    repositories {
        ...
        flatDir {
            dirs 'libs', './libs'
        }
        ...
    }
}

这样,就可以在allprojects文件夹中定义libs目录,并在dependencies块中指定的aar文件中进行定义,就像其他示例一样.

In this way, libs directory is defined in allprojects folder and aar file specified in dependencies block, like othe examples.

请注意,在Gradle v3.0.1之后,使用implementation代替compile关键字.

Note that after Gradle v3.0.1 implementation is used instead compile key word.

荣誉: https://stackoverflow.com/a/37092426/3765109

这篇关于如何在Android的React-native中包含".jar"文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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