Android plug-in method, device and equipment based on Jetpack Compose

Through Jetpack Compose and lazy loading strategies, Android plug-in UI and resources are dynamically loaded, solving the problems of UI update complexity and performance bottlenecks in the existing technology, achieving improved response speed and reduced resource consumption, while ensuring UI consistency.

CN118916093BActive Publication Date: 2025-01-14SHENZHEN DADAO CLOUD TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411409350.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-10
Publication Date
2025-01-14
Estimated Expiration
2044-10-10

AI Technical Summary

Technical Problem

The existing Android plug-in technology has problems such as high UI update and maintenance complexity, performance bottlenecks, high resource consumption, and difficult to guarantee UI style and behavior consistency, especially on low-configuration devices to respond slowly.

Method used

Using Jetpack Compose-based method, by downloading the plug-in's apk file and loading it with DexClassLoader, annotating and marking the Composable function, dynamically loading the plug-in UI and resources through reflection calls and lazy loading strategies, reducing the initial loading time, and optimizing it through LazyColumn or LazyRow components List rendering, asynchronous loading using WebP compressed images and coil framework, memory user interface status and listen for lifecycle events.

Benefits of technology

Improves application response speed, reduces resource consumption, ensures consistency of UI style and behavior, and optimizes the initial loading time of the user interface.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916093B_ABST
    Figure CN118916093B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of computers, and discloses an Android plug-in method, device and equipment based on Jetpack Compose. The method comprises: downloading the apk file of the plug-in to the local; loading the apk file of the plug-in through the class loader DexClassLoader; annotating the functions in the apk file to obtain the Composable function of the plug-in; loading the user interface by reflecting and calling the Composable function of the plug-in to realize dynamic loading of the plug-in UI and resources; loading and rendering the corresponding combination items in the visible area of ​​the user interface through the lazy loading strategy to reduce the initial loading time of the user interface. In an embodiment of the present invention, the plug-in UI and resources can be loaded dynamically, and the plug-in UI components can be loaded on demand, thereby improving the response speed of the application and reducing resource consumption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to an Android plug-in method, device, equipment and storage medium based on Jetpack Compose. Background Art

[0002] As the complexity of Android programs and services increases, the efficiency of updating and releasing all functions and services integrated into one App will be very low. Therefore, the method of using the main program to implement basic functional services and plug-ins to implement additional functional services has become the mainstream.

[0003] Android does not have an officially supported plug-in technology, so there are various plug-in technologies on the Internet, each with its own advantages and disadvantages. First, the traditional plug-in implementation method relies on the View hierarchy, and UI updates and maintenance require a lot of code, which increases the complexity of development and maintenance. Secondly, the View components in plug-in applications may cause performance bottlenecks when dynamically loaded, especially on low-configuration devices, resulting in slower application response and increased resource consumption. In addition, it is difficult to ensure the consistency of traditional plug-in UI style and behavior, which affects the user experience. Summary of the invention

[0004] The main purpose of the present invention is to solve the technical problem of how to dynamically load plug-in UI and resources to improve the response speed of the application and reduce resource consumption.

[0005] A first aspect of the present invention provides an Android plug-in method based on Jetpack Compose, and the Android plug-in method based on Jetpack Compose includes:

[0006] Download the plug-in's apk file to the local computer. The apk file includes all the content required to run the application.

[0007] Load the apk file of the plug-in through the class loader DexClassLoader;

[0008] Annotate the functions in the apk file to obtain a Composable function of the plug-in, where the Composable function is used to define a combination item of the functions in the apk file to describe the shape and data dependency of the user interface;

[0009] The user interface is loaded by calling the Composable function of the plug-in through reflection, so as to realize dynamic loading of the plug-in UI and resources;

[0010] The corresponding combination item is loaded and rendered in the visible area of ​​the user interface through a lazy loading strategy, so as to reduce the initial loading time of the user interface.

[0011] Optionally, in a first implementation of the first aspect of the present invention, loading and rendering the corresponding combination item in the visible area of ​​the user interface by using a lazy loading strategy includes:

[0012] Define a list of the user interface, and define a corresponding key for each of the combination items of the user interface, wherein the list contains all the combination items of the user interface;

[0013] Tracking the scroll position of the list through a component of a lazy loading strategy LazyColumn or LazyRow, and obtaining a combination item in a visible area of ​​the user interface according to the scroll position;

[0014] According to the key corresponding to the combination item in the visible area, the combination item in the visible area is loaded and rendered, so that only the display content of the visible area is loaded first.

[0015] Optionally, in a second implementation of the first aspect of the present invention, before loading and rendering the combination item in the visible area, the method further includes:

[0016] Compressing the image of the user interface via webp;

[0017] Store compressed images in the cloud;

[0018] When loading the image of the user interface, the coil framework is used to asynchronously load the image from the cloud and cache it to avoid repeated downloading of the image.

[0019] Optionally, in a third implementation manner of the first aspect of the present invention, after loading the user interface by calling the Composable function of the plug-in through reflection, the method further includes:

[0020] Storing the user interface state through the remember function so that the user interface state is retained and restored when the user interface view is rebuilt;

[0021] The life cycle events of the combined item are monitored through LaunchedEffect or DisposableEffect to monitor the initialization and destruction of the user interface and perform asynchronous operations.

[0022] Optionally, in a fourth implementation of the first aspect of the present invention, the loading the user interface by calling the Composable function of the plug-in through reflection includes:

[0023] Set the global theme through the CompositionLocalProvider component;

[0024] Passing the global theme to the Composable function through the CompositionLocalProvider component;

[0025] The user interface is loaded by calling the Composable function of the plug-in through reflection, so as to use the global theme in the user interface.

[0026] Optionally, in a fifth implementation of the first aspect of the present invention, the loading of the apk file of the plug-in by the class loader DexClassLoader includes:

[0027] Get the path of the apk file of the plug-in;

[0028] Create a class loader object through the class loader DexClassLoader, and dynamically load the classes in the apk file through the class loader object;

[0029] Create a resource object and dynamically read the resources in the apk file through the resource object.

[0030] Optionally, in a sixth implementation of the first aspect of the present invention, before annotating the function in the apk file, the method further includes:

[0031] Obtain a ProGuard configuration file, and compress the code in the apk file according to the ProGuard configuration file and the code obfuscator R8.

[0032] A second aspect of the present invention provides an Android plug-in device implemented based on Jetpack Compose, comprising: a memory and at least one processor, the memory storing instructions, the memory and the at least one processor being interconnected via a line; the at least one processor calling the instructions in the memory so that the Android plug-in device implemented based on Jetpack Compose executes the above-mentioned Android plug-in method implemented based on Jetpack Compose.

[0033] A third aspect of the present invention provides a computer-readable storage medium, which stores instructions. When the computer-readable storage medium is run on a computer, it enables the computer to execute the above-mentioned Android plug-in method based on Jetpack Compose.

[0034] In an embodiment of the present invention, the apk file of the plug-in is downloaded locally, and the apk file includes all the contents required to run the application program; the apk file of the plug-in is loaded through the class loader DexClassLoader; the functions in the apk file are annotated to obtain the Composable function of the plug-in, and the Composable function is used to define the combination items of the functions in the apk file to describe the shape and data dependency of the user interface; the Composable function of the plug-in is called through reflection to load the user interface to achieve dynamic loading of the plug-in UI and resources; the corresponding combination items are loaded and rendered in the visible area of ​​the user interface through the lazy loading strategy to reduce the initial loading time of the user interface. By defining the combination items of the functions in the apk file through the Composable function, and calling the Composable function through the class loader DexClassLoader and reflection, the plug-in UI and resources can be dynamically loaded, and the plug-in UI components can be loaded on demand, thereby improving the response speed of the application and reducing resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Figure 1 It is a schematic diagram of an embodiment of an Android plug-in method implemented based on Jetpack Compose in an embodiment of the present invention;

[0036] Figure 2 Schematic diagram of an embodiment of an Android plug-in device implemented based on Jetpack Compose in an embodiment of the present invention;

[0037] Figure 3 This is a schematic diagram of an embodiment of an Android plug-in device implemented based on Jetpack Compose in an embodiment of the present invention. DETAILED DESCRIPTION

[0038] The embodiments of the present invention provide an Android plug-in method, apparatus, device and storage medium based on Jetpack Compose.

[0039] The embodiments disclosed in the present invention will be described in more detail below with reference to the accompanying drawings. Although certain embodiments disclosed in the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present invention. It should be understood that the drawings and embodiments disclosed in the present invention are only for exemplary purposes and are not intended to limit the scope of protection disclosed in the present invention.

[0040] In the description of the embodiments disclosed in the present invention, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below.

[0041] Jetpack Compose is a brand new UI development framework that uses declarative programming to build UI and provides a set of modern APIs to simplify UI development for Android applications. Traditional Android UI development uses imperative programming, which requires developers to manually write code to update the UI state. Declarative programming builds the UI by describing the UI state, and the system automatically updates the UI based on state changes. Declarative programming reduces a lot of redundant code, making the code more concise and easy to read, reducing errors and maintenance difficulties.

[0042] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the Android plug-in method implemented based on Jetpack Compose in an embodiment of the present invention includes:

[0043] S100, download the plug-in apk file to the local computer.

[0044] In this embodiment, first, a plug-in architecture is designed, which includes a main application module, a plug-in module and a common module, wherein the main application module is responsible for loading and managing plug-ins, the plug-in module contains independent functional modules, such as login, shopping cart, etc., the common module provides common base classes, tool classes and third-party libraries, the common module is directly packaged into the App main application apk, and the plug-in module introduces the common module through compileOnly, so that the code of the common module will not be packaged, which can greatly reduce the size of the plug-in apk file. In Debug mode, each module is directly introduced into the App main application and can be run directly, reducing the process of publishing plug-ins; in Release mode, the plug-in module can be published independently and loaded through the network or local cache. Among them, apk is an application package file format used by the Android operating system for distributing and installing mobile applications and middleware. The apk file contains all the code, resource files, configuration files, etc. of the application.

[0045] S200, load the plug-in apk file through the class loader DexClassLoader.

[0046] In this embodiment, the class loader DexClassLoader can load classes containing classes.dex entries from the apk file. This mechanism allows the execution of code that is not installed as part of the application, thereby realizing dynamic loading and execution of code. Specifically, DexClassLoader can load a compressed package containing a classes.dex file. These compressed packages can be in jar format or apk format. By using DexClassLoader, the apk file can be dynamically loaded to realize the hot update function of the application, that is, to update some functions of the application without restarting the application; and by loading an external apk file, new functions can be added to the main application without modifying and republishing the main application.

[0047] S300, annotate the functions in the apk file to obtain the Composable function of the plug-in.

[0048] In this embodiment, the functions in the apk file are marked with the @Composable annotation to obtain the Composable function of the plug-in. The Composable function is used to define composable items. These functions describe the shape and data dependencies of the interface, but do not care about the update of the interface. They are pure functions that do not directly correspond to any View controls, but are functions that use Canvas for underlying rendering. Specifically, the Composable function is converted by the Kotlin compiler plug-in and the optimization function is enabled. This process occurs in the Kotlin code base, ensuring the correct conversion and optimization of the Composable function. When the state of the user interface changes, only the composite items that have read the state will be reorganized to update the display. This local refresh strategy is an intelligent reorganization, which will decide whether to reorganize based on whether the parameters have changed, so as to achieve efficient reorganization performance optimization.

[0049] S400, loading the user interface by calling the Composable function of the plug-in through reflection, so as to realize dynamic loading of the plug-in UI and resources.

[0050] In this embodiment, when it is necessary to dynamically load the user interface, the Composable functions in the plug-in can be obtained through the reflection mechanism, and then these functions are called to generate and update the user interface, which allows the developer to load different user interface components as needed at runtime, thereby achieving a more flexible and dynamic user experience. By calling the Composable function in the plug-in through reflection, plug-in development can be implemented, allowing the application to dynamically load or unload different user interface components based on the user's operations or the state of the system, thereby providing a richer and more personalized user experience. However, when using reflection to call the Composable function, it is necessary to pay attention to handling additional parameters and logic in the compilation process to ensure correct control and reorganization. In addition, since the call to the Composable function must occur in the context of the Composable function, it is necessary to handle the calling relationship and context environment to ensure the correct loading and updating of the user interface.

[0051] S500, loading and rendering corresponding combination items in a visible area of ​​the user interface through a lazy loading strategy, so as to reduce the initial loading time of the user interface.

[0052] In this embodiment, the lazy loading strategy dynamically loads and renders data based on the currently visible composite items, rather than rendering all composite items at once. The rendering of composite items is based on whether they are in the visible area. If the composite item is not in the visible area, no rendering and calculation will be performed. When the composite item is close to the visible area, actual rendering and calculation will be performed. Using the lazy loading strategy can reduce the initial loading time of the user interface, only load the content displayed on the screen, reduce unnecessary redrawing and calculation, and dynamically load the views that move into the screen and destroy the views that move out of the screen when the user slides the screen.

[0053] In an optional implementation of the first aspect of the present invention, loading and rendering the corresponding combination item in the visible area of ​​the user interface through a lazy loading strategy includes:

[0054] Define a list of user interfaces and define a corresponding key for each component of the user interface. The list contains all the components of the user interface. Track the scroll position of the list through the lazy loading strategy LazyColumn or LazyRow component, and obtain the components in the visible area of ​​the user interface according to the scroll position. Load and render the components in the visible area according to the key corresponding to the components in the visible area, so that only the display content of the visible area is loaded first.

[0055] In this embodiment, lazy loading is implemented using the LazyColumn and LazyRow components in Jetpack Compose. Their main function is to optimize the rendering performance of a large number of list items. These components will only combine and layout the list items visible in the component viewport, thereby avoiding the problem of combining and laying out all list items in the traditional layout method. LazyColumn is used to arrange list items vertically, while LazyRow is used to arrange list items horizontally. The functions they support include reverse layout, scroll state, direction adjustment, separators, multiple view types, etc. The lazy loading strategy is mainly implemented through the items function and the itemContent function. The items function defines the data set to be rendered, and the itemContent function defines how to display each data item. Specifically, the list of the user interface is specified through the items function, and the list contains all the combined items of the user interface. A key is specified for all the combined items in the items, and the itemContent builder is used to define the rendering content of each combined item. LazyColumn and LazyRow have built-in tracking capabilities for scrolling status. They track the scroll position of the list and load more items as needed. When the LazyColumn or LazyRow scrolls to a certain position, they calculate which combined items need to be rendered. That is, when the combined items enter the visible area, the LazyColumn or LazyRow will automatically render these combinations.

[0056] In an optional implementation manner of the first aspect of the present invention, before loading and rendering the combination items in the visible area, the method further includes:

[0057] Compress user interface images through webp; store compressed images in the cloud; when loading user interface images, use the coil framework to asynchronously load and cache images from the cloud to avoid repeated downloading of images.

[0058] In this embodiment, WebP is used for image compression because the WebP format can generally provide a smaller file size than JPEG and PNG while maintaining good image quality. The WebP format supports transparency and animation and is supported by most modern browsers, so it is suitable for web page images. Storing compressed images in the cloud can take advantage of the advantages of cloud storage services, ensure the availability and scalability of images, and reduce the burden on local servers. The coil framework is used for asynchronous loading of images, where coil is an efficient image loading library that supports asynchronous loading and caching of images, which can reduce the blocking of the main thread and improve the response speed of the page. The loaded images can be cached locally or in the cloud, and can be directly obtained from the cache the next time they are accessed, avoiding repeated downloads and speeding up loading.

[0059] In an optional implementation of the first aspect of the present invention, after loading the user interface by calling the Composable function of the plug-in through reflection, the method further includes:

[0060] The remember function is used to store the UI state so that it can be retained and restored when the UI view is rebuilt. The life cycle events of the composite items are monitored through LaunchedEffect or DisposableEffect to monitor the initialization and destruction of the UI and perform asynchronous operations.

[0061] In this embodiment, the remember function is used to retain the state when the view is rebuilt, ensuring that the data will not be lost when the interface is reorganized. This is very useful for state preservation in situations such as screen rotation, adding or removing elements, and parent element reorganization. The remember function prevents the state from being initialized to the default value after reorganization by remembering the modified value (stored in the UI tree), thereby maintaining data consistency. Specifically, the use scenarios of the remember function include but are not limited to: saving the scroll position of a list, saving the ID of an item that the user wants to know more about, saving ongoing user preference selections, and saving input in a text field.

[0062] Listen to the life cycle events of the composite item through LaunchedEffect or DisposableEffect. LaunchedEffect and DisposableEffect are two ways to handle incidental effects in Jetpack Compose. They can listen to the initialization and destruction of the user interface and perform asynchronous operations, receive external data callbacks, and cooperate with LifeCycle to allow Compose to monitor the life cycle of the composite item, such as creation, start, pause, resume, stop and destruction. This enables Compose to perform corresponding operations according to the state changes of the composite item, such as data statistics, resource release, etc.

[0063] In an optional implementation of the first aspect of the present invention, loading the user interface by reflection calling the Composable function of the plug-in includes:

[0064] Set the global theme through the CompositionLocalProvider component; pass the global theme to the Composable function through the CompositionLocalProvider component; call the Composable function of the plug-in through reflection to load the user interface to use the global theme in the user interface.

[0065] In this embodiment, the global theme is set through CompositionLocalProvider, and the components in the plug-in module obtain the current theme through LocalTheme.current to set the style. By setting the global theme, a set of reusable theme and style definitions is provided to ensure the consistency of UI style and behavior between different plug-ins.

[0066] CompositionLocal is a mechanism provided by Compose for passing data in the UI component tree. CompositionLocal is used to define and store data. It can be regarded as a container that can be passed between components to carry data; while CompositionLocalProvider is a tool for providing this data in the tree. Specifically, the steps to set the global theme through CompositionLocalProvider include: First, you need to define a global theme, which usually involves creating a CompositionLocal object, which will be used as a data container to pass theme information in the Compose UI tree. Next, you need to create a CompositionLocalProvider and pass the defined global theme as a parameter to this CompositionLocalProvider. This CompositionLocalProvider will provide global theme data in the Compose UI tree of the application, ensuring that all child components can access this theme data. Secondly, place the CompositionLocalProvider in the appropriate location of the application, usually at the entry point of the application, so that no matter how many Composable functions there are in the application, they can access the global theme data. Finally, use this global theme in the Composable function, where the global theme is implicitly passed using CompositionLocalProvider, which is passed downward. Therefore, you only need to define the theme style at the top level, and each component in the lower-level plug-ins can directly obtain the current theme through LocalThem.current.

[0067] In an optional implementation of the first aspect of the present invention, loading the apk file of the plug-in through the class loader DexClassLoader includes:

[0068] Get the path of the plug-in's apk file; create a class loader object through the class loader DexClassLoader, and dynamically load the classes in the apk file through the class loader object; create a resource object, and dynamically read the resources in the apk file through the resource object.

[0069] In this embodiment, DexClassLoader can load the dex file in the apk file, so that the application can dynamically load and use the classes and resources in other applications. Specifically, when an application needs to load the classes or resources in another application, it can load the dex file in the apk file by creating a DexClassLoader object. DexClassLoader will dynamically load the dex file into the memory at runtime, and add the classes and resources in it to the class path and resource path of the application, so that the application can use these classes and resources. Dynamically loading apk includes: first downloading the apk file to the local storage, obtaining the path of the apk file, and then creating a class loader object ClassLoader, using the ClassLoader object to dynamically load the classes in the apk file, and then creating a resource object Resources, and dynamically reading the resources in the apk file through the Resources object.

[0070] In an optional implementation manner of the first aspect of the present invention, before annotating the function in the apk file, the method further includes:

[0071] Get the ProGuard configuration file, and compress the code in the apk file according to the ProGuard configuration file and the code obfuscator R8.

[0072] In this embodiment, a proguard-rules.pro file is created, which is a ProGuard configuration file, and custom ProGuard rules are added. These rules can be used to keep specific classes, methods, or variables from being obfuscated, or to apply specific obfuscation rules. R8 is a new generation of code obfuscator introduced in Android Studio 3.6 and above. It provides more efficient obfuscation and optimization strategies. R8 not only supports ProGuard rules, but also provides more advanced optimization techniques such as inlining and dead code elimination. By configuring ProGuard rules and utilizing R8's optimization capabilities, you can optimize the code structure and improve runtime performance, thereby protecting intellectual property rights and improving code execution efficiency. For example, you can configure rules to protect specific classes or methods from being obfuscated, or use R8's Tree shaking optimization function to detect and delete unused code and resources.

[0073] See also Figure 2 A second aspect of the present invention provides an Android plug-in device implemented based on Jetpack Compose, and the Android plug-in device implemented based on Jetpack Compose includes:

[0074] The file download module 10 is used to download the apk file of the plug-in to the local computer. The apk file includes all the contents required to run the application program.

[0075] The file loading module 20 is used to load the apk file of the plug-in through the class loader DexClassLoader;

[0076] The function combination module 30 is used to annotate the functions in the apk file to obtain the Composable function of the plug-in. The Composable function is used to define the combination items of the functions in the apk file to describe the shape and data dependency of the user interface.

[0077] A reflection calling module 40 is used to load the user interface by reflecting and calling the Composable function of the plug-in, so as to realize dynamic loading of the plug-in UI and resources;

[0078] The interface loading module 50 is used to load and render the corresponding combination items in the visible area of ​​the user interface through a lazy loading strategy to reduce the initial loading time of the user interface.

[0079] In an optional implementation of the second aspect of the present invention, the interface loading module 50 is also used to define a list of user interfaces and define a corresponding key for each combination item of the user interface, wherein the list contains all combination items of the user interface; the scrolling position of the list is tracked through the components of the lazy loading strategy LazyColumn or LazyRow, and the combination items in the visible area of ​​the user interface are obtained according to the scrolling position; according to the keys corresponding to the combination items in the visible area, the combination items in the visible area are loaded and rendered, so that only the display content of the visible area is loaded first.

[0080] In an optional implementation of the second aspect of the present invention, the Android plug-in device implemented based on Jetpack Compose further includes:

[0081] The image loading module is used to compress the user interface images through webp; store the compressed images in the cloud; when loading the user interface images, use the coil framework to asynchronously load and cache the images from the cloud to avoid repeated downloading of images.

[0082] In an optional implementation of the second aspect of the present invention, the Android plug-in device implemented based on Jetpack Compose further includes:

[0083] The cache listening module is used to store the user interface state through the remember function, so that the user interface state is retained and restored when the user interface view is rebuilt; the life cycle events of the composite items are listened to through LaunchedEffect or DisposableEffect to listen to the initialization and destruction of the user interface and perform asynchronous operations.

[0084] In an optional implementation of the second aspect of the present invention, the reflection calling module 40 is also used to set the global theme through the CompositionLocalProvider component; pass the global theme to the Composable function through the CompositionLocalProvider component; load the user interface by reflecting and calling the Composable function of the plug-in to use the global theme in the user interface.

[0085] In an optional implementation of the second aspect of the present invention, the file loading module 20 is also used to obtain the path of the plug-in's apk file; create a class loader object through the class loader DexClassLoader, and dynamically load the class in the apk file through the class loader object; create a resource object, and dynamically read the resources in the apk file through the resource object.

[0086] In an optional implementation of the second aspect of the present invention, the Android plug-in device implemented based on Jetpack Compose further includes:

[0087] The compression module is used to obtain the ProGuard configuration file and compress the code in the apk file according to the ProGuard configuration file and the code obfuscator R8.

[0088] Figure 31 is a schematic diagram of the structure of an Android plug-in device based on Jetpack Compose provided by an embodiment of the present invention. The Android plug-in device 500 based on Jetpack Compose may have relatively large differences due to different configurations or performances, and may include one or more processors (central processing units, CPU) 510 (for example, one or more processors) and a memory 520, and one or more storage media 530 (for example, one or more mass storage devices) storing application programs 533 or data 532. Among them, the memory 520 and the storage medium 530 may be short-term storage or persistent storage. The program stored in the storage medium 530 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the Android plug-in device 500 based on Jetpack Compose. Furthermore, the processor 510 may be configured to communicate with the storage medium 530 to execute a series of instruction operations in the storage medium 530 on the Android plug-in device 500 based on Jetpack Compose.

[0089] The Android plug-in device 500 based on Jetpack Compose can also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input and output interfaces 560, and / or one or more operating systems 531, such as Windows Serve, Mac OS X, Unix, Linux, Free BSD, etc. It can be understood by those skilled in the art that Figure 3 The Android plug-in device structure based on Jetpack Compose shown does not constitute a limitation on the Android plug-in device based on Jetpack Compose, and may include more or fewer components than shown in the figure, or a combination of certain components, or a different arrangement of components.

[0090] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the Android plug-in method implemented based on Jetpack Compose.

[0091] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0092] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.

[0093] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

Claims

1. An Android plug-in method based on Jetpack Compose, characterized in that: The Android plug-in method based on Jetpack Compose includes: Download the plug-in's apk file to the local computer. The apk file includes all the content required to run the application. Load the apk file of the plug-in through the class loader DexClassLoader; Annotate the functions in the apk file to obtain a Composable function of the plug-in, where the Composable function is used to define a combination item of the functions in the apk file to describe the shape and data dependency of the user interface; The user interface is loaded by calling the Composable function of the plug-in through reflection, so as to realize dynamic loading of the plug-in UI and resources; Loading and rendering the corresponding combination item in the visible area of ​​the user interface through a lazy loading strategy to reduce the initial loading time of the user interface; The loading and rendering of the corresponding combination item in the visible area of ​​the user interface by using the lazy loading strategy includes: Define a list of the user interface, and define a corresponding key for each of the combination items of the user interface, wherein the list contains all the combination items of the user interface; Tracking the scroll position of the list through the LazyColumn or LazyRow component of the lazy loading strategy, and obtaining the combination item in the visible area of ​​the user interface according to the scroll position; According to the key corresponding to the combination item in the visible area, the combination item in the visible area is loaded and rendered, so that only the display content of the visible area is loaded first; The LazyColumn is used to arrange list items vertically, while the LazyRow is used to arrange list items horizontally; the lazy loading strategy is mainly implemented through the items function and the itemContent function. The items function defines the data set to be rendered, and the itemContent function defines how to display each data item. The list of the user interface is specified through the items function, and the list contains all the combination items of the user interface. A key is specified for all the combination items, and the itemContent builder is used to define the rendering content of each combination item; the LazyColumn and the LazyRow have built-in tracking capabilities for the scrolling state, which will track the scrolling position of the list and load more items as needed. When the LazyColumn or the LazyRow scrolls to a certain position, it will calculate which combination items need to be rendered, that is, when the combination items enter the visible area, the LazyColumn or the LazyRow will automatically render the combination items; The loading of the user interface by calling the Composable function of the plug-in through reflection includes: Set the global theme through the CompositionLocalProvider component; Passing the global theme to the Composable function through the CompositionLocalProvider component; Load the user interface by calling the Composable function of the plug-in through reflection, so as to use the global theme in the user interface; The steps of setting the global theme through the CompositionLocalProvider component include: first, defining a global theme and creating a CompositionLocal object. The CompositionLocal object will be used as a data container to pass theme information in the Compose UI tree; next, creating a CompositionLocalProvider, passing the defined global theme as a parameter to the CompositionLocalProvider, and the CompositionLocalProvider will provide global theme data in the Compose UI tree of the application to ensure that all subcomponents can access the global theme data; secondly, placing the CompositionLocalProvider at the entry point of the application so that no matter how many Composable functions there are in the application, the global theme data can be accessed; finally, using the global theme in the Composable function.

2. The Android plug-in method based on Jetpack Compose according to claim 1, characterized in that: Before loading and rendering the combination item in the visible area, the method further includes: Compressing the image of the user interface via webp; Store compressed images in the cloud; When loading the image of the user interface, the coil framework is used to asynchronously load the image from the cloud and cache it to avoid repeated downloading of the image.

3. The Android plug-in method based on Jetpack Compose according to claim 2, characterized in that: After the Composable function of the plug-in is called by reflection to load the user interface, the method further includes: Storing the user interface state through the remember function so that the user interface state is retained and restored when the user interface view is rebuilt; The life cycle events of the combined item are monitored through LaunchedEffect or DisposableEffect to monitor the initialization and destruction of the user interface and perform asynchronous operations.

4. The Android plug-in method based on Jetpack Compose according to claim 1, characterized in that: The apk file of the plug-in loaded by the class loader DexClassLoader includes: Get the path of the apk file of the plug-in; Create a class loader object through the class loader DexClassLoader, and dynamically load the classes in the apk file through the class loader object; Create a resource object and dynamically read the resources in the apk file through the resource object.

5. The Android plug-in method based on Jetpack Compose according to claim 1, characterized in that: Before annotating the functions in the apk file, the method further includes: Obtain a ProGuard configuration file, and compress the code in the apk file according to the ProGuard configuration file and the code obfuscator R8.

6. An Android plug-in device based on Jetpack Compose, characterized in that: The Android plug-in device implemented based on Jetpack Compose includes: A file download module, used to download the apk file of the plug-in to the local computer, wherein the apk file includes all the contents required to run the application program; A file loading module, used to load the apk file of the plug-in through the class loader DexClassLoader; A function combination module, used to annotate the functions in the apk file to obtain the Composable function of the plug-in, wherein the Composable function is used to define the combination items of the functions in the apk file to describe the shape and data dependency of the user interface; A reflection calling module, used to load the user interface by calling the Composable function of the plug-in through reflection, so as to realize dynamic loading of the plug-in UI and resources; An interface loading module, used to load and render the corresponding combination item in the visible area of ​​the user interface through a lazy loading strategy, so as to reduce the initial loading time of the user interface; The interface loading module is further used to define a list of the user interfaces and define a corresponding key for each of the combination items of the user interfaces, wherein the list contains all the combination items of the user interfaces; Tracking the scroll position of the list through the LazyColumn or LazyRow component of the lazy loading strategy, and obtaining the combination item in the visible area of ​​the user interface according to the scroll position; According to the key corresponding to the combination item in the visible area, the combination item in the visible area is loaded and rendered, so that only the display content of the visible area is loaded first; The LazyColumn is used to arrange list items vertically, while the LazyRow is used to arrange list items horizontally; the lazy loading strategy is mainly implemented through the items function and the itemContent function. The items function defines the data set to be rendered, and the itemContent function defines how to display each data item. The list of the user interface is specified through the items function, and the list contains all the combination items of the user interface. A key is specified for all the combination items, and the itemContent builder is used to define the rendering content of each combination item; the LazyColumn and the LazyRow have built-in tracking capabilities for the scrolling state, which will track the scrolling position of the list and load more items as needed. When the LazyColumn or the LazyRow scrolls to a certain position, it will calculate which combination items need to be rendered, that is, when the combination items enter the visible area, the LazyColumn or the LazyRow will automatically render the combination items; The reflection call module is also used to set the global theme through the CompositionLocalProvider component; Passing the global theme to the Composable function through the CompositionLocalProvider component; Load the user interface by calling the Composable function of the plug-in through reflection, so as to use the global theme in the user interface; The steps of setting the global theme through the CompositionLocalProvider component include: first, defining a global theme and creating a CompositionLocal object. The CompositionLocal object will be used as a data container to pass theme information in the Compose UI tree; next, creating a CompositionLocalProvider, passing the defined global theme as a parameter to the CompositionLocalProvider, and the CompositionLocalProvider will provide global theme data in the Compose UI tree of the application to ensure that all subcomponents can access the global theme data; secondly, placing the CompositionLocalProvider at the entry point of the application so that no matter how many Composable functions there are in the application, the global theme data can be accessed; finally, using the global theme in the Composable function.

7. An Android plug-in device based on Jetpack Compose, characterized in that: The Android plug-in device implemented based on Jetpack Compose includes: a memory and at least one processor, the memory stores instructions, and the memory and the at least one processor are interconnected through a line; The at least one processor calls the instructions in the memory so that the Android plug-in device implemented based on Jetpack Compose executes the Android plug-in method implemented based on Jetpack Compose as described in any one of claims 1-5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the Android plug-in method based on Jetpack Compose as described in any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • UI style rendering method and device, equipment and storage medium

    CN116610885A