未解决的参考:toByteString

Unresolved reference: toByteString

我正在使用 SDK ,它需要“ByteString”中的数据。

当我尝试将 BigInteger 转换为 toByteString 时,它给我一条错误消息。

BigInteger("d693a400", 16).toByteString()

Unresolved reference: toByteString

我尝试包含 protobuf 插件,但错误仍然存​​在。

项目级别 - Build.gradle

dependencies {
    classpath "com.android.tools.build:gradle:4.1.1"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

应用级别 - Build.gradle

plugins {
    id 'com.android.application'
    id "com.google.protobuf" version "0.8.15"
}

添加依赖项 implementation "com.trustwallet:wallet-core:0.12.31" 后,我可以使用 com.google.protobuf

中的 ByteString

我检查了存储库并找到了这些扩展 https://github.com/trustwallet/wallet-core/blob/05375deb1b4b45d491b59ca775aa43e9e9a39b11/android/app/src/main/java/com/trustwallet/core/app/utils/Extensions.kt#L17,这是对字符串的扩展。

所以我查看了他们的实际示例,发现他们在那里使用了自定义函数:

private fun BigInteger.toByteString(): ByteString {
    return ByteString.copyFrom(this.toByteArray())
}

来源:https://github.com/trustwallet/wallet-core/blob/05375deb1b4b45d491b59ca775aa43e9e9a39b11/samples/android/app/src/main/java/com/trust/walletcore/example/MainActivity.kt#L115