Use common components of mPaaS framework(optional)

更新时间:
复制 MD 格式

When migrating from component-based access mode to native AAR access mode, configure APT-based annotation registration to replace the metainfo.xml entries for your app's mPaaS framework common components.

If your app uses any of the four mPaaS framework common components, follow this guide to configure APT-based annotation registration as a compatibility layer. Skip this page if your app does not use these components.

The four components supported via APT on mPaaS baseline 10.1.60 and later are:

Note

These four components work the same way as in component-based access mode. Click a component name above to see its usage details.

Configure components

  1. Add the following dependencies to both your library and app module projects:

    implementation 'com.mpaas.mobile:metainfo-annotations:1.3.4'
    annotationProcessor 'com.mpaas.mobile:metainfo-compiler:1.3.4' // Java projects
    kapt 'com.mpaas.mobile:metainfo-compiler:1.3.4'                 // Kotlin projects
  2. Add the corresponding annotation to each component class. Four annotation types are available:

    • @Application

    • @Service

    • @BroadcastReceiver

    • @Pipeline

    Each annotation takes the same parameters as the corresponding entry in metainfo.xml. For example, annotate your ActivityApplication subclass with @Application as follows:

    @Application(appId = "123123")
    public class MicroApplication extends ActivityApplication {
    }

When the library module is not used

Add @MetaInfoApplication to any class in your app module. If you also use the easyconfig plugin, enable the plugin compatibility switch:

@MetaInfoApplication(compatibleWithPlugin=true)

When the library module is used

If any of the four components are defined in a library module, perform both steps:

  1. In the library module, add @MetaInfoLibrary to any class and set the parameter to the library module's package name:

    @MetaInfoLibrary(applicationId=BuildConfig.APPLICATION_ID)
  2. In the app module, add @MetaInfoApplication to any class and reference the MetaInfoConfig.java generated by the library module:

    @MetaInfoApplication(dependencies={com.mylibrary.MetaInfoConfig.class})

    If you also use the easyconfig plugin, enable the plugin compatibility switch in the same annotation:

    @MetaInfoApplication(dependencies={com.mylibrary.MetaInfoConfig.class}, compatibleWithPlugin = true)

Obfuscation

Add com.alipay.mobile.core.impl.MetaInfoConfig to your ProGuard allowlist:

-keep public class com.alipay.mobile.core.impl.MetaInfoConfig