• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 应用程序包常见问题
2<!--Kit: Ability Kit-->
3<!--Subsystem: BundleManager-->
4<!--Owner: @wanghang904-->
5<!--Designer: @hanfeng6-->
6<!--Tester: @kongjing2-->
7<!--Adviser: @Brilliantry_Rui-->
8
9## 如何获取签名信息中的指纹信息
10
11* 通过调用接口获取。
12
13可以调用[bundleManager.getBundleInfoForSelf](../reference/apis-ability-kit/js-apis-bundleManager.md#bundlemanagergetbundleinfoforself)获取自身的BundleInfo应用包信息,应用包信息中包含signatureInfo签名信息,签名信息中包含fingerprint指纹信息。
14
15```ts
16import { bundleManager } from '@kit.AbilityKit';
17import { BusinessError } from '@kit.BasicServicesKit';
18import { hilog } from '@kit.PerformanceAnalysisKit';
19
20let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
21try {
22  bundleManager.getBundleInfoForSelf(bundleFlags).then((bundleInfo:bundleManager.BundleInfo) => {
23    console.info('testTag', 'getBundleInfoForSelf successfully. fingerprint: %{public}s', bundleInfo.signatureInfo.fingerprint);
24  }).catch((err: BusinessError) => {
25    console.error('testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
26  });
27} catch (err) {
28  let message = (err as BusinessError).message;
29  console.error('testTag', 'getBundleInfoForSelf failed: %{public}s', message);
30}
31```
32
33* 通过[bm工具](../tools/bm-tool.md)获取fingerprint指纹信息。
34
35```shell
36hdc shell
37# 需将com.example.myapplication替换为实际应用的包名
38bm dump -n com.example.myapplication | grep fingerprint
39```
40
41![alt text](figures/get_fingerprint.png)
42
43* 通过.cer证书文件获取,可以参考[APP备案FAQ](https://developer.huawei.com/consumer/cn/doc/app/50130)中HarmonyOS应用/元服务如何获取公钥和签名信息。
44
45* 通过keytool工具获取,详情参考[生成签名证书指纹](https://developer.huawei.com/consumer/cn/doc/AppGallery-connect-Guides/appgallerykit-preparation-game-0000001055356911#section147011294331)46
47## 什么是appIdentifier
48
49appIdentifier是<!--RP1-->[Profile签名文件](../security/app-provision-structure.md)<!--RP1End-->中的一个字段,为应用的唯一标识,在应用签名时生成,其中:
50
511. 通过DevEco Studio工具[自动签名](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-signing#section18815157237)生成,此时的appIdentifier字段是随机生成的,在不同的设备上签名、或者重新签名均会导致appIdentifier字段不一致。
52<!--RP2-->
532. 手动配置签名,详情参考[应用包签名工具指导](../security/hapsigntool-guidelines.md),此时appIdentifier字段取值为[HarmonyAppProvision配置文件](../security/app-provision-structure.md)中app-identifier字段。
54<!--RP2End-->
55
56因此,在跨设备调试、跨应用交互调试、或者多用户共同开发且需要共享密钥等要求appIdentifier不变的场景下,推荐使用手动签名,具体场景请参考[使用场景说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-signing#section54361623194519)57
58## 如何获取应用信息中的appIdentifier
59
60* 可以调用[bundleManager.getBundleInfoForSelf](../reference/apis-ability-kit/js-apis-bundleManager.md#bundlemanagergetbundleinfoforself)获取自身的BundleInfo应用包信息,应用包信息中包含signatureInfo签名信息,签名信息中包含appIdentifier信息。
61
62```ts
63import { bundleManager } from '@kit.AbilityKit';
64import { BusinessError } from '@kit.BasicServicesKit';
65import { hilog } from '@kit.PerformanceAnalysisKit';
66
67let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_SIGNATURE_INFO;
68try {
69  bundleManager.getBundleInfoForSelf(bundleFlags).then((bundleInfo:bundleManager.BundleInfo) => {
70    console.info('testTag', 'getBundleInfoForSelf successfully. appIdentifier: %{public}s', bundleInfo.signatureInfo.appIdentifier);
71  }).catch((err: BusinessError) => {
72    console.error('testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message);
73  });
74} catch (err) {
75  let message = (err as BusinessError).message;
76  console.error('testTag', 'getBundleInfoForSelf failed: %{public}s', message);
77}
78```
79
80* 通过[bm工具](../tools/bm-tool.md)获取。
81
82```shell
83hdc shell
84# 需将com.example.myapplication替换为实际应用的包名
85bm dump -n com.example.myapplication | grep appIdentifier
86```
87
88![alt text](figures/get_appIdentifier.png)
89
90
91