As games become increasingly complex, a loading bar is no longer just a countdown to an adventure, but a messenger that connects the player to the developer.

Players always want the game to load immediately, which means that “loading” has its own priorities: resources that will be used in the first few minutes of the game need to be packed into the APK, and everything else can be downloaded in the background after the player starts the game.

The business always wants a lot of new twists in the game, which means that variation itself has become the norm: different holidays require different screens and themes, and even the look and feel of the game has to be like, “Oh, it’s a big day, too.”

Zhuomeng’s le Change Game subcontracting service helps game developers meet players’ needs by dynamically downloading and inserting new resources during game loading and running.

Netease’s “legend of the Meteor Group Of Heroes”, Longyuan’s “many since chess”, purple dragon’s “dream simulation war”, swim of the “young three kingdoms 2″…… And many other manufacturers of the game, to bring players experience is also different. But they all have one thing in common: they all use Zhuomeng’s Game subcontracting service to dynamically load resources.

Even Zhuomin itself needs to use dynamic loading resources to provide a better development experience for users of its OWN SDKS, namely game manufacturers. Such as making SDK integration as easy as possible, and providing quick fixes when adjustments are made to SDK internal resources without requiring developers to update the SDK.

Before Android 11 provided the ResourcesLoader interface, it wasn’t easy to create a dynamic resource loading process.

The old solution

When Zhuomin started building its product, Android did not expose use cases for interface support for dynamic resource loading. The team did its best, eventually adding external resources using a non-public interface. While this implementation meets the technical requirements, it is very fragile — it relies on non-public interfaces that have far lower compatibility guarantees than the official public SDKS and can be changed or removed at any time without prior notice.

The company has found that compatibility issues crop up unexpectedly with each new release of Android. These require additional testing and development to ensure the stability of the product. It took the team six engineer * months and a lot of code to stabilize the solution after several iterations, with the understanding that it would break again in the next Android release. As Android strictly limits the use of non-public interfaces to improve stability and compatibility, Zomonot needs to remove its dependence on those non-public interfaces.

Sustainable solutions

As the Android system team focuses more and more on helping apps migrate to public interfaces, Zomm sees the light at the end of the tunnel. They contacted the Android team to provide feedback on their specific use cases and detailed requirements for the exposed interface.

After a lot of communication and ongoing collaboration, Android 11 released the first public interface to support dynamic resource loading. Zhuomo technologies has migrated to the new ResourcesLoader interface and has seen significant productivity and product quality improvements. Zhuobeng technology believes that the ResourcesLoader interface has the following advantages:

  • Simple to use. The development team switched from the existing solution to the new one and tested it in two days.
  • Nondestructive performance. There is no reduction (or even improvement in some scenarios, because some of the resources in the package are compressed, while resources added through ResourcesLoader are non-compressed) compared to directly built-in resources in the package.
  • Development efficiency. The previous scheme requires senior engineers to first understand the principle of AssetManager, find the corresponding private interface and its implementation details in each system version; You also need to understand zip file structure and other technical details unrelated to Android development. With the new public interface, a junior engineer who can read the documentation can easily cope.
  • Simple maintenance. The previous solution accumulated more than 1,000 lines of code to be compatible, but the new solution is just a few lines!
  • Forward compatibility. By using the public interface supported by Android, developers’ solutions will be more compatible on the Android platform in the future.
String sdkroot = getApplicationInfo().dataDir + "/lebian";
ResourcesLoader rl = new ResourcesLoader();
rl.addProvider(ResourcesProvider.loadFromDirectory(sdkroot, null));
Resources res = getResources();
res.addLoaders(rl);
final AssetManager assetManager = res.getAssets();
Copy the code

After using the ResourcesLoader API, only a few lines of core code are required

Performance improvement

Zhuomeng Technology took 16,028 files (total size 1.47GB, compressed 1.36GB) as an example and tested them using four loading schemes:

  • Read directly from APK
  • Load the directory and read it using some private interface
  • Load the APK using the ResourcesLoader interface and then read it
  • Use the ResourcesLoader interface to load the directory and then read it

The first three schemes compress resource files, and the average load time is about 19 seconds. In scheme 4, load directories through ResourcesLoader and read uncompressed resources directly. The average load time is only about 3 seconds, and the performance is improved by 6 times.

“The new ResourcesLoader interface significantly reduces development and maintenance costs, enabling us to focus more on product and business innovation,” said Mr. Hogg Huang, CEO and product leader of Zhuobeng Technology.

Hold a paintbrush, draw a fine picture

△ Zhuomeng Technology Team

“We have developed valuable products and services that support our continued commitment to developing innovative products on Android.” “We look forward to more opportunities to participate in the development of the Android ecosystem and contribute to making Android more accessible to consumers and easier for developers,” The company said.

Zhuomeng technology is committed to improving the long-term compatibility of its solutions. Migrating to the ResourcesLoader public interface improves stability and performance, simplifies code complexity, and reduces future compatibility risks on Android systems. More importantly, because ResourcesLoader is an open interface in Android 11, the entire Android developer community can leverage it to make money.

As always, the Android team values developer feedback and creativity. The birth of dynamic resource loading interface is inseparable from the support and cooperation of developers. We look forward to seeing more developers follow zhuomin’s lead in creating creativity, value, and success in the Android ecosystem, as well as helping Make Android a great platform for developers and users alike.