Movatterモバイル変換


[0]ホーム

URL:


CN108021389B - Method and device for introducing ARouter into Android - Google Patents

Method and device for introducing ARouter into Android
Download PDF

Info

Publication number
CN108021389B
CN108021389BCN201711130180.5ACN201711130180ACN108021389BCN 108021389 BCN108021389 BCN 108021389BCN 201711130180 ACN201711130180 ACN 201711130180ACN 108021389 BCN108021389 BCN 108021389B
Authority
CN
China
Prior art keywords
arouter
version number
configuration file
component
version
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201711130180.5A
Other languages
Chinese (zh)
Other versions
CN108021389A (en
Inventor
张磊
张文明
陈少杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co LtdfiledCriticalWuhan Douyu Network Technology Co Ltd
Priority to CN201711130180.5ApriorityCriticalpatent/CN108021389B/en
Publication of CN108021389ApublicationCriticalpatent/CN108021389A/en
Application grantedgrantedCritical
Publication of CN108021389BpublicationCriticalpatent/CN108021389B/en
Expired - Fee Relatedlegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Images

Classifications

Landscapes

Abstract

Translated fromChinese

本发明提供一种Android中引入ARouter的方法及装置,所述方法包括:S1,创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;S2,根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;S3,当组件被创建时,在所述组件的第二配置文件中注入所述版本信息。本发明一方面实现了对所有组件引入的Arouter的版本号进行统一升级和管理,便于维护;另一方面实现在组件创建时自动配置ARouter的版本号,提高了开发效率和配置的准确性。

Figure 201711130180

The present invention provides a method and device for introducing ARouter into Android, the method includes: S1, creating a first configuration file, defining a set variable in the first configuration file, the set variable is a global variable, and in the The first version number of the ARouter core function and the second version number of the ARouter parser are defined in the set variable; S2, according to the first version number and the second version number, generate and introduce the version information of the ARouter; S3, The version information is injected in the second configuration file of the component when the component is created. On the one hand, the present invention realizes unified upgrade and management of the version numbers of Arouter introduced by all components, which is convenient for maintenance;

Figure 201711130180

Description

Translated fromChinese
一种Android中引入ARouter的方法及装置A method and device for introducing ARouter in Android

技术领域technical field

本发明属于应用开发领域,更具体地,涉及一种Android中引入ARouter的方法及装置。The invention belongs to the field of application development, and more particularly, relates to a method and device for introducing ARouter into Android.

背景技术Background technique

在Android的组件化开发过程中,为了方便各个组件之间进行通信,通常需要引入第三方开源通信框架ARouter。In the component development process of Android, in order to facilitate communication between components, it is usually necessary to introduce a third-party open source communication framework ARouter.

在每次添加新的组件时,为了使新的组件能与其他组件进行通信,需要在新的组件中对ARouter的相关信息进行配置,从而实现对ARouter的引入。当一个组件需要引入ARouter时,需要在该组件的编译脚本build.gradle文件中对ARouter的相关信息进行配置。传统的方式直接将ARouter的相关信息进行引入,如compile"com.alibaba:arouter-api:2.2.2",compile"com.alibaba:arouter-compiler:1.2.2",其中2.2.2为ARouter核心功能的版本号,1.2.2为ARouter解析器的版本号。Every time a new component is added, in order to enable the new component to communicate with other components, it is necessary to configure the related information of ARouter in the new component, so as to realize the introduction of ARouter. When a component needs to import ARouter, you need to configure the ARouter-related information in the build.gradle file of the component's compilation script. The traditional method directly introduces the relevant information of ARouter, such as compile "com.alibaba:arouter-api:2.2.2", compile "com.alibaba:arouter-compiler:1.2.2", of which 2.2.2 is the core of ARouter The version number of the function, 1.2.2 is the version number of the ARouter parser.

由于配置ARouter的字符串比较繁琐,以手动的方式来对新组件进行配置容易出错,且费时费力。当ARouter的版本号发生变化时,需要在引入ARouter的所有组件的编译脚本中更改ARouter的版本号,消耗大量时间。Since the configuration string of ARouter is cumbersome, manually configuring new components is prone to errors and is time-consuming and labor-intensive. When the version number of ARouter changes, it is necessary to change the version number of ARouter in the compilation scripts of all components introduced into ARouter, which consumes a lot of time.

发明内容SUMMARY OF THE INVENTION

为克服上述手动在组件中引入ARouter容易出错、费时费力且不便于更改的问题或者至少部分地解决上述问题,本发明提供了一种Android中引入ARouter的方法及装置。In order to overcome the above-mentioned problems that manually introducing ARouter into a component is error-prone, time-consuming, labor-intensive, and inconvenient to change, or at least partially solve the above-mentioned problems, the present invention provides a method and device for introducing ARouter into Android.

根据本发明的第一方面,提供一种Android中引入ARouter的方法,包括:According to a first aspect of the present invention, a method for introducing ARouter into Android is provided, including:

S1,创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;S1, create a first configuration file, define a set variable in the first configuration file, the set variable is a global variable, and define the first version number of the ARouter core function and the second version number of the ARouter parser in the set variable version number;

S2,根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;S2, according to the first version number and the second version number, generate the version information introduced into the ARouter;

S3,当组件被创建时,在所述组件的第二配置文件中注入所述版本信息。S3, when the component is created, inject the version information into the second configuration file of the component.

具体地,所述步骤S2具体包括:Specifically, the step S2 specifically includes:

在所述第一版本号的变量和所述第二版本号的变量前分别添加$符号,生成引入所述ARouter的版本信息。A $ sign is respectively added before the variable of the first version number and the variable of the second version number to generate version information introduced into the ARouter.

具体地,所述步骤S3具体包括:Specifically, the step S3 specifically includes:

S31,使用register函数注册监听器;S31, use the register function to register the listener;

S32,当使用所述监听器监听到组件被创建时,回调组件创建方法;S32, when using the listener to monitor that the component is created, call back the component creation method;

S33,使用所述组件创建方法,在所述组件的第二配置文件中注入所述版本信息。S33. Using the component creation method, inject the version information into the second configuration file of the component.

具体地,所述步骤S33具体包括:Specifically, the step S33 specifically includes:

S331,获取所述组件的第二配置文件,依次读取所述第二配置文件中的各行数据,直到读取到“dependencies”字符串;S331, obtain the second configuration file of the component, and sequentially read each row of data in the second configuration file, until the "dependencies" string is read;

S332,在“dependencies”字符串所在行的下一行插入所述版本信息。S332, insert the version information in the row next to the row where the "dependencies" string is located.

具体地,所述步骤S331具体包括:Specifically, the step S331 specifically includes:

S3311,使用File类中的open方法打开所述第二配置文件,返回所述第二配置文件的文件对象;S3311, use the open method in the File class to open the second configuration file, and return the file object of the second configuration file;

S3312,调用所述文件对象的readLine方法读取所述第二配置文件中的各行数据,直到读取到“dependencies”字符串。S3312, calling the readLine method of the file object to read each line of data in the second configuration file until the "dependencies" string is read.

具体地,所述步骤S3312具体包括:Specifically, the step S3312 specifically includes:

S33121,调用所述文件对象的readLine方法读取所述第二配置文件中当前行中的数据;S33121, calling the readLine method of the file object to read the data in the current line in the second configuration file;

S33122,若所述当前行中不存在“dependencies”字符串,则将文件游标移动到下一行的开头;S33122, if the "dependencies" string does not exist in the current line, move the file cursor to the beginning of the next line;

S33123,将所述下一行作为当前行迭代执行步骤S33121至S33123,直到读取到“dependencies”字符串。S33123, iteratively execute steps S33121 to S33123 with the next line as the current line, until the "dependencies" string is read.

具体地,所述步骤S332包括:Specifically, the step S332 includes:

使用seek方法将文件游标移动到“dependencies”字符串所在行的下一行;Use the seek method to move the file cursor to the line below the line where the "dependencies" string is located;

使用write方法将所述版本信息写入到所述第二配置文件中;using the write method to write the version information into the second configuration file;

使用flush方法,对所述第二配置文件进行刷新。Using the flush method, refresh the second configuration file.

具体地,所述步骤S3之后还包括:Specifically, after the step S3, it also includes:

对所述集合变量中第一版本号的值和/或第二版本号的值进行更改。A change is made to the value of the first version number and/or the value of the second version number in the set variable.

根据本发明的第二方面,提供一种Android中引入ARouter的装置,包括:According to a second aspect of the present invention, a device for introducing ARouter in Android is provided, comprising:

创建单元,用于创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;The creation unit is used to create a first configuration file, in which a set variable is defined, the set variable is a global variable, and the first version number of the ARouter core function and the ARouter parser are defined in the set variable The second version number of ;

生成单元,用于根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;a generating unit, configured to generate version information introduced into the ARouter according to the first version number and the second version number;

注入单元,用于当组件被创建时,在所述组件的第二配置文件中注入所述版本信息。The injection unit is used for injecting the version information into the second configuration file of the component when the component is created.

根据本发明的第三方面,提供一种非暂态计算机可读存储介质,用于存储如前所述方法的计算机程序。According to a third aspect of the present invention, there is provided a non-transitory computer-readable storage medium for storing a computer program of the aforementioned method.

本发明提供一种Android中引入ARouter的方法及装置,该方法一方面通过将ARouter的核心功能的第一版本号和解析器的第二版本号放在一个全局的集合变量中,避免重名,当ARouter的版本的版本号发生变化时,只用更改所述集合变量,实现了对所有组件引入的Arouter的版本号进行统一升级和管理,便于维护,另一方面根据所述集合变量生成引入所述ARouter的版本信息,当组件被创建时自动在所述组件的第二配置文件中注入所述版本信息,实现在组件创建时自动配置ARouter的版本号,提高了开发效率和配置的准确性。The present invention provides a method and device for introducing ARouter into Android. On the one hand, in the method, the first version number of the core function of ARouter and the second version number of the parser are placed in a global set variable to avoid duplicate names, When the version number of the ARouter version changes, only the set variable is changed, which realizes the unified upgrade and management of the version number of the Arouter introduced by all components, which is convenient for maintenance. The version information of the ARouter is automatically injected into the second configuration file of the component when the component is created, so that the version number of the ARouter is automatically configured when the component is created, which improves development efficiency and configuration accuracy.

附图说明Description of drawings

图1为本发明实施例提供的Android中引入ARouter的方法整体流程示意图;1 is a schematic overall flow diagram of a method for introducing ARouter in Android provided by an embodiment of the present invention;

图2为本发明实施例提供的Android中引入ARouter的装置整体结构示意图;2 is a schematic diagram of the overall structure of an apparatus for introducing ARouter into Android provided by an embodiment of the present invention;

图3为本发明实施例提供的Android中引入ARouter的设备整体结构示意图。FIG. 3 is a schematic diagram of an overall structure of a device that introduces ARouter into Android according to an embodiment of the present invention.

具体实施方式Detailed ways

下面结合附图和实施例,对本发明的具体实施方式作进一步详细描述。以下实施例用于说明本发明,但不用来限制本发明的范围。The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and embodiments. The following examples are intended to illustrate the present invention, but not to limit the scope of the present invention.

在本发明的一个实施例中提供一种Android中引入ARouter的方法,图1为本发明实施例提供的Android中引入ARouter的方法整体流程示意图,该方法包括:S1,创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;S2,根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;S3,当组件被创建时,在所述组件的第二配置文件中注入所述版本信息。In an embodiment of the present invention, a method for introducing ARouter into Android is provided. FIG. 1 is a schematic diagram of the overall flow of the method for introducing ARouter into Android according to an embodiment of the present invention. The method includes: S1, creating a first configuration file, in A set variable is defined in the first configuration file, the set variable is a global variable, and the first version number of the ARouter core function and the second version number of the ARouter parser are defined in the set variable; S2, according to the first version number of the ARouter parser; A version number and the second version number, generate version information imported into the ARouter; S3, when the component is created, inject the version information into the second configuration file of the component.

具体地,S1中,在引入ARouter的时候需要ARouter的版本号。为了方便后期同一更新所有组件的配置文件中Arouter的版本信息,将Arouter的版本号定义在一个独立的全局变量中,从而使得所有组件所引入的Arouter的版本号相同,方便后期对所有组件引入的Arouter的版本号进行统一升级和管理。Arouter的版本号包括ARouter的核心功能的第一版本号和ARouter的解析器的第二版本号。所述第一配置文件为config.gradle配置文件。在所述第一配置文件中添加定义所述集合变量的代码,如:Specifically, in S1, the version number of ARouter is required when introducing ARouter. In order to facilitate the later update of the version information of Arouter in the configuration files of all components at the same time, the version number of Arouter is defined in an independent global variable, so that the version number of Arouter introduced by all components is the same, which is convenient for all components introduced later. The version number of Arouter is upgraded and managed uniformly. The version number of ARouter includes the first version number of the core function of ARouter and the second version number of the parser of ARouter. The first configuration file is a config.gradle configuration file. Add the code that defines the set variable in the first configuration file, such as:

Figure BDA0001469334490000051
Figure BDA0001469334490000051

其中,ext为定义的集合变量,然后在ext集合变量中定义ARouter的核心功能的第一版本号和解析器的第二版本号。ARouterAPi为所述第一版本号的变量,2.2.2为所述第一版本号的值,ArouterProcess为所述第二版本号的变量,1.2.2为所述第一版本号的值。ARouter的第一版本号由ARouter的核心功能库定义,第二版本号由解析器库定义。通过配置所述第一版本号和所述第二版本号以配置ARouter。S2中,当定义好了全局的ARouter的版本号后,根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息,所述版本信息为包含所述第一版本号和所述第二版本号的配置语句。S3中,当捕捉到有组件被创建时,在所述组件的第二配置文件中注入所述版本信息。所述第二配置文件为build.gradle脚本文件。从而实现在新建组件中自动注入ARouter的版本号。Among them, ext is a defined set variable, and then the first version number of the core function of ARouter and the second version number of the parser are defined in the ext set variable. ARouterAPi is the variable of the first version number, 2.2.2 is the value of the first version number, ArouterProcess is the variable of the second version number, and 1.2.2 is the value of the first version number. The first version number of ARouter is defined by the core function library of ARouter, and the second version number is defined by the parser library. ARouter is configured by configuring the first version number and the second version number. In S2, after the global ARouter version number is defined, according to the first version number and the second version number, the version information introduced into the ARouter is generated, where the version information includes the first version number and the configuration statement for the second version number. In S3, when it is captured that a component is created, the version information is injected into the second configuration file of the component. The second configuration file is a build.gradle script file. In this way, the version number of ARouter is automatically injected into the new component.

本实施例一方面通过将ARouter的核心功能的第一版本号和解析器的第二版本号放在一个全局的集合变量中,避免重名,当ARouter的版本的版本号发生变化时,只用更改所述集合变量,实现了对所有组件引入的Arouter的版本号进行统一升级和管理,便于维护,另一方面根据所述集合变量生成引入所述ARouter的版本信息,当组件被创建时自动在所述组件的第二配置文件中注入所述版本信息,实现在组件创建时自动配置ARouter的版本号,提高了开发效率和配置的准确性。In this embodiment, on the one hand, the first version number of the core function of ARouter and the second version number of the parser are placed in a global set variable to avoid duplication of names. When the version number of the ARouter version changes, only the Changing the set variable realizes unified upgrade and management of the version numbers of Arouter introduced by all components, which is convenient for maintenance. The version information is injected into the second configuration file of the component, so that the version number of the ARouter is automatically configured when the component is created, which improves development efficiency and configuration accuracy.

在上述实施例的基础上,本实施例中所述步骤S2具体包括:在所述第一版本号的变量和所述第二版本号的变量前分别添加$符号,生成引入所述ARouter的版本信息。On the basis of the above embodiment, the step S2 in this embodiment specifically includes: adding a $ sign before the variable of the first version number and the variable of the second version number, respectively, to generate a version imported into the ARouter information.

具体地,在定义好ARouter的第一版本号和第二版本号后,在所述第一版本号的变量和所述第二版本号的变量前分别添加$符号,生成引入所述ARouter的版本信息,如:Specifically, after defining the first version number and the second version number of the ARouter, add a $ symbol before the variable of the first version number and the variable of the second version number respectively to generate a version that introduces the ARouter information such as:

compile"com.alibaba:arouter-api:${ext.ARouterAPi}",compile "com.alibaba:arouter-api:${ext.ARouterAPi}",

compile"com.alibaba:arouter-compiler:${ext.ARouterProcess}";compile "com.alibaba:arouter-compiler:${ext.ARouterProcess}";

对比现有技术可以发现,本实施例将现有技术中ARouter的第一版本号的值和第二版本号的值替换为${ext.ARouterAPi}和${ext.ARouterProcess},使用$符合引入定义的所述第一版本号和所述第二版本号的值,从而使所有组件都引入相同的ARouter版本号,便于后期对ARouter的版本号进行统一的管理。Compared with the prior art, it can be found that, in this embodiment, the value of the first version number and the value of the second version number of ARouter in the prior art are replaced by ${ext.ARouterAPi} and ${ext.ARouterProcess}, and the introduction of $ The defined values of the first version number and the second version number enable all components to introduce the same ARouter version number, which facilitates unified management of the ARouter version numbers in the later stage.

在上述各实施例的基础上,本实施例中所述步骤S3具体包括:S31,使用register函数注册监听器;S32,当使用所述监听器监听到组件被创建时,回调组件创建方法;S33,使用所述组件创建方法,在所述组件的第二配置文件中注入所述版本信息。On the basis of the above embodiments, the step S3 in this embodiment specifically includes: S31, use the register function to register the listener; S32, when using the listener to monitor the creation of the component, call back the component creation method; S33 , using the component creation method to inject the version information into the second configuration file of the component.

具体地,为了实现自动引入Arouter的版本号,使用regiser(onModelCreated)函数注册监听器,所述监听器用于监听组件的创建,onModelCreated为组件创建方法。使用regiser函数注册后,当监听到有组件被创建时回调组件创建方法onModelCreated。在所述组件创建方法onModelCreated中自动在所述组件的第二配置文件中注入生成的版本信息,所述第二配置文件为build.gradle脚本文件。Specifically, in order to realize the automatic introduction of the version number of the Arouter, a regiser(onModelCreated) function is used to register a listener, the listener is used to monitor the creation of a component, and onModelCreated is a component creation method. After registering with the regiser function, the component creation method onModelCreated is called back when a component is created. In the component creation method onModelCreated, the generated version information is automatically injected into the second configuration file of the component, where the second configuration file is a build.gradle script file.

在上述实施例的基础上,本实施例中所述步骤S33具体包括:S331,获取所述组件的第二配置文件,依次读取所述第二配置文件中的各行数据,直到读取到“dependencies”字符串;S332,在“dependencies”字符串所在行的下一行插入所述版本信息。On the basis of the above-mentioned embodiment, the step S33 in this embodiment specifically includes: S331, obtaining the second configuration file of the component, and sequentially reading the data of each line in the second configuration file, until the "" "dependencies" string; S332, insert the version information in the next line of the line where the "dependencies" string is located.

具体地,获取新创建的组件的第二配置文件,从所述第二配置文件中的第一行数据开始按顺序一行一行地读取数据,当读取到“dependencies”字符串时,停止读取所述第二配置文件。在“dependencies”字符串所在行的下一行插入生成的所述版本信息,如在新创建的所述组件的在build.gradl脚本文件中插入compile"com.alibaba:arouter-api:${ext.ARouterAPi}"和compile"com.alibaba:arouter-compiler:${ext.ARouterProcess}",从而引入Arouter的版本信息。Specifically, the second configuration file of the newly created component is obtained, and the data is read line by line starting from the first line of data in the second configuration file, and when the "dependencies" string is read, the reading is stopped. Take the second configuration file. Insert the generated version information in the next line of the "dependencies" string, for example, insert compile"com.alibaba:arouter-api:${ext.in the build.gradl script file of the newly created component. ARouterAPi}" and compile "com.alibaba:arouter-compiler:${ext.ARouterProcess}", thereby introducing the version information of Arouter.

在上述实施例的基础上,本实施例中所述步骤S331具体包括:S3311,使用File类中的open方法打开所述第二配置文件,返回所述第二配置文件的文件对象;S3312,调用所述文件对象的readLine方法读取所述第二配置文件中的各行数据,直到读取到“dependencies”字符串。On the basis of the above embodiment, the step S331 in this embodiment specifically includes: S3311, use the open method in the File class to open the second configuration file, and return the file object of the second configuration file; S3312, call The readLine method of the file object reads each line of data in the second configuration file until the "dependencies" string is read.

具体地,使用File类中的open方法打开所述第二配置文件,返回所述第二配置文件的文件对象file,调用所述文件对象file中的readLine方法按先后顺序一行一行地读取所述第二配置文件中的各行数据,当读取到“dependencies”字符串后停止读取。Specifically, use the open method in the File class to open the second configuration file, return the file object file of the second configuration file, and call the readLine method in the file object file to read the second configuration file line by line in sequence. Each line of data in the second configuration file stops reading when the "dependencies" string is read.

在上述实施例的基础上,本实施例中所述步骤S3312具体包括:S33121,调用所述文件对象的readLine方法读取所述第二配置文件中当前行中的数据;S33122,若使用contains方法获知所述当前行中不存在“dependencies”字符串,则将文件游标移动到下一行的开头;S33123,将所述下一行作为当前行迭代执行步骤S33121至S33123,直到读取到“dependencies”字符串。On the basis of the above embodiment, the step S3312 in this embodiment specifically includes: S33121, calling the readLine method of the file object to read the data in the current line in the second configuration file; S33122, if the contains method is used Knowing that the "dependencies" string does not exist in the current line, move the file cursor to the beginning of the next line; S33123, iteratively execute steps S33121 to S33123 with the next line as the current line, until the "dependencies" character is read string.

在上述实施例,所述步骤S332包括:使用seek方法将文件游标移动到“dependencies”字符串所在行的下一行;使用write方法将所述版本信息写入到所述第二配置文件中;使用flush方法,对所述第二配置文件进行刷新。In the above embodiment, the step S332 includes: using the seek method to move the file cursor to the next line of the line where the "dependencies" string is located; using the write method to write the version information into the second configuration file; using The flush method refreshes the second configuration file.

在上述实施例的基础上,本实施例中所述步骤S3之后还包括:对所述集合变量中第一版本号的值和/或第二版本号的值进行更改。On the basis of the above embodiment, in this embodiment, after step S3, the method further includes: changing the value of the first version number and/or the value of the second version number in the set variable.

具体地,组件的第二配置文件中ARouter的所述版本信息全部依赖于定义的所述集合变量中Arouter的第一版本号和第二版本号。当需要对Arouter进行升级时,仅需要更改所述集合变量中Arouter的第一版本号和/或第二版本号,从而实现对所有组件所引入的ARouter的版本进行了统一升级,节约时间。Specifically, the version information of ARouter in the second configuration file of the component all depends on the first version number and the second version number of ARouter in the defined set variable. When the Arouter needs to be upgraded, only the first version number and/or the second version number of the Arouter in the set variable needs to be changed, so that the versions of the Arouter introduced by all components are upgraded uniformly, saving time.

在本发明的另一个实施例中提供一种Android中引入ARouter的装置,图2为本发明实施例提供的Android中引入ARouter的装置整体结构示意图,该装置包括创建单元1、生成单元2和注入单元3,其中:In another embodiment of the present invention, an apparatus for introducing ARouter into Android is provided. FIG. 2 is a schematic diagram of the overall structure of an apparatus for introducing ARouter into Android according to an embodiment of the present invention. The apparatus includes acreation unit 1, ageneration unit 2, and an injection unit.Unit 3, where:

所述创建单元1用于创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;所述生成单元2用于根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;所述注入单元3用于当组件被创建时,在所述组件的第二配置文件中注入所述版本信息。Thecreation unit 1 is configured to create a first configuration file, in which a set variable is defined, the set variable is a global variable, and the first version number of the ARouter core function and the ARouter core function are defined in the set variable The second version number of the parser; thegenerating unit 2 is used to generate the version information introduced into the ARouter according to the first version number and the second version number; theinjection unit 3 is used when the component is created when the version information is injected into the second configuration file of the component.

具体地,在引入ARouter的时候需要ARouter的版本号。为了方便后期同一更新所有组件的配置文件中Arouter的版本信息,所述创建单元1将Arouter的版本号定义在一个独立的全局变量中,从而使得所有组件所引入的Arouter的版本号相同,方便后期对所有组件引入的Arouter的版本号进行统一升级和管理。Arouter的版本号包括ARouter的核心功能的第一版本号和ARouter的解析器的第二版本号。所述第一配置文件为config.gradle配置文件。ARouter的第一版本号由ARouter的核心功能库定义,第二版本号由解析器库定义。通过配置所述第一版本号和所述第二版本号以配置ARouter。当定义好了全局的ARouter的版本号后,所述生成单元2根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息,所述版本信息为包含所述第一版本号和所述第二版本号的配置语句。当捕捉到有组件被创建时,所述注入单元3在所述组件的第二配置文件中注入所述版本信息。所述第二配置文件为build.gradle脚本文件。从而实现在新建组件中自动注入ARouter的版本号。Specifically, the version number of ARouter is required when introducing ARouter. In order to facilitate the later update of the version information of Arouter in the configuration files of all components at the same time, thecreation unit 1 defines the version number of Arouter in an independent global variable, so that the version numbers of Arouter introduced by all components are the same, which is convenient for later Unified upgrade and management of Arouter version numbers introduced by all components. The version number of ARouter includes the first version number of the core function of ARouter and the second version number of the parser of ARouter. The first configuration file is a config.gradle configuration file. The first version number of ARouter is defined by the core function library of ARouter, and the second version number is defined by the parser library. ARouter is configured by configuring the first version number and the second version number. After the global version number of the ARouter is defined, the generatingunit 2 generates version information for importing the ARouter according to the first version number and the second version number, where the version information includes the first version number and the second version number. A configuration statement for a version number and the second version number. When capturing that a component is created, theinjection unit 3 injects the version information into the second configuration file of the component. The second configuration file is a build.gradle script file. In this way, the version number of ARouter is automatically injected into the new component.

本实施例一方面通过将ARouter的核心功能的第一版本号和解析器的第二版本号放在一个全局的集合变量中,避免重名,当ARouter的版本的版本号发生变化时,只用更改所述集合变量,实现了对所有组件引入的Arouter的版本号进行统一升级和管理,便于维护,另一方面根据所述集合变量生成引入所述ARouter的版本信息,当组件被创建时自动在所述组件的第二配置文件中注入所述版本信息,实现在组件创建时自动配置ARouter的版本号,提高了开发效率和配置的准确性。In this embodiment, on the one hand, the first version number of the core function of ARouter and the second version number of the parser are placed in a global set variable to avoid duplication of names. When the version number of the ARouter version changes, only the Changing the set variable realizes unified upgrade and management of the version numbers of Arouter introduced by all components, which is convenient for maintenance. The version information is injected into the second configuration file of the component, so that the version number of the ARouter is automatically configured when the component is created, which improves development efficiency and configuration accuracy.

在上述实施例的基础上,本实施例中所述生成单元具体用于在所述第一版本号的变量和所述第二版本号的变量前分别添加$符号,生成引入所述ARouter的版本信息。On the basis of the above-mentioned embodiment, the generating unit in this embodiment is specifically configured to add a $ symbol before the variable of the first version number and the variable of the second version number, respectively, to generate a version introduced into the ARouter information.

在上述各实施例的基础上,本实施例中所述注入单元包括:注册子单元,用于使用register函数注册监听器;回调子单元,用于当使用所述监听器监听到组件被创建时,回调组件创建方法;注入子单元,用于使用所述组件创建方法,在所述组件的第二配置文件中注入所述版本信息。On the basis of the above embodiments, the injection unit in this embodiment includes: a registration subunit, used to register a listener using the register function; a callback subunit, used to use the listener to monitor when a component is created , the component creation method is called back; the injection subunit is used to inject the version information into the second configuration file of the component by using the component creation method.

在上述实施例的基础上,本实施例中所述注入子单元包括:读取子单元,用于获取所述组件的第二配置文件,依次读取所述第二配置文件中的各行数据,直到读取到“dependencies”字符串;插入子单元,用于在“dependencies”字符串所在行的下一行插入所述版本信息。On the basis of the above-mentioned embodiment, the injection subunit in this embodiment includes: a reading subunit, configured to acquire the second configuration file of the component, and sequentially read each row of data in the second configuration file, Until the "dependencies" string is read; insert a subunit for inserting the version information on the line below the line where the "dependencies" string is located.

在上述实施例的基础上,本实施例中所述读取子单元包括:打开子单元,用于使用File类中的open方法打开所述第二配置文件,返回所述第二配置文件的文件对象;调用子单元,用于调用所述文件对象的readLine方法读取所述第二配置文件中的各行数据,直到读取到“dependencies”字符串。On the basis of the above embodiment, the reading subunit in this embodiment includes: an opening subunit, which is used to open the second configuration file by using the open method in the File class, and return the file of the second configuration file Object; the calling subunit is used to call the readLine method of the file object to read each line of data in the second configuration file until the "dependencies" string is read.

在上述实施例的基础上,本实施例中所述调用子单元具体用于:调用所述文件对象的readLine方法读取所述第二配置文件中当前行中的数据;若所述当前行中不存在“dependencies”字符串,则将文件游标移动到下一行的开头;将所述下一行作为当前行迭代执行上述读取数据、判断和移动到下一行的步骤,直到读取到“dependencies”字符串。On the basis of the above embodiment, the calling subunit in this embodiment is specifically used to: call the readLine method of the file object to read the data in the current line in the second configuration file; If there is no "dependencies" string, move the file cursor to the beginning of the next line; iteratively execute the above steps of reading data, judging and moving to the next line with the next line as the current line, until "dependencies" is read string.

在上述实施例的基础上,本实施例中所述插入子单元具体用于:使用seek方法将文件游标移动到“dependencies”字符串所在行的下一行;使用write方法将所述版本信息写入到所述第二配置文件中;使用flush方法,对所述第二配置文件进行刷新。On the basis of the above embodiment, the insert subunit in this embodiment is specifically used to: use the seek method to move the file cursor to the next line of the line where the "dependencies" string is located; use the write method to write the version information into into the second configuration file; use the flush method to refresh the second configuration file.

在上述实施例的基础上,本实施例中所述装置还包括升级单元,用于对所述集合变量中第一版本号的值和/或第二版本号的值进行更改。On the basis of the above embodiment, the apparatus in this embodiment further includes an upgrade unit, configured to modify the value of the first version number and/or the value of the second version number in the set variable.

本实施例提供一种Android中引入ARouter的设备,图3为本发明实施例提供的Android中引入ARouter的设备整体结构示意图,该设备包括:至少一个处理器31、至少一个存储器32和总线33;其中,This embodiment provides a device that introduces ARouter into Android. FIG. 3 is a schematic diagram of the overall structure of the device that introduces ARouter into Android according to an embodiment of the present invention. The device includes: at least oneprocessor 31, at least onememory 32, and abus 33; in,

所述处理器31和存储器32通过所述总线33完成相互间的通信;Theprocessor 31 and thememory 32 communicate with each other through thebus 33;

所述存储器32存储有可被所述处理器31执行的程序指令,所述处理器调用所述程序指令能够执行上述各方法实施例所提供的方法,例如包括:S1,创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;S2,根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;S3,当组件被创建时,在所述组件的第二配置文件中注入所述版本信息。Thememory 32 stores program instructions that can be executed by theprocessor 31, and the processor invokes the program instructions to be able to execute the methods provided by the above method embodiments, for example, including: S1, creating a first configuration file, A set variable is defined in the first configuration file, the set variable is a global variable, and the first version number of the ARouter core function and the second version number of the ARouter parser are defined in the set variable; S2, according to the The first version number and the second version number are used to generate version information imported into the ARouter; S3, when the component is created, the version information is injected into the second configuration file of the component.

本实施例提供一种非暂态计算机可读存储介质,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行上述各方法实施例所提供的方法,例如包括:S1,创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;S2,根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;S3,当组件被创建时,在所述组件的第二配置文件中注入所述版本信息。This embodiment provides a non-transitory computer-readable storage medium, where the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions cause the computer to execute the methods provided by the foregoing method embodiments, for example, including : S1, create a first configuration file, define a set variable in the first configuration file, the set variable is a global variable, and define the first version number of the ARouter core function and the first version number of the ARouter parser in the set variable Second version number; S2, according to the first version number and the second version number, generate the version information introduced into the ARouter; S3, when the component is created, inject all the components into the second configuration file of the component version information.

本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by program instructions related to hardware, the aforementioned program can be stored in a computer-readable storage medium, and when the program is executed, execute It includes the steps of the above method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other media that can store program codes.

以上所描述的Android中引入ARouter的设备实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The above-described device embodiments for introducing ARouter into Android are only illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical unit, that is, it can be located in one place, or it can be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution in this embodiment. Those of ordinary skill in the art can understand and implement it without creative effort.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。From the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and certainly can also be implemented by hardware. Based on this understanding, the above-mentioned technical solutions can be embodied in the form of software products in essence or the parts that make contributions to the prior art, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic A disc, an optical disc, etc., includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform the methods described in various embodiments or some parts of the embodiments.

最后,本申请的方法仅为较佳的实施方案,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。Finally, the method of the present application is only a preferred embodiment, and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims (9)

Translated fromChinese
1.一种Android中引入ARouter的方法,其特征在于,包括:1. a method for introducing ARouter in Android, is characterized in that, comprises:S1,创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;S1, create a first configuration file, define a set variable in the first configuration file, the set variable is a global variable, and define the first version number of the ARouter core function and the second version number of the ARouter parser in the set variable version number;S2,根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;S2, according to the first version number and the second version number, generate the version information introduced into the ARouter;S3,当组件被创建时,在所述组件的第二配置文件中注入所述版本信息;S3, when the component is created, inject the version information into the second configuration file of the component;其中,所述步骤S3具体包括:Wherein, the step S3 specifically includes:S31,使用register函数注册监听器;S31, use the register function to register the listener;S32,当使用所述监听器监听到组件被创建时,回调组件创建方法;S32, when using the listener to monitor that the component is created, call back the component creation method;S33,使用所述组件创建方法,在所述组件的第二配置文件中注入所述版本信息。S33. Using the component creation method, inject the version information into the second configuration file of the component.2.根据权利要求1所述的方法,其特征在于,所述步骤S2具体包括:2. The method according to claim 1, wherein the step S2 specifically comprises:在所述第一版本号的变量和所述第二版本号的变量前分别添加$符号,生成引入所述ARouter的版本信息。A $ sign is respectively added before the variable of the first version number and the variable of the second version number to generate version information introduced into the ARouter.3.根据权利要求1所述的方法,其特征在于,所述步骤S33具体包括:3. The method according to claim 1, wherein the step S33 specifically comprises:S331,获取所述组件的第二配置文件,依次读取所述第二配置文件中的各行数据,直到读取到“dependencies”字符串;S331, obtain the second configuration file of the component, and sequentially read each row of data in the second configuration file, until the "dependencies" string is read;S332,在“dependencies”字符串所在行的下一行插入所述版本信息。S332, insert the version information in the row next to the row where the "dependencies" string is located.4.根据权利要求3所述的方法,其特征在于,所述步骤S331具体包括:4. The method according to claim 3, wherein the step S331 specifically comprises:S3311,使用File类中的open方法打开所述第二配置文件,返回所述第二配置文件的文件对象;S3311, use the open method in the File class to open the second configuration file, and return the file object of the second configuration file;S3312,调用所述文件对象的readLine方法读取所述第二配置文件中的各行数据,直到读取到“dependencies”字符串。S3312, calling the readLine method of the file object to read each line of data in the second configuration file until the "dependencies" string is read.5.根据权利要求4所述的方法,其特征在于,所述步骤S3312具体包括:5. The method according to claim 4, wherein the step S3312 specifically comprises:S33121,调用所述文件对象的readLine方法读取所述第二配置文件中当前行中的数据;S33121, calling the readLine method of the file object to read the data in the current line in the second configuration file;S33122,若所述当前行中不存在“dependencies”字符串,则将文件游标移动到下一行的开头;S33122, if the "dependencies" string does not exist in the current line, move the file cursor to the beginning of the next line;S33123,将所述下一行作为当前行迭代执行步骤S33121至S33123,直到读取到“dependencies”字符串。S33123, iteratively execute steps S33121 to S33123 with the next line as the current line, until the "dependencies" string is read.6.根据权利要求3所述的方法,其特征在于,所述步骤S332包括:6. The method according to claim 3, wherein the step S332 comprises:使用seek方法将文件游标移动到“dependencies”字符串所在行的下一行;Use the seek method to move the file cursor to the line below the line where the "dependencies" string is located;使用write方法将所述版本信息写入到所述第二配置文件中;using the write method to write the version information into the second configuration file;使用flush方法,对所述第二配置文件进行刷新。Using the flush method, refresh the second configuration file.7.根据权利要求1-6任一所述的方法,其特征在于,所述步骤S3之后还包括:7. The method according to any one of claims 1-6, wherein after the step S3, the method further comprises:对所述集合变量中第一版本号的值和/或第二版本号的值进行更改。A change is made to the value of the first version number and/or the value of the second version number in the set variable.8.一种Android中引入ARouter的装置,其特征在于,包括:8. A device for introducing ARouter in Android, characterized in that, comprising:创建单元,用于创建第一配置文件,在所述第一配置文件中定义集合变量,所述集合变量为全局变量,在所述集合变量中定义ARouter核心功能的第一版本号和ARouter解析器的第二版本号;The creation unit is used to create a first configuration file, in which a set variable is defined, the set variable is a global variable, and the first version number of the ARouter core function and the ARouter parser are defined in the set variable The second version number of ;生成单元,用于根据所述第一版本号和所述第二版本号,生成引入所述ARouter的版本信息;a generating unit, configured to generate version information introduced into the ARouter according to the first version number and the second version number;注入单元,用于当组件被创建时,在所述组件的第二配置文件中注入所述版本信息;an injection unit, configured to inject the version information into the second configuration file of the component when the component is created;其中,所述注入单元包括:Wherein, the injection unit includes:注册子单元,用于使用register函数注册监听器;Register subunits for registering listeners using the register function;回调子单元,用于当使用所述监听器监听到组件被创建时,回调组件创建方法;The callback subunit is used to call back the component creation method when the listener is used to monitor the creation of the component;注入子单元,用于使用所述组件创建方法,在所述组件的第二配置文件中注入所述版本信息。The injection subunit is used for injecting the version information in the second configuration file of the component by using the component creation method.9.一种非暂态计算机可读存储介质,其特征在于,所述非暂态计算机可读存储介质存储计算机指令,所述计算机指令使所述计算机执行如权利要求1至7任一所述的方法。9. A non-transitory computer-readable storage medium, characterized in that the non-transitory computer-readable storage medium stores computer instructions, the computer instructions cause the computer to execute any one of claims 1 to 7 Methods.
CN201711130180.5A2017-11-152017-11-15Method and device for introducing ARouter into AndroidExpired - Fee RelatedCN108021389B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201711130180.5ACN108021389B (en)2017-11-152017-11-15Method and device for introducing ARouter into Android

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201711130180.5ACN108021389B (en)2017-11-152017-11-15Method and device for introducing ARouter into Android

Publications (2)

Publication NumberPublication Date
CN108021389A CN108021389A (en)2018-05-11
CN108021389Btrue CN108021389B (en)2021-01-01

Family

ID=62080631

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201711130180.5AExpired - Fee RelatedCN108021389B (en)2017-11-152017-11-15Method and device for introducing ARouter into Android

Country Status (1)

CountryLink
CN (1)CN108021389B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN109189490A (en)*2018-07-032019-01-11武汉斗鱼网络科技有限公司A kind of configuration method and relevant device of module
CN112256324B (en)*2020-12-082021-03-19智道网联科技(北京)有限公司Method and device for processing files in android application program construction process

Citations (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN102880456A (en)*2012-07-312013-01-16北京奇虎科技有限公司Method and device for creating plug-in

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
TW201224814A (en)*2010-12-072012-06-16Hon Hai Prec Ind Co LtdSystem and method for updating software on android
CN105988995B (en)*2015-01-272019-05-24杭州海康威视数字技术股份有限公司A method of based on HFile batch load data

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN102880456A (en)*2012-07-312013-01-16北京奇虎科技有限公司Method and device for creating plug-in

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
浅谈android组件化之ARouter简单使用;繁华落尽666;《脚本之家 https://www.jb51.net/article/123776.htm 》;20170915;第1-10页*

Also Published As

Publication numberPublication date
CN108021389A (en)2018-05-11

Similar Documents

PublicationPublication DateTitle
CN103744709B (en)patch loading method and device
CN110780860A (en)Generation method and device of table building script, computer equipment and storage medium
CN112988583B (en)Method and device for testing grammar compatibility of database
CN108923997B (en) A python-based cloud service node automatic testing method and device
CN114721681A (en)Configuration file updating method, device, equipment and storage medium
CN111930398B (en) Application program update method, device, system, medium and equipment
CN113900944B (en) A logical verification method and device applied to Flink SQL
CN109446047B (en)Performance test platform script storage method, device, equipment and storage medium
CN108021389B (en)Method and device for introducing ARouter into Android
WO2025195153A1 (en)Spark engine-based static parsing method and apparatus for data lineage, medium, and product
CN108279905B (en)Method and device for introducing library file into assembly
CN113032004B (en) Method, apparatus and program product for managing development work in a development environment
CN110781639A (en)Method and device for automatic marking in PCB design
CN113836852B (en)Analog bit stream generation method, device, equipment and storage medium
CN112433738B (en) A firmware update testing method, system, device and medium
CN117668777A (en)Data authority management method and system based on mybatis frame interceptor
CN108595488B (en) Data migration method and apparatus
CN114398074A (en) Method and device for automatic interface development
CN114115982A (en)Code issuing method, device, equipment and storage medium
CN111008018A (en)CAN signal unpacking processing method and system
CN106681914B (en)Television picture quality debugging method and device
CN116303476B (en) Big data storage method, device, electronic equipment and medium
CN116562204B (en)Chip verification method and device, electronic equipment and computer readable storage medium
CN113791786B (en)APP page control automation method and device based on IOS system
CN113296789B (en)Code generation method, device, equipment and storage medium

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant
CF01Termination of patent right due to non-payment of annual fee
CF01Termination of patent right due to non-payment of annual fee

Granted publication date:20210101


[8]ページ先頭

©2009-2025 Movatter.jp