尝试使用 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/