android - 将 key 文件放入 APK 中

标签 android

尝试使用 gradle、任务assemble 构建应用程序 apk 文件。我的应用程序包含私钥文件,但出现错误:

E:\D\android\MQTT\app\src\main\res\raw\clientkey.pem: Error: The raw\\clientkey.pem file seems to be a private key file. Please make sure not to embed this in your APK file. [PackagedPrivateKey]

   Explanation for issues of type "PackagedPrivateKey":
   In general, you should not package private key files inside your app. 

1 errors, 0 warnings

> Task :app:lintVitalRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.

  To proceed, either fix the issues identified by lint, or modify your build script as follows:
  ...
  android {
      lintOptions {
          checkReleaseBuilds false
          // Or, if you prefer, you can continue to check for errors in release builds,
          // but continue the build even when errors are found:
          abortOnError false
      }
  }
  ...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 21s

我知道将 key 保存在 apk 中并不安全,但目前我想将其放在 apk 中。如何实现这一目标?

最佳答案

可以针对每个文件禁用此检查;模块build.gradle:

lintOptions {
    lintConfig file("../lint.xml")
}

根项目lint.xml

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="PackagedPrivateKey">
        <ignore path="src/main/res/raw/clientkey.pem"/>
    </issue>
</lint>

免责声明:请注意,私钥可能会像这样泄露。

关于android - 将 key 文件放入 APK 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60141376/

相关文章:

java - 共享首选项不应用更改

android - 如何在NavigationView 的菜单项中设置椭圆大小?

java - 如何检查 Android 中的互联网访问是否可用

android - FileObserver 收到奇怪的事件

android - 在 android 中阻止传出短信/彩信

javascript - 如何在 android 的 javascriptcore 中使用 Object.defineProperty

android - PinnedHeaderListView 滚动和标题问题

java - 通知构建显示标题和图像,但不显示内容

java - Android Intent.getStringExtra() 在 Broadcastreceiver 中返回 null

android - 怎么修? "ERROR: : Could not find any version that matches com.android.support:appcompat-v7:29.+."