我使用自签名证书通过 SSL 提供 REST 服务。我可以通过 TRESTClient 从常规的 delphi 应用程序调用它。但是当我在 Android 应用程序中使用它时,它会在调用期间引发以下异常。
Exception class EJNIException with message 'java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
我发现,必须通过将 android:networkSecurityConfig="@xml/network_security_config"
添加到 AndroidManifest.template.xml 的 application
部分来配置网络安全 文件。
<application android:networkSecurityConfig="@xml/network_security_config"
android:persistent="%persistent%"
android:restoreAnyVersion="%restoreAnyVersion%"
android:label="%label%"
android:debuggable="%debuggable%"
android:largeHeap="%largeHeap%"
android:icon="%icon%"
android:theme="%theme%"
android:hardwareAccelerated="%hardwareAccelerated%"
android:resizeableActivity="false">
然后我必须创建具有类似内容的 res\xml\network_security_config.xml 文件:
<?xml version="1.0" encoding="utf-8"?> <network-security-config>
<domain-config>
<domain includeSubdomains="true">example.com</domain>
<trust-anchors>
<certificates src="@raw/my_ca"/>
</trust-anchors>
</domain-config> </network-security-config>
但是在哪里放置network_security_config.xml 文件。当我将它放在 Debug 内的 res 文件夹中时,它在构建过程中被删除了。因此在打包阶段找不到它并引发异常。
Error: E2312 C:\Users\User\Documents\Embarcadero\Studio\Projects\Andr\Android\Debug\TabbedApplication\AndroidManifest.xml:19: error: Error: No resource found that matches the given name (at 'networkSecurityConfig' with value '@xml/network_security_config').
我不知道,把它放在哪里并让 RAD Studio 知道,它必须在编译时抓取这个文件。
最佳答案
您不能直接使用 Debug 和 Release 文件夹来指定需要随应用程序一起部署的文件,因为它们是在每次重建时清除的临时文件夹。
对于部署,您应该使用Project -> Deployment
对话框。
您可以在此处指定要部署的本地文件(放置在构建文件夹之外)、配置(调试、发布或两者)及其目标路径。
关于android - RAD的Android应用中的自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56301765/