1# 包管理子系统ChangeLog 2 3## cl.bundlemanager.1 包管理NDK结构体OH_NativeBundle_ApplicationInfo新增appId和appIdentifier字段,需手动释放。 4 5**访问级别** 6 7公开接口 8 9**变更原因** 10 11结构体[OH_NativeBundle_ApplicationInfo](../../../application-dev/reference/native-apis/_o_h___native_bundle_application_info.md)新增appId和appIdentifier字段。 12 13**变更影响** 14 15如果使用API 11及以上的开发的Native应用,如果不手动释放结构体OH_NativeBundle_ApplicationInfo中的appId和appIdentifier字段,会造成内存泄漏。如果使用API 11之前的开发的native应用,则无需适配。 16 17**变更发生版本** 18 19从OpenHarmony SDK 4.1.3.2开始 20 21**变更的接口/组件** 22 23应用调用包管理NDK接口[OH_NativeBundle_GetCurrentApplicationInfo](../../../application-dev/reference/native-apis/native__interface__bundle.md#oh_nativebundle_getcurrentapplicationinfo)查询应用自身信息。 24 25**适配指导** 26 27应用若是使用API 11及以上的版本开发的Native应用,则需要在代码里手动释放appId和appIdentifier申请的内存。 28 29示例代码 30 31 ```c++ 32 static napi_value GetCurrentApplicationInfo(napi_env env, napi_callback_info info) 33 { 34 // 调用Native接口获取应用信息 35 OH_NativeBundle_ApplicationInfo nativeApplicationInfo = OH_NativeBundle_GetCurrentApplicationInfo(); 36 napi_value result = nullptr; 37 napi_create_object(env, &result); 38 // Native接口获取的应用包名转为js对象里的bundleName属性 39 napi_value bundleName; 40 napi_create_string_utf8(env, nativeApplicationInfo.bundleName, NAPI_AUTO_LENGTH, &bundleName); 41 napi_set_named_property(env, result, "bundleName", bundleName); 42 // Native接口获取的指纹信息转为js对象里的fingerprint属性 43 napi_value fingerprint; 44 napi_create_string_utf8(env, nativeApplicationInfo.fingerprint, NAPI_AUTO_LENGTH, &fingerprint); 45 napi_set_named_property(env, result, "fingerprint", fingerprint); 46 47 char* appId = OH_NativeBundle_GetAppId(); 48 // Native接口获取的appId转为js对象里的appId属性 49 napi_value napi_appId; 50 napi_create_string_utf8(env, appId, NAPI_AUTO_LENGTH, &napi_appId); 51 napi_set_named_property(env, result, "appId", napi_appId); 52 53 char* appIdentifier = OH_NativeBundle_GetAppIdentifier(); 54 // Native接口获取的appIdentifier转为js对象里的appIdentifier属性 55 napi_value napi_appIdentifier; 56 napi_create_string_utf8(env, appIdentifier, NAPI_AUTO_LENGTH, &napi_appIdentifier); 57 napi_set_named_property(env, result, "appIdentifier", napi_appIdentifier); 58 // 最后为了防止内存泄漏,手动释放 59 free(nativeApplicationInfo.bundleName); 60 free(nativeApplicationInfo.fingerprint); 61 free(appId); 62 free(appIdentifier); 63 return result; 64 } 65``` 66 67详细开发指导可参考包[管理NDK开发指导](../../../application-dev/napi/native-bundle-guidelines.md)。