A method and device for connecting an Android project to a target development environment
By packaging the react-native Android source code into an Android library, we can quickly integrate Android projects and abandon the react-native environment, solving the high cost problem of existing technologies and improving development efficiency and flexibility.
Patent Information
- Application Number
- CN202111304138.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-05
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2041-11-05
AI Technical Summary
In the existing technology, integrating Android projects into the React-Native environment requires manual configuration and familiarity with the React-Native environment, resulting in high manpower and time costs. The costs are especially high in multi-person or multi-project development scenarios, and the integration and abandonment costs are high.
Extract the react-native Android source code, package it into an Android library, and provide the target development environment to the Android project through the Android library, isolating the native development environment. The Android project can quickly access or abandon the react-native environment by relying on the Android library.
It reduces the time and labor costs of integrating Android projects and abandoning react-native, avoids complex environment configuration and code migration issues, and improves development efficiency.
Smart Images

Figure CN114020325B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method and apparatus for connecting an Android project to a target development environment. Background Art
[0002] Hybrid development refers to an APP development method that includes two or more APP forms, such as an APP development method that includes native APP and web APP. Among them, according to different operating systems, native APP development can be divided into Android APP development and iOS APP development. React-native (RN for short) is a currently popular hybrid development framework. At present, the way to connect Android to react-native is to first create a react-native project, which includes the front-end (web side), Android and iOS project code. If it is a new project, the three sides only need to implement the corresponding business logic in the corresponding project directory; if it is an existing project connection, the Android project code needs to be copied to the Android directory under the react-native project and configured accordingly.
[0003] In either of the above situations, Android developers are required to manually configure the React-Native environment, and becoming familiar with and using the React-Native environment requires a certain amount of manpower and time. When it comes to scenarios where multiple people are developing the same project or multiple projects need to integrate with React-Native, the manpower and time costs will be even higher. For example, if multiple people are developing the same project, all the developers need to configure the React-Native environment. When multiple projects need to integrate with React-Native, there will be considerable costs whether the existing Android project is integrated or abandoned for some reason. This is especially true when only some of the projects need to integrate with React-Native, in which case the cost will be even higher.
[0004] Therefore, it is urgent to propose a more efficient solution for Android to access react-native to reduce the cost of using react-native. Summary of the Invention
[0005] The embodiments of the present application provide a method and apparatus for connecting an Android project to a target development environment, thereby reducing the cost of using React Native.
[0006] In a first aspect, an embodiment of the present application provides a method for connecting an Android project to a target development environment, obtaining Android source code of the target development environment, wherein the target development environment includes react-native;
[0007] Create an Android library;
[0008] Integrating the Android source code of the target development environment into the Android library to provide the target development environment to the Android project through the Android library, thereby isolating the target development environment from the Android native development environment;
[0009] Add a dependency on the Android library to the Android project to quickly connect the Android project to the target development environment.
[0010] In a second aspect, the present application also provides a device for connecting an Android project to a target development environment.
[0011] A source code acquisition module is used to obtain the Android source code of the target development environment, wherein the target development environment includes react-native;
[0012] Android library creation module, used to create Android libraries;
[0013] A source code integration module, configured to integrate the Android source code of the target development environment into the Android library, so as to provide the target development environment to the Android project through the Android library, thereby isolating the target development environment from the Android native development environment;
[0014] The dependency adding module is used to add the dependency on the Android library to the Android project so as to quickly connect the Android project to the target development environment.
[0015] In a third aspect, an embodiment of the present application further provides an electronic device comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the method described in the first aspect or the second aspect.
[0016] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in the first aspect or the second aspect are implemented.
[0017] At least one of the above-mentioned technical solutions adopted in the embodiments of the present application extracts the Android source code of the target development environment including react-native, packages it into the Android library, and provides the target development environment including react-native to the Android project, thereby isolating the target development environment from the Android native development environment. The Android project can easily and quickly access the target development environment by relying on the Android library, and the access to the target development environment can be abandoned by removing the Android project's dependence on the Android library. Therefore, the manpower and time costs of the Android project accessing and abandoning the target development environment including react-native can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1 This is a schematic diagram of the principle of a method for connecting an Android project to a target development environment in the prior art.
[0020] Figure 2 This is a schematic diagram of another method in the prior art for connecting an Android project to a target development environment.
[0021] Figure 3 This is a flowchart of a method for connecting an Android project to a target development environment provided in one embodiment of the present application.
[0022] Figure 4 This is a schematic diagram of obtaining the Android Module of react-native-code-push provided in an embodiment of the present application.
[0023] Figure 5 This is a schematic diagram of the principle of a method for connecting an Android project to a target development environment provided in one embodiment of the present application.
[0024] Figure 6 This is a flowchart of a method for connecting an Android project to a target development environment provided by another embodiment of the present application.
[0025] Figure 7 This is a flowchart of a method for connecting an Android project to a target development environment provided by another embodiment of the present application.
[0026] Figure 8 This is a structural diagram of a device for connecting an Android project to a target development environment, provided in one embodiment of the present application.
[0027] Figure 9This is a structural diagram of a device for connecting an Android project to a target development environment, provided in another embodiment of the present application.
[0028] Figure 10 This is a structural diagram of a device for connecting an Android project to a target development environment, provided in another embodiment of the present application.
[0029] Figure 11 This is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0031] Currently, there are two ways to connect Android projects to react-native: Figure 1 and Figure 2 shown.
[0032] refer to Figure 1 It can be seen that the first way to integrate an Android project into react-native includes the following process: for the development of a product (such as an APP) that requires an Android version, after installing node, create a new react-native project 12 in node, and the same is true for other products 11; then use the npm install command to download the react-native aar 13 and the third-party plug-ins used by react-native (also called react-native plug-ins) 14 from the remote npm repository, and put them into the Android container 15, and then write the Android code 16 in the Android directory under the react-native project 12 or copy the existing Android project code 16 to the corresponding Android directory under the react-native project, and finally achieve the purpose of integrating the Android project into react-native.
[0033] refer to Figure 2It can be seen that the second way to connect an Android project to react-native includes the following process: for other products 21 that want to connect to an existing Android project 22, after installing node, create a new react-native project 23 in the root directory of the existing Android project 22; then use the npm install command to download react-native's aar 24 and third-party plug-ins used by react-native (also called react-native plug-ins) 25 from the remote npm warehouse, and use Android gradle to configure the local warehouse path and automatic link (link), and then put them together with react-native's aar 24 and third-party plug-ins used by react-native (also called react-native plug-ins) 25 into the Android container 27, and then write Android code 28 in the Android directory under the react-native project 12, and finally achieve the purpose of connecting the Android project to react-native.
[0034] It is not difficult to see that in the existing technology, no matter which access method is used, it is necessary to first create a react-native project and manually configure the react-native environment. In addition, familiarity with and use of the react-native environment requires a certain amount of manpower and time costs. When it involves multiple people developing the same project or multiple projects need to access react-native, these scenarios will be even more expensive. For example, if multiple people develop the same project, all the people involved in the development need to configure the react-native environment. When multiple projects need to access react-native, there will be considerable costs whether the existing Android project is accessed or abandoned for some reason after access. In particular, the cost will be even higher when only some of the projects need to access react-native.
[0035] In order to reduce the manpower and time costs of integrating an Android project into a target development environment including React-Native, an embodiment of the present application provides a method and apparatus for integrating an Android project into a target development environment. The execution subject of the method and apparatus can be an electronic device, such as a personal computer.
[0036] It should be noted that node is an open source and cross-platform JavaScript runtime environment; npm (full name node package manager) is the package manager of node.js, which is used for node plug-in management, including installation, uninstallation, and dependency management.
[0037] The following describes a method for connecting an Android project to a target development environment provided in an embodiment of the present application.
[0038] like Figure 3 As shown, an embodiment of the present application provides a method for connecting an Android project to a target development environment, which may include the following steps:
[0039] Step 301: Obtain Android source code of a target development environment, where the target development environment includes react-native.
[0040] Optionally, the target development environment may also include third-party plug-ins used by react-native (referred to as react-native plug-ins), which are generally basic plug-ins commonly used by react-native, such as code-push hot update, camera, image compression, local storage, device information, common view plug-ins, etc. It is understandable that after the react-native plug-in is integrated into the Android library together with react-native through subsequent steps, a more complete react-native development environment can be provided to the Android project. Of course, if react-native itself alone meets the Android development requirements, the target development environment may not include the above-mentioned third-party plug-ins.
[0041] Since react-native and react-native plugins are usually managed on npm, you can first install node, then create a react-native demo project in node, and then install react-native and react-native plugins in the react-native demo project to obtain the react-native aar file and the react-native plugin's Android Module source code.
[0042] In the react-native demo project, run the npm install command to install react-native, then read the react-native framework's AAR file from the node_modules\react-native\android\com\facebook\react\react-native\0.64.x directory. The react-native framework's AAR file provides the react-native API in Android projects. After importing react-native, components in the front-end code can be identified and converted into Android-specific controls, allowing them to render properly on the Android platform. For example, the JSC and Hermes engines parse the front-end JavaScript code and map react-native components to native Android components (views). The following lists some of the mappings between react-native components and native Android components:
[0043] Text->TextView (Android text component);
[0044] Image->ImageView (Android image display component);
[0045] TextInput->EditText (Android input box);
[0046] CheckBox->AppCompatCheckBox (Android checkbox);
[0047] RefreshControl->SwipeRefreshLayout (Android refresh component);
[0048] ScrollView->ScrollView (Android scroll bar), etc.
[0049] Alternatively, in the react-native demo project environment, execute the npm install command to install the react-native plugin used by react-native, then obtain the source code of its Android module in the corresponding directory, and upload it to the Maven library to generate the aar dependency. Figure 4As shown in the example, using the react-native-code-push hot update plugin, the Android module in the node_modules\react-native-code-push\android\app directory is retrieved. Furthermore, if the front-end code executes the react-native-code-push hot update logic, it is mapped to the react-native-code-push Android implementation logic, downloading the hot update bundle (module) from AppCenter and replacing the original bundle packaged with the front-end code in the Android app.
[0050] Optionally, after obtaining the target development environment's AAR, you can also upload the target development environment's AAR to the Maven repository to facilitate access by Android developers. For example, upload the react-native AAR to the Maven repository and upload the react-native plugin source code to the Maven repository to generate the AAR dependency.
[0051] Step 302: Create an Android library.
[0052] Step 303: Integrate the Android source code of the target development environment into the Android library, so as to provide the target development environment to the Android project through the Android library, thereby isolating the target development environment from the Android native development environment.
[0053] When the target development environment includes react-native, the Android source code of react-native is integrated into the Android library; when the target development environment includes react-native and react-native plug-ins, the Android source code of react-native and react-native plug-ins is integrated into the Android library. It can be understood that since the source code of the target development environment is integrated into the Android library, the target development environment can be provided to the Android project in the form of the Android library. The advantage of doing so is that it not only avoids the problem of high access and abandonment costs and isolates the original target development environment from the Android native development environment, but also avoids the Android project from developing code in the same react-native project as the front-end and iOS when accessing react-native, so the development environment is more friendly.
[0054] There are at least two possible implementation methods here: one is to directly integrate the Android source code of the target development environment (such as the aar of the target development environment) into the Android library; the other is that if the aar of the target development environment is uploaded to the Maven library, the dependency of the aar of the target development environment in the Maven library can be determined first, and then the dependency of the aar of the target development environment can be integrated into the Android library to integrate the Android source code of the target development environment into the Android library.
[0055] The following is a code example for integrating the aar file of a third-party plug-in uploaded to the Maven library into the Android library:
[0056] api"com.xal.publicrepository:react-native-device-info:${DEP_VERSION_NAME}"
[0057] api"com.xal.publicrepository:react-native-code-push:${DEP_VERSION_NAME}"
[0058] api"com.xal.publicrepository:lottie-react-native:${DEP_VERSION_NAME}"
[0059] api"com.xal.publicrepository:react-native-linear-gradient:${DEP_VERSION_NAME}"
[0060] api"com.xal.publicrepository:react-native-safe-area-context:${DEP_VERSION_NAME}"
[0061] api"com.xal.publicrepository:react-native-gesture-handler:${DEP_VERSION_NAME}"
[0062] api"com.xal.publicrepository:react-native-compressor:${DEP_VERSION_NAME}"
[0063] Step 304: Add a dependency on the Android library to the Android project to quickly connect the Android project to the target development environment.
[0064] It can be understood that after the Android project relies on the Android library, it can quickly access the target development environment by calling the code of the target development environment integrated in the Android library.
[0065] Figure 5 The schematic diagram shows a principle of a method for connecting an Android project to a target development environment provided by an embodiment of the present application. Figure 5 It can be seen that the embodiment of the present application provides a method for connecting an Android project to a target development environment. First, a new react-native project 51 is created in node; then, in the react-native project 51 environment, react-native and react-native plug-in 53 are downloaded and installed from npm through the npminstall command; after installing react-native, react-native aar 52 can be obtained in the corresponding installation directory; after installing the react-native plug-in 53, the Android module 54 of the react-native plug-in 53 can also be obtained in the corresponding installation directory; then, the react-nativeaar 52 is uploaded to the maven library 55 in the form of aar, and the Android module 54 is uploaded to the maven library and aar dependencies are generated; thereafter, an Android library 56 is created, and the dependencies of the react-native aar 52 and the Androidmodule 54's aar in the maven library 55 are integrated into the Android library 56; thereafter, the Android project 57 or other products can be quickly connected to react-native by relying on the Android library.
[0066] Alternatively, as Figure 5 As shown, after obtaining react-native aar 52 and Android module 54, you can also directly integrate them into Android library 56 instead of uploading Maven library 55. At this time, Android library 56 can also provide react-native development environment. Android project 57 or other products can also quickly access react-native by relying on Android library.
[0067] By Figure 5 Respectively Figure 1 and Figure 2By comparison, it can be seen that the embodiment of the present application provides a method for connecting an Android project to a target development environment. The method extracts the Android source code of the target development environment including react-native, packages it into an Android library, and provides the Android project with a target development environment including react-native, thereby isolating the target development environment from the Android native development environment. The Android project can easily and quickly connect to the target development environment by relying on the Android library. If, after connection, you want to abandon react-native for some reason, you can delete the Android project's dependence on the Android library without worrying about the migration of the Android native code. Therefore, the manpower and time costs of connecting and abandoning react-native for the Android project can be reduced.
[0068] In summary, the embodiment of the present application provides a method for connecting an Android project to a target development environment. Android native development does not require knowledge of how to configure a react-native environment and use front-end tools such as node; connection and abandonment are convenient and the cost is relatively low.
[0069] Alternatively, as Figure 6 As shown, when the target development environment also includes a third-party plug-in (react-native plug-in) used by react-native, the method of connecting an Android project to the target development environment provided by the embodiment of the present application may further include:
[0070] Step 305: Add the third-party plug-in's Package file to the ReactNativeHost List <reactpackage>In order to facilitate the front-end to reference the third-party plug-in through the List <reactpackage>Find the Package source code corresponding to the third-party plug-in to implement the corresponding function, wherein the ReactNativeHost is a packaging class for creating a react-native manager in the Android library.
[0071] It's important to note that ReactNativeHost is a wrapper class for the React-Native configuration. The module name and file entry name corresponding to the bundle resource file provided by the frontend are ultimately configured in this class. This class also builds the basic ReactInstanceManage as a React-Native manager to manage ReactPackage, which in turn manages ReactRootView and controls its lifecycle.
[0072] It should also be noted that List <reactpackage>It will eventually be mapped into a method table, so that when the front-end references a third-party plug-in, it can find the corresponding Package source code through this method table to implement the corresponding function.
[0073] Add the third-party plug-in package file to the list <reactpackage>A code example is as follows:
[0074]
[0075] Alternatively, as Figure 7 As shown, the method for connecting an Android project to a target development environment provided by an embodiment of the present application may further include:
[0076] Step 306: Add a react-native container exposed to the Android project in the Android library, so that the Android project loads and displays the module from the front end through the react-native container, wherein the react-native container includes at least one of an Activity and a Fragment, and the react-native container includes a ReactRootView in the react-native, and the ReactRootView is used to load and display the module from the front end, and the module is packaged by the front-end code.
[0077] The reason why the react-native container (at least one of Activity and Fragment) is exposed in the Android library is that the bundle (module) packaged into the front-end code must be loaded and displayed by React-native's ReactRootView. The encapsulated Activity and Fragment can be easily inherited and extended by Android projects connected to the Android library.
[0078] It is understandable that if you want to upload the AAR file of the Android library to the Maven library, you can upload it after executing the above step 306.
[0079] On this basis, a method for connecting an Android project to a target development environment provided by an embodiment of the present application may also include: receiving a module resource file provided by the front end, a module name corresponding to the module resource file, and a file entry name corresponding to the module resource file, so that the Android project loads the module resource file through the react-native container with the module name corresponding to the module resource file and the file entry name corresponding to the module resource file to display the corresponding page.
[0080] It's understandable that front-end developers package the front-end code into a bundle resource file and also provide the Android developer with the module name and file entry name corresponding to the bundle resource file. Because the aforementioned Android library already includes the react-native framework, which includes a component called ReactRootView that can load and parse react-native front-end code resource files; and the react-native container exposed by the aforementioned Android library includes this ReactRootView, Android developers can use the react-native container (Activity or fragment) exposed by the aforementioned Android library to load the bundle resource file normally using the module name and file entry name corresponding to the bundle resource file, thereby displaying a normal page.
[0081] For example, getBundleAssetName is the bundle file name packaged with the front-end code, getJsMainModulePath is the entry point for the front-end code, and getRNModuleName is the module name exported by the front-end code. The front-end needs to provide these three elements to properly parse the bundle file packaged with the front-end code. Among them, the encapsulated getRNModuleName corresponds to the getMainComponentName of ReactActivity in the react-native framework, and corresponds to the value passed with arg_component_name as the key when opening ReactFragment or its subclasses in the react-native framework. The code example is as follows:
[0082]
[0083]
[0084] Optionally, in addition to exposing the above-mentioned react-native container in the Android library, a method for connecting an Android project to a target development environment provided by an embodiment of the present application may also include but is not limited to at least one of the following steps: adding code for a Package management entry of a new react-native plug-in to the Android library, so that the Android project can add a new react-native plug-in to the Android library; adding communication code between the Android native development environment and the react-native to the Android library, so that the Android native development environment and the react-native can communicate with each other; and, adding a preset public library function to the Android library, so that the Android project can quickly use the preset public library function, etc.
[0085] It is understandable that if the aar of the Android library is to be uploaded to the Maven library, it can be uploaded after executing the above step 306 and other steps of adding content to the Android library.
[0086] Optionally, if the code for the Package management entry of the newly added react-native plug-in is added to the Android library, the method for connecting an Android project to the target development environment provided by the embodiment of the present application may further include: adding the Package file of the newly added react-native plug-in of the Android project to the List of ReactNativeHost <reactpackage>In order to facilitate the front-end to reference the specified react-native plug-in through the List <reactpackage>Find the Package source code corresponding to the newly added react-native plug-in to implement the corresponding function, wherein the ReactNativeHost is a packaging class for creating a react-native manager in the Android library.
[0087] New react-native plugins are usually added to meet specific business needs in the product, such as the front-end needs to obtain some information in the product. The front-end only needs to agree on the plugin name and execution method with the Android developer, and the Android developer implements the corresponding logic in the agreed method. Because only the List added to ReactNativeHost (the wrapper class that creates the react-native manager in the Android library) <reactpackage>The newly added react-native plug-in can be recognized by the front-end code and execute normal logic when called, so the newly added react-native plug-in needs to be added to the List <reactpackage>The following is an example of how Android developers provide plugins to the front-end and how the front-end references the plugins.
[0088] For example, the code example of the Android plugin for exposing information to the front end can be:
[0089] 1. Create an Android module code implementation for obtaining information plug-in:
[0090]
[0091] 2. Create a package for the information acquisition plug-in. The package manages the Android module for the information acquisition plug-in:
[0092]
[0093]
[0094] 3. Add the Package of the information acquisition plug-in to the List <reactpackage>middle:
[0095]
[0096] A code example of a front-end reference to the react-native plugin:
[0097]
[0098] Furthermore, the method of connecting an Android project to a target development environment provided in an embodiment of the present application may also include, before executing the above step 304: uploading the aar of the Android library to the Maven library, so that more Android projects can quickly connect to the target development environment by adding dependencies on the Android library from the Maven library.
[0099] Correspondingly, the above step 304 may also include: adding a dependency on the aar of the Android library in the Maven library to the Android project, so that the Android project can quickly access the target development environment.
[0100] An embodiment of the present application provides a method for connecting an Android project to a target development environment. Android native development does not require knowledge of how to configure a react-native environment or use front-end tools such as node. An Android project can connect to react-native by relying on an Android library. The Android project can abandon react-native by deleting its dependency on the Android library. Both connection and abandonment are very convenient and the cost is relatively low.
[0101] Corresponding to the above method embodiment, the embodiment of the present application also provides a device for connecting an Android project to a target development environment, which is introduced below.
[0102] like Figure 8 As shown, an embodiment of the present application provides a device for connecting an Android project to a target development environment. The device may include: a source code acquisition module 801, an Android library creation module 802, a source code integration module 803 and a dependency addition module 804.
[0103] The source code acquisition module 801 is used to obtain the Android source code of the target development environment, and the target development environment includes react-native.
[0104] Optionally, the target development environment may also include third-party plug-ins used by react-native (referred to as react-native plug-ins), which are generally basic plug-ins commonly used by react-native, such as code-push hot update, camera, image compression, local storage, device information, common views, etc.
[0105] Optionally, after obtaining the target development environment's AAR, the target development environment's AAR can be uploaded to the Maven repository through the first upload module to facilitate Android developers' access. For example, the react-native AAR can be uploaded to the Maven repository, and the source code of the react-native plugin's Android module can be uploaded to the Maven repository to generate the AAR dependency.
[0106] The Android library creation module 802 is used to create an Android library.
[0107] The source code integration module 803 is used to integrate the Android source code of the target development environment into the Android library, so as to provide the target development environment to the Android project through the Android library, thereby isolating the target development environment from the Android native development environment.
[0108] When the target development environment includes react-native, the react-native Android source code is integrated into the Android library; when the target development environment includes react-native and react-native plug-ins, the react-native Android source code is integrated into the Android library. It can be understood that since the source code of the target development environment is integrated into the Android library, the target development environment can be provided to the Android project in the form of the Android library. The advantage of doing so is that it not only avoids the problem of high access and abandonment costs and isolates the original target development environment from the Android native development environment, but also avoids the Android project from developing code in the same react-native project as the front-end and iOS when accessing react-native, so the development environment is more friendly.
[0109] There are at least two possible implementation methods here: one is to directly integrate the Android source code of the target development environment (such as the aar of the target development environment) into the Android library; the other is that if the aar of the target development environment is uploaded to the Maven library, the dependency of the aar of the target development environment in the Maven library can be determined first, and then the dependency of the aar of the target development environment can be integrated into the Android library to integrate the Android source code of the target development environment into the Android library.
[0110] The dependency adding module 804 is used to add a dependency on the Android library to the Android project, so as to quickly connect the Android project to the target development environment.
[0111] An embodiment of the present application provides a device for connecting an Android project to a target development environment. The device extracts the Android source code of the target development environment including React-Native, packages it into an Android library, and provides the Android project with the target development environment including React-Native, thereby isolating the target development environment from the Android native development environment. The Android project can easily and quickly connect to the target development environment by relying on the Android library. If, after the connection, you want to abandon React-Native for some reason, you only need to delete the Android project's dependence on the Android library without worrying about the migration of the Android native code. Therefore, the manpower and time costs of connecting and abandoning React-Native to the Android project can be reduced.
[0112] Alternatively, as Figure 9 As shown, an apparatus for connecting an Android project to a target development environment provided by an embodiment of the present application may further include: a Package file management module 805 .
[0113] The package file management module is used to add the package file of the third-party plug-in (react-native plug-in) used by react-native to the list of ReactNativeHost when the target development environment also includes the third-party plug-in used by react-native <reactpackage>In order to facilitate the front-end to reference the third-party plug-in through the List <reactpackage>Find the Package source code corresponding to the third-party plug-in to implement the corresponding function, wherein the ReactNativeHost is a packaging class for creating a react-native manager in the Android library.
[0114] List <reactpackage>It will eventually be mapped into a method table, so that when the front-end references a third-party plug-in, it can find the corresponding Package source code through this method table to implement the corresponding function.
[0115] Alternatively, as Figure 10 As shown, an apparatus for connecting an Android project to a target development environment provided by an embodiment of the present application may further include: an exposure increasing module 806 .
[0116] An exposure adding module 806 is used to add a react-native container exposed to the Android project within the Android library, so that the Android project loads and displays the module from the front end through the react-native container, wherein the react-native container includes at least one of an Activity and a Fragment, and the react-native container includes the ReactRootView in the react-native, and the ReactRootView is used to load and display the module from the front end, and the module is packaged by the front-end code.
[0117] The reason why the react-native container (at least one of Activity and Fragment) is exposed in the Android library is that the bundle (module) packaged into the front-end code must be loaded and displayed by React-native's ReactRootView. The encapsulated Activity and Fragment can be easily inherited and extended by Android projects connected to the Android library.
[0118] It is understandable that if you want to upload the aar of the Android library to the Maven library, you can upload it after adding the react-native container.
[0119] On this basis, an embodiment of the present application provides a device for connecting an Android project to a target development environment, which may also include: a receiving module for receiving the module resource file provided by the front end, the module name corresponding to the module resource file, and the file entry name corresponding to the module resource file, so that the Android project loads the module resource file through the react-native container with the module name corresponding to the module resource file and the file entry name corresponding to the module resource file to display the corresponding page.
[0120] It's understandable that front-end developers package the front-end code into a bundle resource file and also provide the Android developer with the module name and file entry name corresponding to the bundle resource file. Because the aforementioned Android library already includes the react-native framework, which includes a component called ReactRootView that can load and parse react-native front-end code resource files; and the react-native container exposed by the aforementioned Android library includes this ReactRootView, Android developers can use the react-native container (Activity or fragment) exposed by the aforementioned Android library to load the bundle resource file normally using the module name and file entry name corresponding to the bundle resource file, thereby displaying a normal page.
[0121] Optionally, in addition to exposing the above-mentioned react-native container in the Android library, the device for connecting an Android project to a target development environment provided by an embodiment of the present application may also include but is not limited to one or more of a first content addition module, a second content addition module, and a third content addition module.
[0122] The first content adding module is used to add the code of the Package management entry of the newly added react-native plug-in in the Android library, so that the Android project can add the react-native plug-in in the Android library.
[0123] The second content adding module is used to add the communication code between the Android native development environment and the react-native in the Android library, so as to facilitate the communication between the Android native development environment and the react-native.
[0124] The third content adding module is used to add a preset public library function in the Android library so that the Android project can quickly use the preset public library function.
[0125] It is understandable that if you want to upload the aar of the Android library to the Maven library, you can upload it after adding the above.
[0126] Optionally, if the code for the Package management entry of a new react-native plug-in is added to the Android library, the above-mentioned Package file management module can also be used to add the Package file of the new react-native plug-in added to the Android project to the List of ReactNativeHost <reactpackage>In order to facilitate the front-end to reference the specified react-native plug-in through the List <reactpackage>Find the Package source code corresponding to the newly added react-native plug-in to implement the corresponding function, wherein the ReactNativeHost is a packaging class for creating a react-native manager in the Android library.
[0127] New react-native plugins are usually added to meet specific business needs in the product, such as the front-end needs to obtain some information in the product. The front-end only needs to agree on the plugin name and execution method with the Android developer, and the Android developer implements the corresponding logic in the agreed method. <reactpackage>The newly added react-native plug-in can be recognized by the front-end code and execute normal logic when called, so the newly added react-native plug-in needs to be added to the List <reactpackage>middle.
[0128] Furthermore, the device for connecting an Android project to a target development environment provided by an embodiment of the present application may also include: a second uploading module for uploading the aar of the Android library to the Maven library, so that more Android projects can quickly connect to the target development environment by adding dependencies on the Android library from the Maven library.
[0129] Accordingly, the dependency adding module 904 may be used to add a dependency on the aar of the Android library in the Maven library to the Android project, so that the Android project can quickly access the target development environment.
[0130] An embodiment of the present application provides a device for connecting an Android project to a target development environment. Android native development does not require knowledge of how to configure a react-native environment or use front-end tools such as node. An Android project can connect to react-native by relying on an Android library. The Android project can abandon react-native by deleting its dependency on the Android library. Both connection and abandonment are very convenient and the cost is relatively low.
[0131] It should be noted that since the content executed by the device embodiment is similar to that of the method embodiment, the description of the device embodiment part in this article is relatively brief. Please refer to the method embodiment part for relevant details.
[0132] Figure 11 FIG2 is a schematic diagram showing the structure of an electronic device provided by an embodiment of the present application. Figure 11 At the hardware level, the electronic device includes a processor and, optionally, an internal bus, a network interface, and memory. The memory may include internal memory, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk drive. Of course, the electronic device may also include other hardware required for its services.
[0133] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 11 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0134] The memory is used to store programs. Specifically, the program may include program code, which includes computer operating instructions. The memory may include internal memory and non-volatile memory, and provides instructions and data to the processor.
[0135] The processor reads the corresponding computer program from the non-volatile memory into the internal memory and then runs it, forming a device that logically connects the Android project to the target development environment. The processor executes the program stored in the memory and is specifically used to perform the method for connecting the Android project to the target development environment provided in the embodiments of the present application.
[0136] The above application Figure 8 The method disclosed in the illustrated embodiment for executing an apparatus for accessing an Android project to a target development environment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor or by software instructions. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of this application can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in conjunction with the embodiments of this application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above method.
[0137] The embodiment of the present application also provides a computer-readable storage medium, which stores one or more programs, wherein the one or more programs include instructions, which, when executed by an electronic device including multiple application programs, can enable the electronic device to execute Figure 8 The method executed by the device for connecting an Android project to a target development environment in the illustrated embodiment is specifically used to execute the method for connecting an Android project to a target development environment provided in the embodiment of the present application.
[0138] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0139] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0140] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0141] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0142] It should be noted that the various embodiments in this application are described in a related manner. For similar or identical parts between the various embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the apparatus embodiments, since they are generally similar to the method embodiments, the description is relatively simple. For relevant parts, reference can be made to the partial description of the method embodiments.
[0143] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a..." does not preclude the presence of other identical elements in the process, method, commodity, or apparatus comprising the element.
[0144] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.< / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage> < / reactpackage>
Claims
1. A method for connecting an Android project to a target development environment, characterized in that: The method comprises: Obtaining Android source code for a target development environment, wherein the target development environment includes react-native; Create an Android library; Integrating the Android source code of the target development environment into the Android library to provide the target development environment to the Android project through the Android library, thereby isolating the target development environment from the Android native development environment; Add a dependency on the Android library to the Android project to quickly connect the Android project to the target development environment.
2. The method according to claim 1, characterized in that The step of obtaining the Android source code of the target development environment includes: Get the aar file of the target development environment and upload it to the Maven repository; The step of integrating the Android source code of the target development environment into the Android library includes: Determine the dependencies of the target development environment's aar in the Maven repository; Integrate the dependencies of the target development environment's aar into the Android library, so as to integrate the Android source code of the target development environment into the Android library.
3. The method according to claim 1, characterized in that The target development environment also includes a third-party plug-in used by react-native, and the method further includes: Add the package file of the third-party plug-in to the List of ReactNativeHost <reactpackage>In order to facilitate the front-end to reference the third-party plug-in through the List <reactpackage> Find the Package source code corresponding to the third-party plug-in to implement the corresponding function, wherein the ReactNativeHost is a packaging class for creating a react-native manager in the Android library.< / reactpackage> < / reactpackage> 4. The method according to claim 1, wherein The method further comprises: A react-native container is added to the Android library and exposed to the Android project, so that the Android project loads and displays the module from the front end through the react-native container, wherein the react-native container includes at least one of an Activity and a Fragment, and the react-native container includes the ReactRootView in the react-native, and the ReactRootView is used to load and display the module from the front end, and the module is packaged by the front-end code.
5. The method according to claim 4, characterized in that The method further comprises: Receive the module resource file provided by the front end, the module name corresponding to the module resource file and the file entry name corresponding to the module resource file, so that the Android project loads the module resource file through the react-native container with the module name corresponding to the module resource file and the file entry name corresponding to the module resource file to display the corresponding page.
6. The method according to claim 1, characterized in that The method further comprises at least one of the following steps: Add the code of the Package management entry of the new react-native plug-in in the Android library, so that the Android project can add the react-native plug-in in the Android library; Adding communication code between the Android native development environment and the react-native in the Android library to facilitate communication between the Android native development environment and the react-native; A preset public library function is added to the Android library so that the Android project can quickly use the preset public library function.
7. The method according to claim 6, characterized in that The method further comprises: Add the new react-native plugin package file of the Android project to the ReactNativeHost list <reactpackage>In order to facilitate the front-end reference to specify the react-native plug-in through the List <reactpackage>Find the Package source code corresponding to the newly added react-native plug-in to implement the corresponding function, wherein the ReactNativeHost is a packaging class for creating a react-native manager in the Android library.< / reactpackage> < / reactpackage> 8. The method according to any one of claims 1 to 7, characterized in that Before adding a dependency on the Android library to the Android project, the method further includes: Upload the aar of the Android library to the Maven library; The step of adding a dependency on the Android library to the Android project includes: Add a dependency on the aar of the Android library in the Maven library to the Android project so that the Android project can quickly access the target development environment.
9. A device for connecting an Android project to a target development environment, characterized in that: The device comprises: A source code acquisition module is used to obtain the Android source code of the target development environment, wherein the target development environment includes react-native; Android library creation module, used to create Android libraries; A source code integration module, configured to integrate the Android source code of the target development environment into the Android library, so as to provide the target development environment to the Android project through the Android library, thereby isolating the target development environment from the Android native development environment; The dependency adding module is used to add the dependency on the Android library to the Android project so as to quickly connect the Android project to the target development environment.
10. The device according to claim 9, characterized in that The target development environment also includes a third-party plug-in used by react-native, and the device also includes: Package file management module, used to add the third-party plug-in's Package file to the ReactNativeHost List <reactpackage>In order to facilitate the front-end to reference the third-party plug-in through the List <reactpackage> Find the Package source code corresponding to the third-party plug-in to implement the corresponding function, wherein the ReactNativeHost is a packaging class for creating a react-native manager in the Android library.< / reactpackage> < / reactpackage>
Citation Information
Patent Citations
Terminal device and method for executing an android application on a general-purpose operating system, and computer-readable recording medium for same
WO2012138046A1