简体   繁体   English

如何在React Native中导入Android Gradle依赖项

[英]How to import Android gradle dependencies in React Native

I have a React Native app that should use a Wi-Fi for connecting and getting some data. 我有一个React Native应用程序,应该使用Wi-Fi连接和获取一些数据。 I have a custom Wi-Fi library written in Java and it was used for native Android apps. 我有一个用Java编写的自定义Wi-Fi库,该库用于本机Android应用程序。 Now I want to use this library for my react-native app. 现在,我想将此库用于我的react-native应用程序。 How can I use it in my react-native app? 如何在我的本地应用程序中使用它? Any detailed information would help me. 任何详细信息都会对我有所帮助。

Thank you very much for your time and assistance in this matter. 非常感谢您的时间和协助。

If you have already written a library in java then you can use that library in android by following the steps mentioned in the link below:- 如果您已经用Java编写了一个库,则可以按照以下链接中提到的步骤在android中使用该库:-

https://facebook.github.io/react-native/docs/native-modules-android.html https://facebook.github.io/react-native/docs/native-modules-android.html

If you still have any issues then please let me know. 如果您仍有任何问题,请告诉我。

EDIT:- 编辑:-

You can use your native module after providing that in getPackages inside your react native components as below:- 您可以在React Native组件内的getPackages中提供该模块后使用本机模块,如下所示:

  1. Create a file and use your native module and export it so that you can use it inside your components:- 创建一个文件并使用您的本机模块并将其导出,以便可以在组件内部使用它:-
 import {NativeModules} from 'react-native'; module.exports = NativeModules.ToastExample; //here ToastExample is the name of your native module. 
  1. Then import your module inside your component and you can use its further functions/methods as below:- 然后将模块导入组件中,您可以使用其进一步的功能/方法,如下所示:
 import ToastExample from './ToastExample'; ToastExample.show('Awesome', ToastExample.SHORT); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM