编写插件功能
前提条件
操作步骤
1.
@Bundle
public class MainBundle extends BundleApplication {
... ...
@Override
public void onApplicationCreate(BundleContext context) {
super.onApplicationCreate(context);
this.bundleContext = context; // 该行不要删除
context.getApplication().registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityResumed(@NonNull Activity activity) {
Watermark.show(activity);
}
... ...
});
}
}
2.

3.
@Extension(id = "example_securit_setting", target = "setting_items")
public class ExampleSettingMenu extends EpSettingMenu {
@Override
public SettingMenuObject getMenuObject() {
SettingMenuObject menu = new SettingMenuObject();
menu.title = "演示设置";
return menu;
}
... ...
@Override
public void onClick(View v) {
// 此处可startActivity,打开自定义的Activity
// Demo工程演示效果
Toast.makeText(v.getContext(), "点击自定义设置菜单", Toast.LENGTH_SHORT).show();
}
}
4.

后续步骤
常见问题
1. 开发中的编译问题
1.
<application> <!-- 建议application节点不要添加任何参数-->
<!-- 如果依赖了某个sdk的miniSDKVersion和钉钉不一致,
请配置overrideLibrary属性-->
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="29"
tools:overrideLibrary="com.airbnb.lottie"/>
<meta-data
android:name="example_key"
android:value="example_value" />
<activity
android:name="com.example.DemoActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"/>
</application>
2.
// 建议改为如下形式
<provider
// 此处Provider命名请使用自定义Provider类
android:name="com.example.DemoFileProvider"
android:authorities="com.example.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/example_paths" />
//此处android:resource的文件名命名请注意,避免重复!!!
</provider>
2. so架构引入
3. 外部依赖三方SDK冲突
1.
2.
3.
4. Support库版本适配
androidx.activity:activity:1.1.0@aar
androidx.appcompat:appcompat:1.2.0@aar
androidx.arch.core:core-common:2.1.0@jar
androidx.arch.core:core-runtime:2.1.0@aar
androidx.browser:browser:1.0.0@aar
androidx.cardview:cardview:1.0.0@aar
androidx.constraintlayout:constraintlayout:1.1.3@aar
androidx.coordinatorlayout:coordinatorlayout:1.0.0@aar
androidx.core:core:1.3.2@aar
androidx.customview:customview:1.0.0@aar
androidx.documentfile:documentfile:1.0.0@aar
androidx.drawerlayout:drawerlayout:1.0.0@aar
androidx.exifinterface:exifinterface:1.0.0@aar
androidx.fragment:fragment:1.2.0@aar
androidx.media:media:1.0.0@aar
androidx.palette:palette:1.0.0@aar
androidx.recyclerview:recyclerview:1.0.0@aar
androidx.savedstate:savedstate:1.0.0@aar
androidx.slidingpanelayout:slidingpanelayout:1.0.0@aar
androidx.swiperefreshlayout:swiperefreshlayout:1.0.0@aar
androidx.vectordrawable:vectordrawable:1.1.0@aar
androidx.viewpager:viewpager:1.0.0@aar
androidx.webkit:webkit:1.3.0@aar
androidx.window:window:1.1.0-alpha03@aar
com.alibaba:fastjson:1.1.71.android@jar
com.google.android.material:material:1.0.0@aar
com.google.android.play:core:1.8.3@aar
com.google.android:flexbox:1.0.0@aar
com.google.code.gson:gson:2.2.4@jar
com.google.dagger:dagger:2.23@jar
com.squareup.okhttp3:okhttp:3.11.0@jar
io.reactivex.rxjava2:rxandroid:2.0.2@aar
org.jetbrains.kotlin:kotlin-stdlib:1.7.10@jar
org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1@jar
org.jsoup:jsoup:1.8.2@ja
修改于 2024-01-29 08:36:29