如何在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 alibs
folder into theandroid/app
directory of the project with yourjar
file and enjoy!
- 如果要将
jar
文件添加到native-module
,则将compile fileTree(dir: "libs", include: ["*.jar"])
行添加到本机模块的build.gradle
文件的dependencies
部分中.
- If you want to add a
jar
file to anative-module
then add the line ofcompile fileTree(dir: "libs", include: ["*.jar"])
into thedependencies
part ofbuild.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.