# Gradle 对包进行签名的时候提示错误 00B5050F

**URL:** <https://www.isharkfly.com/t/gradle-00b5050f/789>\
**Category:** DevOps\
**Created:** [December 25, 2020, 6:15pm UTC](https://www.isharkfly.com/t/gradle-00b5050f/789 "2020-12-25T18:15:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas](https://www.isharkfly.com/user_avatar/www.isharkfly.com/lucas/32/20805_2.png) [@lucas](https://www.isharkfly.com/u/lucas)\
**Post date:** [December 25, 2020, 6:15pm UTC](https://www.isharkfly.com/t/gradle-00b5050f/789/1 "2020-12-25T18:15:47Z")

</div>

具体的错误提示信息如下：

```auto
The key ID must be in a valid form (eg 00B5050F or 0x00B5050F), given value: 1E5CBEF8B550FB7D

```

![gralde-error-01](https://www.isharkfly.com/images/transparent.png)

## 问题和解决

这个问题比较蠢。与 Gradle 的插件 id ‘signing’ 有关。

可以反问源代码：[gradle/subprojects/security/src/main/java/org/gradle/plugins/signing/signatory/pgp/PgpKeyId.java at 124712713a77a6813e112ae1b68f248deca6a816 · gradle/gradle · GitHub](https://github.com/gradle/gradle/blob/124712713a77a6813e112ae1b68f248deca6a816/subprojects/security/src/main/java/org/gradle/plugins/signing/signatory/pgp/PgpKeyId.java)

在这个源代码中有一个对 Key 校验的方法：

```auto
    private static String normaliseKeyId(String keyId) {
        String keyIdUpped = keyId.toUpperCase();
        switch (keyIdUpped.length()) {
            case 10:
                if (!keyIdUpped.startsWith("0X")) {
                    throw new IllegalArgumentException("10 character key IDs must start with 0x (given value: " + keyId + ")");
                }
                return keyIdUpped.substring(2);
            case 8:
                if (keyId.startsWith("0X")) {
                    throw new IllegalArgumentException("8 character key IDs must not start with 0x (given value: " + keyId + ")");
                }
                return keyIdUpped;
            default:
                throw new IllegalStateException("The key ID must be in a valid form (eg 00B5050F or 0x00B5050F), given value: " + keyId);
        }
    }

```

![gralde-error-02](https://www.isharkfly.com/images/transparent.png)

从这个方法中，你可以看到如果你的 Key ID 是 10 位的，你需要使用 0X 开头。

如果你的 key ID 超过 10 位就直接报错了。

在 Kleopatra 中，默认给了 16位的 Key Id，如果你直接拷贝的话，只会报错。

![gralde-error-03](https://www.isharkfly.com/images/transparent.png)

因此，根据上面的问题：

signing.keyId=

参数应该只能保留 8 位置。

因此

```auto
signing.keyId=

```

的配置应该为：

```auto
signing.keyId=B550FB7D

```

通过上面的调整后再进行编译，你应该不会遇到上面错误问题。
