Android笔记(二十五):两种sdk热更插件资源加载方案
背景
在研究sdk插件化热更新方式的过程中总结出了两套插件资源加载方案,在此记录下
资源热更方式
方式一:合并所有插件资源
需要解决资源id冲突问题
资源ID值一共4个字段,由三部分组成:PackageId+TypeId+EntryId
- PackageId:是包的Id值,Android 中如果第三方应用的话,这个默认值是 0x7f,系统应用的话就是 0x01 ,插件的话那么就是给插件分配的id值,占用1个字节。
- TypeId:是资源的类型Id值,一般 Android 中有这几个类型:attr,drawable,layout,anim,raw,dimen,string,bool,style,integer,array,color,id,menu 等。【应用程序所有模块中的资源类型名称,按照字母排序之后。值是从1开支逐渐递增的,而且顺序不能改变(每个模块下的R文件的相同资源类型id值相同)。比如:anim=0x01占用1个字节,那么在这个编译出的所有R文件中anim 的值都是 0x01】
- EntryId:是在具体的类型下资源实例的id值,从0开始,依次递增,他占用2个字节。
两种解决方式
- gradle3.5以上可以动态配置aapt的package-id参数修改插件apk的packageId,可在插件模块的build.gradle配置如下:
android {compileSdkVersion 32defaultConfig {applicationId "xxx"minSdkVersion 21targetSdkVersion 32versionCode 1versionName "1.0"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}//为模块定一个唯一的package-id,如0x80aaptOptions {additionalParameters '--allow-reserved-package-id','--package-id', '0x80'}
}
- gradle3.5以下,可以将打包出来的插件apk包进行解包,修改public.xml文件内资源id的package-id,再扫描每一个R$xxx.smali文件,纠正代码中R类的值,与public.xml中的对应,重新打包。
反射替换Application中的mResources字段
注意:在启动service和receiver的时候,会使用application的resource
fun mergePatchResources(application: Application, apkPaths : List<String>) {val newAssetManagerObj = AssetManager::class.java.newInstance()//todo 需要注意这里的addAssetPath被标志为废弃了val addAssetPath = AssetManager::class.java.getMethod("addAssetPath", String::class.java)// 插入宿主的资源addAssetPath.invoke(newAssetManagerObj, application.baseContext.packageResourcePath)// 插入插件的资源apkPaths.forEach {addAssetPath.invoke(newAssetManagerObj, it)}val newResourcesObj = Resources(newAssetManagerObj,application.baseContext.resources.displayMetrics,application.baseContext.resources.configuration)newHoldResources = newResourcesObjval resourcesField = application.baseContext.javaClass.getDeclaredField("mResources")resourcesField.isAccessible = trueresourcesField[application.baseContext] = newResourcesObjval packageInfoField = application.baseContext.javaClass.getDeclaredField("mPackageInfo")packageInfoField.isAccessible = trueval packageInfoObj = packageInfoField[application.baseContext]// 获取 mPackageInfo 变量对象中类的Resources类型的mResources 变量,并替换它的值为新的Resources对象// 注意:这是最主要的需要替换的,如果不需要支持插件运行时更新,只留这一个就可以了val resourcesField2 = packageInfoObj.javaClass.getDeclaredField("mResources")resourcesField2.isAccessible = trueresourcesField2[packageInfoObj] = newResourcesObj// 获取 ContextImpl 中的 Resources.Theme 类型的 mTheme 变量,并至空它// 注意:清理mTheme对象,否则通过inflate方式加载资源会报错, 如果是activity动态加载插件,则需要把activity的mTheme对象也设置为nullval themeField = application.baseContext.javaClass.getDeclaredField("mTheme")themeField.isAccessible = truethemeField[application.baseContext] = null
}
更新Activity的资源
- 监听activity的onCreate回调
((Application)context).registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {@Overridepublic void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {Log.d("zbm111", "doMonitorActivity---onCreate");Resources resources = "含宿主和所有插件资源的完整resource对象"ResHookUtil.monkeyPatchExistingResources(activity, resources);}@Overridepublic void onActivityStarted(@NonNull Activity activity) {}@Overridepublic void onActivityResumed(@NonNull Activity activity) {}@Overridepublic void onActivityPaused(@NonNull Activity activity) {}@Overridepublic void onActivityStopped(@NonNull Activity activity) {}@Overridepublic void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {}@Overridepublic void onActivityDestroyed(@NonNull Activity activity) {}});
- 将要启动的activity反射替换mResources字段
public static void monkeyPatchExistingResources(Activity activity, Resources newResources) {try {Class<?> contextThemeWrapperClass = null;try {contextThemeWrapperClass = Class.forName("android.view.ContextThemeWrapper");} catch (ClassNotFoundException e) {e.printStackTrace();}// 反射获取 ContextThemeWrapper 类的 mResources 字段Field mResourcesField = null;try {mResourcesField = contextThemeWrapperClass.getDeclaredField("mResources");} catch (NoSuchFieldException e) {e.printStackTrace();}// 设置字段可见性mResourcesField.setAccessible(true);// 将插件资源设置到插件 Activity 中try {mResourcesField.set(activity, newResources);} catch (IllegalAccessException e) {e.printStackTrace();}Method mTheme = contextThemeWrapperClass.getDeclaredMethod("setTheme", Resources.Theme.class);mTheme.setAccessible(true);mTheme.invoke(activity, (Object) null);} catch (Exception e) {e.printStackTrace();}}
方式二:封装含插件资源的Resource对象
注意:插件apk的包名须与宿主的包名保持一致
需要解决资源id冲突问题
参考方式一,可以通过修改type id与宿主区分开
hook ActivityThread的handler设置callback
- 给ActivityThread中mH(Hander类型)对象的mCallback字段设置一个代理对象ProxyHandlerCallback
public static void doHandlerHook(Context context) {try {HookUtils.context = context;Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");Method currentActivityThread = activityThreadClass.getDeclaredMethod("currentActivityThread");Object activityThread = currentActivityThread.invoke(null);Field mHField = activityThreadClass.getDeclaredField("mH");mHField.setAccessible(true);Handler mH = (Handler) mHField.get(activityThread);Field mCallbackField = Handler.class.getDeclaredField("mCallback");mCallbackField.setAccessible(true);mCallbackField.set(mH, new ProxyHandlerCallback(mH));} catch (Exception e) {e.printStackTrace();}}
- 系统启动service前,进行拦截,将ActivityThread的mPackages新增一个service的LoadedApk,该LoadedApk的mResources字段替换为含插件+宿主资源的SingleMixRes对象;
系统启动receiver前,进行拦截,将application的mResources字段替换为含插件+宿主资源的SingleMixRes对象。
public class ProxyHandlerCallback implements Handler.Callback {private Handler mBaseHandler;private Map<String, String> mPathToPluginNameMap = new HashMap<>();public ProxyHandlerCallback(Handler mBaseHandler) {this.mBaseHandler = mBaseHandler;}@Overridepublic boolean handleMessage(Message msg) {Log.d("zbm111", "接受到消息了msg:" + msg);if (msg.what == 113){//启动receiver的时候走这里try {Object object = msg.obj;Field infoField = object.getClass().getDeclaredField("info");infoField.setAccessible(true);ActivityInfo activityInfo = (ActivityInfo) infoField.get(object);String hostReceiverName = activityInfo.name;Resources resources = "含插件+宿主资源的SingleMixRes对象";Field resourcesField = ((Application)HookUtils.getContext()).getBaseContext().getClass().getDeclaredField("mResources");resourcesField.setAccessible(true);resourcesField.set(((Application)HookUtils.getContext()).getBaseContext(), resources);}catch (Exception e){Log.e("zbm111", "handle create receiver failed");}} else if (msg.what == 114) {//启动service的时候走这里try {Object object = msg.obj;Field infoField = object.getClass().getDeclaredField("info");infoField.setAccessible(true);ServiceInfo serviceInfo = (ServiceInfo) infoField.get(object);String hostServiceName = serviceInfo.name;String path = "插件apk本地存储路径"//todo dex热修复必须同时进行资源热更if (path != null) {replaceLoadApk(hostServiceName, path, false);Log.i("zbm111", "replaced to plugin service success");}} catch (Exception e) {Log.e("zbm111", "handle create service failed");}}mBaseHandler.handleMessage(msg);return true;}private void replaceLoadApk(String componentName, String path, boolean isUseActivity) throws Exception {Log.i("zbm111", "start replaceLoadApk");Field activityThreadField = Class.forName("android.app.ActivityThread").getDeclaredField("sCurrentActivityThread");activityThreadField.setAccessible(true);Object sCurrentActivityThread = activityThreadField.get(null);Field mPackagesField = sCurrentActivityThread.getClass().getDeclaredField("mPackages");mPackagesField.setAccessible(true);ArrayMap mPackages = (ArrayMap) mPackagesField.get(sCurrentActivityThread);if (null == mPackages) {Log.i("zbm111", "can not get mPackages");return;}ApplicationInfo applicationInfo = generateApplicationInfo(path);if (null != applicationInfo) {Field compatibilityInfoField = Class.forName("android.content.res.CompatibilityInfo").getDeclaredField("DEFAULT_COMPATIBILITY_INFO");compatibilityInfoField.setAccessible(true);Object defaultCompatibilityInfo = compatibilityInfoField.get(null);Object loadedApk;if (isUseActivity){Method getPackageInfoMethod = sCurrentActivityThread.getClass().getDeclaredMethod("getPackageInfo", ApplicationInfo.class, Class.forName("android.content.res.CompatibilityInfo"), int.class);getPackageInfoMethod.setAccessible(true);loadedApk = getPackageInfoMethod.invoke(sCurrentActivityThread, applicationInfo, defaultCompatibilityInfo, Context.CONTEXT_INCLUDE_CODE);}else {Method getPackageInfoMethod = sCurrentActivityThread.getClass().getDeclaredMethod("getPackageInfoNoCheck", ApplicationInfo.class, Class.forName("android.content.res.CompatibilityInfo"));getPackageInfoMethod.setAccessible(true);loadedApk = getPackageInfoMethod.invoke(sCurrentActivityThread, applicationInfo, defaultCompatibilityInfo);}String pluginName = applicationInfo.packageName;if (!TextUtils.isEmpty(pluginName)) {Log.i("zbm111", "plugin pkg name is " + pluginName);Resources resources = "含插件+宿主资源的SingleMixRes对象";setResource(loadedApk, resources);mPackages.put(pluginName, new WeakReference<>(loadedApk));mPackagesField.set(sCurrentActivityThread, mPackages);mPathToPluginNameMap.put(path, pluginName);} else {Log.i("zbm111", "get plugin pkg name failed");}} else {Log.i("zbm111", "can not get application info");}}private void setResource(Object loadedApk, Resources resources) throws Exception{Field mResourcesField = loadedApk.getClass().getDeclaredField("mResources");mResourcesField.setAccessible(true);mResourcesField.set(loadedApk, resources);}public ApplicationInfo generateApplicationInfo(String pluginPath) {try {ApplicationInfo applicationInfo = getApplicationInfoByPackageArchiveInfo(pluginPath);if (null == applicationInfo) {LogUtil.i("zbm111", "get applicationInfo failed");return null;}applicationInfo.sourceDir = pluginPath;applicationInfo.publicSourceDir = pluginPath;return applicationInfo;} catch (Exception e) {LogUtil.i("zbm111", "generateApplicationzInfo failed " + e.getMessage());}return null;}private ApplicationInfo getApplicationInfoByPackageArchiveInfo(String pluginPath) {PackageManager packageManager = HookUtils.getContext().getPackageManager();if (null == packageManager) {LogUtil.i("zbm111", "get PackageManager failed");return null;}PackageInfo packageInfo = packageManager.getPackageArchiveInfo(pluginPath, 0);if (null == packageInfo) {LogUtil.i("zbm111", "get packageInfo failed");return null;}return packageInfo.applicationInfo;}
}
- 自定义ResourcesWrapper
public class ResourcesWrapper extends Resources {private Resources mBase;public ResourcesWrapper(Resources base){super(base.getAssets(),base.getDisplayMetrics(),base.getConfiguration());mBase = base;}@Overridepublic CharSequence getText(int id) throws NotFoundException {return mBase.getText(id);}@TargetApi(Build.VERSION_CODES.O)@Overridepublic Typeface getFont(int id) throws NotFoundException {return mBase.getFont(id);}@Overridepublic CharSequence getQuantityText(int id, int quantity) throws NotFoundException {return mBase.getQuantityText(id, quantity);}@Overridepublic String getString(int id) throws NotFoundException {return mBase.getString(id);}@Overridepublic String getString(int id, Object... formatArgs) throws NotFoundException {return mBase.getString(id, formatArgs);}@Overridepublic String getQuantityString(int id, int quantity, Object... formatArgs) throws NotFoundException {return mBase.getQuantityString(id, quantity, formatArgs);}@Overridepublic String getQuantityString(int id, int quantity) throws NotFoundException {return mBase.getQuantityString(id, quantity);}@Overridepublic CharSequence getText(int id, CharSequence def) {return mBase.getText(id, def);}@Overridepublic CharSequence[] getTextArray(int id) throws NotFoundException {return mBase.getTextArray(id);}@Overridepublic String[] getStringArray(int id) throws NotFoundException {return mBase.getStringArray(id);}@Overridepublic int[] getIntArray(int id) throws NotFoundException {return mBase.getIntArray(id);}@Overridepublic TypedArray obtainTypedArray(int id) throws NotFoundException {return mBase.obtainTypedArray(id);}@Overridepublic float getDimension(int id) throws NotFoundException {return mBase.getDimension(id);}@Overridepublic int getDimensionPixelOffset(int id) throws NotFoundException {return mBase.getDimensionPixelOffset(id);}@Overridepublic int getDimensionPixelSize(int id) throws NotFoundException {return mBase.getDimensionPixelSize(id);}@Overridepublic float getFraction(int id, int base, int pbase) {return mBase.getFraction(id, base, pbase);}@Overridepublic Drawable getDrawable(int id) throws NotFoundException {return mBase.getDrawable(id);}@TargetApi(Build.VERSION_CODES.LOLLIPOP)@Overridepublic Drawable getDrawable(int id, Theme theme) throws NotFoundException {return mBase.getDrawable(id, theme);}@Overridepublic Drawable getDrawableForDensity(int id, int density) throws NotFoundException {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {return mBase.getDrawableForDensity(id, density);} else {return null;}}@TargetApi(Build.VERSION_CODES.LOLLIPOP)@Overridepublic Drawable getDrawableForDensity(int id, int density, Theme theme) {return mBase.getDrawableForDensity(id, density, theme);}@Overridepublic Movie getMovie(int id) throws NotFoundException {return mBase.getMovie(id);}@Overridepublic int getColor(int id) throws NotFoundException {return mBase.getColor(id);}@TargetApi(Build.VERSION_CODES.M)@Overridepublic int getColor(int id, Theme theme) throws NotFoundException {return mBase.getColor(id, theme);}@Overridepublic ColorStateList getColorStateList(int id) throws NotFoundException {return mBase.getColorStateList(id);}@TargetApi(Build.VERSION_CODES.M)@Overridepublic ColorStateList getColorStateList(int id, Theme theme) throws NotFoundException {return mBase.getColorStateList(id, theme);}@Overridepublic boolean getBoolean(int id) throws NotFoundException {return mBase.getBoolean(id);}@Overridepublic int getInteger(int id) throws NotFoundException {return mBase.getInteger(id);}@Overridepublic XmlResourceParser getLayout(int id) throws NotFoundException {return mBase.getLayout(id);}@Overridepublic XmlResourceParser getAnimation(int id) throws NotFoundException {return mBase.getAnimation(id);}@Overridepublic XmlResourceParser getXml(int id) throws NotFoundException {return mBase.getXml(id);}@Overridepublic InputStream openRawResource(int id) throws NotFoundException {return mBase.openRawResource(id);}@Overridepublic InputStream openRawResource(int id, TypedValue value) throws NotFoundException {return mBase.openRawResource(id, value);}@Overridepublic AssetFileDescriptor openRawResourceFd(int id) throws NotFoundException {return mBase.openRawResourceFd(id);}@Overridepublic void getValue(int id, TypedValue outValue, boolean resolveRefs) throws NotFoundException {mBase.getValue(id, outValue, resolveRefs);}@Overridepublic void getValueForDensity(int id, int density, TypedValue outValue, boolean resolveRefs) throws NotFoundException {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {mBase.getValueForDensity(id, density, outValue, resolveRefs);}}@Overridepublic void getValue(String name, TypedValue outValue, boolean resolveRefs) throws NotFoundException {mBase.getValue(name, outValue, resolveRefs);}@Overridepublic TypedArray obtainAttributes(AttributeSet set, int[] attrs) {return mBase.obtainAttributes(set, attrs);}@Overridepublic DisplayMetrics getDisplayMetrics() {return mBase.getDisplayMetrics();}@Overridepublic Configuration getConfiguration() {return mBase.getConfiguration();}@Overridepublic int getIdentifier(String name, String defType, String defPackage) {return mBase.getIdentifier(name, defType, defPackage);}@Overridepublic String getResourceName(int resid) throws NotFoundException {return mBase.getResourceName(resid);}@Overridepublic String getResourcePackageName(int resid) throws NotFoundException {return mBase.getResourcePackageName(resid);}@Overridepublic String getResourceTypeName(int resid) throws NotFoundException {return mBase.getResourceTypeName(resid);}@Overridepublic String getResourceEntryName(int resid) throws NotFoundException {return mBase.getResourceEntryName(resid);}@Overridepublic void parseBundleExtras(XmlResourceParser parser, Bundle outBundle) throws XmlPullParserException, IOException {mBase.parseBundleExtras(parser, outBundle);}@Overridepublic void parseBundleExtra(String tagName, AttributeSet attrs, Bundle outBundle) throws XmlPullParserException {mBase.parseBundleExtra(tagName, attrs, outBundle);}
}
- SingleMixRes优先从插件加载资源,找不到则从宿主加载资源
public class SingleMixRes extends ResourcesWrapper{private Resources mHostResources;public SingleMixRes(Resources hostResources, Resources pluginResources) {super(pluginResources);mHostResources = hostResources;}@Overridepublic CharSequence getText(int id) throws NotFoundException {try {return super.getText(id);} catch (NotFoundException e) {return mHostResources.getText(id);}}@Overridepublic String getString(int id) throws NotFoundException {try {return super.getString(id);} catch (NotFoundException e) {return mHostResources.getString(id);}}@Overridepublic String getString(int id, Object... formatArgs) throws NotFoundException {try {return super.getString(id,formatArgs);} catch (NotFoundException e) {return mHostResources.getString(id,formatArgs);}}@Overridepublic float getDimension(int id) throws NotFoundException {try {return super.getDimension(id);} catch (NotFoundException e) {return mHostResources.getDimension(id);}}@Overridepublic int getDimensionPixelOffset(int id) throws NotFoundException {try {return super.getDimensionPixelOffset(id);} catch (NotFoundException e) {return mHostResources.getDimensionPixelOffset(id);}}@Overridepublic int getDimensionPixelSize(int id) throws NotFoundException {try {return super.getDimensionPixelSize(id);} catch (NotFoundException e) {return mHostResources.getDimensionPixelSize(id);}}@Overridepublic Drawable getDrawable(int id) throws NotFoundException {try {return super.getDrawable(id);} catch (NotFoundException e) {return mHostResources.getDrawable(id);}}@TargetApi(Build.VERSION_CODES.LOLLIPOP)@Overridepublic Drawable getDrawable(int id, Theme theme) throws NotFoundException {try {return super.getDrawable(id, theme);} catch (NotFoundException e) {return mHostResources.getDrawable(id,theme);}}@Overridepublic Drawable getDrawableForDensity(int id, int density) throws NotFoundException {try {return super.getDrawableForDensity(id, density);} catch (NotFoundException e) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {return mHostResources.getDrawableForDensity(id, density);} else {return null;}}}@TargetApi(Build.VERSION_CODES.LOLLIPOP)@Overridepublic Drawable getDrawableForDensity(int id, int density, Theme theme) {try {return super.getDrawableForDensity(id, density, theme);} catch (Exception e) {return mHostResources.getDrawableForDensity(id,density,theme);}}@Overridepublic int getColor(int id) throws NotFoundException {try {return super.getColor(id);} catch (NotFoundException e) {return mHostResources.getColor(id);}}@TargetApi(Build.VERSION_CODES.M)@Overridepublic int getColor(int id, Theme theme) throws NotFoundException {try {return super.getColor(id,theme);} catch (NotFoundException e) {return mHostResources.getColor(id,theme);}}@Overridepublic ColorStateList getColorStateList(int id) throws NotFoundException {try {return super.getColorStateList(id);} catch (NotFoundException e) {return mHostResources.getColorStateList(id);}}@TargetApi(Build.VERSION_CODES.M)@Overridepublic ColorStateList getColorStateList(int id, Theme theme) throws NotFoundException {try {return super.getColorStateList(id,theme);} catch (NotFoundException e) {return mHostResources.getColorStateList(id,theme);}}@Overridepublic boolean getBoolean(int id) throws NotFoundException {try {return super.getBoolean(id);} catch (NotFoundException e) {return mHostResources.getBoolean(id);}}@Overridepublic XmlResourceParser getLayout(int id) throws NotFoundException {try {return super.getLayout(id);} catch (NotFoundException e) {return mHostResources.getLayout(id);}}@Overridepublic String getResourceName(int resid) throws NotFoundException {try {return super.getResourceName(resid);} catch (NotFoundException e) {return mHostResources.getResourceName(resid);}}@Overridepublic int getInteger(int id) throws NotFoundException {try {return super.getInteger(id);} catch (NotFoundException e) {return mHostResources.getInteger(id);}}@Overridepublic CharSequence getText(int id, CharSequence def) {try {return super.getText(id,def);} catch (NotFoundException e) {return mHostResources.getText(id,def);}}@Overridepublic InputStream openRawResource(int id) throws NotFoundException {try {return super.openRawResource(id);} catch (NotFoundException e) {return mHostResources.openRawResource(id);}}@Overridepublic XmlResourceParser getXml(int id) throws NotFoundException {try {return super.getXml(id);} catch (NotFoundException e) {return mHostResources.getXml(id);}}@TargetApi(Build.VERSION_CODES.O)@Overridepublic Typeface getFont(int id) throws NotFoundException {try {return super.getFont(id);} catch (NotFoundException e) {return mHostResources.getFont(id);}}@Overridepublic Movie getMovie(int id) throws NotFoundException {try {return super.getMovie(id);} catch (NotFoundException e) {return mHostResources.getMovie(id);}}@Overridepublic XmlResourceParser getAnimation(int id) throws NotFoundException {try {return super.getAnimation(id);} catch (NotFoundException e) {return mHostResources.getAnimation(id);}}@Overridepublic InputStream openRawResource(int id, TypedValue value) throws NotFoundException {try {return super.openRawResource(id,value);} catch (NotFoundException e) {return mHostResources.openRawResource(id,value);}}@Overridepublic AssetFileDescriptor openRawResourceFd(int id) throws NotFoundException {try {return super.openRawResourceFd(id);} catch (NotFoundException e) {return mHostResources.openRawResourceFd(id);}}
}
更新Activity的资源
参考方式一
两种方式注意事项
- 打包出的插件apk需要去除第三方smali代码,否则可能会报资源问题
- 代码更新与资源更新最好同步,预防id对应不上
附录
修改资源id冲突及去除第三方smali文件工具
相关文章:

Android笔记(二十五):两种sdk热更插件资源加载方案
背景 在研究sdk插件化热更新方式的过程中总结出了两套插件资源加载方案,在此记录下 资源热更方式 方式一:合并所有插件资源 需要解决资源id冲突问题 资源ID值一共4个字段,由三部分组成:PackageIdTypeIdEntryId PackageId&…...

spring框架--全面详解(学习笔记)
目录 1.Spring是什么 2.Spring 框架特点 3.Spring体系结构 4.Spring开发环境搭建 5.spring中IOC和DI 6.Spring中bean的生命周期 7.Spring Bean作用域 8.spring注解开发 9.Spring框架中AOP(Aspect Oriented Programming) 10.AOP 实现分类 11.A…...
2023年CDGA考试模拟题库(401-500)
2023年CDGA考试模拟题库(401-500) 401.数据管理战略的SMART原则指的是哪项? [1分] A.具体 、高质量、可操作 、现实、有时间限制 B.具体、可衡量、可检验、现实、有时间限制 C.具体、可衡量、可操作、现实、有时间限制 D.具体、高质量、可检验、现实12-24个月的目标 答…...
软件设计师备考文档
cpu 计算机的基本硬件系统:运算器、控制器、存储器、输入设备、输出设备 cpu负责获取程序指令,对指令进行译码并加以执行 * cpu的功能控制器(保证程序正常执行,处理异常事件) 程序控制操作控制运算器(只能…...
Javascript的API基本内容(一)
一、获取DOM对象 querySelector 满足条件的第一个元素 querySelectorAll 满足条件的元素集合 返回伪数组 document.getElementById 专门获取元素类型节点,根据标签的 id 属性查找 二、操作元素内容 通过修改 DOM 的文本内容,动态改变网页的内容。 inn…...
10、最小公倍数
法一: #include <stdio.h>int main(){int a,b;scanf("%d%d",&a,&b);int m a>b?a:b;//m表示a,b之间的较大值while(1){if(m%a0&&m%b0){break;}m;}printf("%d",m);return 0; }法二:a*i%b0成立 #include &…...
【vue】vue2.x项目中使用md文件
一、Vue项目展示md文件的三种方式 1、将md文件 导入为 html 生成的标题标签自带具有id属性,值为标题内容; <h2 id"测试">测试</h2> # 处理md为html字符串 yarn add markdown-loader # 处理字符串,用于导出显示 yarn a…...

操作系统权限提升(十三)之绕过UAC提权-MSF和CS绕过UAC提权
系列文章 操作系统权限提升(十二)之绕过UAC提权-Windows UAC概述 注:阅读本编文章前,请先阅读系列文章,以免造成看不懂的情况!! MSF和CS绕过UAC提权 CS绕过UAC提权 拿到一个普通管理员的SHELL,在CS中没有*号代表有…...
快速排序+快速定位
快速排序算法采用了分治法以及递归作为解决问题的思想。在计算机科学中,分治法是一种很重要的算法。字面上的解释是“分而治之”,就是把一个复杂的问题分成两个或更多的相同或相似的子问题,再把子问题分成更小的子问题……直到最后子问题可以…...
nginx http rewrite module 详解
大家好,我是 17。 今天和大家聊聊 nginx http rewrite module 。 简单来说, ngx_http_rewrite_module module 用正则匹配请求,改写请求,然后做跳转。可以是内部跳转,也可以是外部跳转。 学习这个模块的时候…...

机器学习可解释性一(LIME)
随着深度学习的发展,越来越多的模型诞生,并且在训练集和测试集上的表现甚至于高于人类,但是深度学习一直被认为是一个黑盒模型,我们通俗的认为,经过训练后,机器学习到了数据中的特征,进而可以正…...

CV学习笔记-MobileNet
MobileNet 文章目录MobileNet1. MobileNet概述2. 深度可分离卷积(depthwise separable convolution)2.1 深度可分离卷积通俗理解2.2 深度可分离卷积对于参数的优化3. MobileNet网络结构4. 代码实现4.1 卷积块4.2 深度可分离卷积块4.3 MobileNet定义4.4 完…...

C++进阶——继承
C进阶——继承 1.继承的概念及定义 面向对象三大特性:封装、继承、多态。 概念: 继承(inheritance)机制是面向对象程序设计使代码可以复用的最重要的手段,它允许程序员在保持原有类特 性的基础上进行扩展,增加功能,这…...

数据结构---单链表
专栏:数据结构 个人主页:HaiFan. 专栏简介:从零开始,数据结构!! 单链表前言顺序表的缺陷链表的概念以及结构链表接口实现打印链表中的元素SLTPrintphead->next!NULL和phead!NULL的区别开辟空间SLTNewNod…...

redis数据结构的底层实现
文章目录一.引言二.redis的特点三.Redis的数据结构a.字符串b.hashc.listd.sete.zset(有序集合)一.引言 redis是一个开源的使用C语言编写、支持网络、可基于内存亦可持久化的日志型、key-value的NoSQL数据库。 通常使用redis作为缓存中间件来降低数据库的压力,除此…...

【JavaSE】复习(进阶)
文章目录1.final关键字2.常量3.抽象类3.1概括3.2 抽象方法4. 接口4.1 接口在开发中的作用4.2类型和类型之间的关系4.3抽象类和接口的区别5.包机制和import5.1 包机制5.2 import6.访问控制权限7.Object7.1 toString()7.2 equals()7.3 String类重写了toString和equals8.内部类8.1…...
Java 主流日志工具库
日志系统 java.util.logging (JUL) JDK1.4 开始,通过 java.util.logging 提供日志功能。虽然是官方自带的log lib,JUL的使用确不广泛。 JUL从JDK1.4 才开始加入(2002年),当时各种第三方log lib已经被广泛使用了JUL早期存在性能问题&#x…...

产品经理有必要考个 PMP吗?(含PMP资料)
现在基本上做产品的都有一个PMP证件,从结果导向来说,不对口不会有这么大范围的人来考,但是需要因地制宜,在公司内部里,标准程序并不流畅,产品和项目并不规范,关系错综复杂。 而产品经理的职能又…...

什么是原型、原型链?原型和原型链的作用
1、ES6之前,继承都用构造函数来实现;对象的继承,先申明一个对象,里面添加实例成员<!DOCTYPE html> <html><head><meta charset"utf-8" /><title></title></head><body><script…...
条件期望4
条件期望例题----快排算法的分析 快速排序算法的递归定义如下: 有n个数(n≥2n\geq 2n≥2), 一开始随机选取一个数xix_ixi, 并将xix_ixi和其他n-1个数进行比较, 记SiS_iSi为比xix_ixi小的元素构成的集合, Siˉ\bar{S_i}Siˉ为比xix_ixi大的元素构成的集合, 然后分…...

docker详细操作--未完待续
docker介绍 docker官网: Docker:加速容器应用程序开发 harbor官网:Harbor - Harbor 中文 使用docker加速器: Docker镜像极速下载服务 - 毫秒镜像 是什么 Docker 是一种开源的容器化平台,用于将应用程序及其依赖项(如库、运行时环…...

中南大学无人机智能体的全面评估!BEDI:用于评估无人机上具身智能体的综合性基准测试
作者:Mingning Guo, Mengwei Wu, Jiarun He, Shaoxian Li, Haifeng Li, Chao Tao单位:中南大学地球科学与信息物理学院论文标题:BEDI: A Comprehensive Benchmark for Evaluating Embodied Agents on UAVs论文链接:https://arxiv.…...

Swift 协议扩展精进之路:解决 CoreData 托管实体子类的类型不匹配问题(下)
概述 在 Swift 开发语言中,各位秃头小码农们可以充分利用语法本身所带来的便利去劈荆斩棘。我们还可以恣意利用泛型、协议关联类型和协议扩展来进一步简化和优化我们复杂的代码需求。 不过,在涉及到多个子类派生于基类进行多态模拟的场景下,…...

从零实现STL哈希容器:unordered_map/unordered_set封装详解
本篇文章是对C学习的STL哈希容器自主实现部分的学习分享 希望也能为你带来些帮助~ 那咱们废话不多说,直接开始吧! 一、源码结构分析 1. SGISTL30实现剖析 // hash_set核心结构 template <class Value, class HashFcn, ...> class hash_set {ty…...
WEB3全栈开发——面试专业技能点P2智能合约开发(Solidity)
一、Solidity合约开发 下面是 Solidity 合约开发 的概念、代码示例及讲解,适合用作学习或写简历项目背景说明。 🧠 一、概念简介:Solidity 合约开发 Solidity 是一种专门为 以太坊(Ethereum)平台编写智能合约的高级编…...

深入浅出深度学习基础:从感知机到全连接神经网络的核心原理与应用
文章目录 前言一、感知机 (Perceptron)1.1 基础介绍1.1.1 感知机是什么?1.1.2 感知机的工作原理 1.2 感知机的简单应用:基本逻辑门1.2.1 逻辑与 (Logic AND)1.2.2 逻辑或 (Logic OR)1.2.3 逻辑与非 (Logic NAND) 1.3 感知机的实现1.3.1 简单实现 (基于阈…...
MySQL 8.0 事务全面讲解
以下是一个结合两次回答的 MySQL 8.0 事务全面讲解,涵盖了事务的核心概念、操作示例、失败回滚、隔离级别、事务性 DDL 和 XA 事务等内容,并修正了查看隔离级别的命令。 MySQL 8.0 事务全面讲解 一、事务的核心概念(ACID) 事务是…...

WPF八大法则:告别模态窗口卡顿
⚙️ 核心问题:阻塞式模态窗口的缺陷 原始代码中ShowDialog()会阻塞UI线程,导致后续逻辑无法执行: var result modalWindow.ShowDialog(); // 线程阻塞 ProcessResult(result); // 必须等待窗口关闭根本问题:…...

【Linux手册】探秘系统世界:从用户交互到硬件底层的全链路工作之旅
目录 前言 操作系统与驱动程序 是什么,为什么 怎么做 system call 用户操作接口 总结 前言 日常生活中,我们在使用电子设备时,我们所输入执行的每一条指令最终大多都会作用到硬件上,比如下载一款软件最终会下载到硬盘上&am…...
git: early EOF
macOS报错: Initialized empty Git repository in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/ remote: Enumerating objects: 2691797, done. remote: Counting objects: 100% (1760/1760), done. remote: Compressing objects: 100% (636/636…...