lib无需在App进行初始化无需依赖自动初始化
导入初始化器依赖
implementation 'androidx.startup:startup-runtime:1.0.0-alpha01'在lib清单列表中注册该初始化器
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.angle.mvplib"> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <application> <provider android:name="androidx.startup.InitializationProvider" android:authorities="${applicationId}.androidx-startup" android:exported="false" tools:node="merge"> <meta-data android:name="com.angle.mvplib.MvpInitializer" android:value="androidx.startup" /> </provider> </application> </manifest>实现初始化接口
public class MvpInitializer implements Initializer<Void> { @NonNull @Override public Void create(@NonNull Context context) { //在这进行初始化 MvpManager.init(context); return null; } @NonNull @Override public List<Class<? extends Initializer<?>>> dependencies() { return new ArrayList<>(); } }