android - RAD的Android应用中的自签名证书

标签 android rest delphi ssl android-manifest

我使用自签名证书通过 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/

相关文章:

delphi - CxClasses 单元自动添加到 Uses 部分

delphi - 如何强制链接器包含调试期间所需的函数?

android - 使用 COUNT(*) AS 的 Room SQL 查询

java - Spring MVC - 如何为我的 resttemplate 使用不同的超时?

delphi - 捕获用鼠标选择的文本

java - RESTEasy 的错误特殊字符编码

java - 如何使用 @ControllerAdvice 在 Spring MVC 中返回 ResponseEntity 的方法中返回错误消息

java - 从单选组值中选择一个并向下滚动并在 Recycler View 中自动选择一些项目(初学者)

android - 必须声明元素自适应图标

java - Android Volley : BasicNetwork. performRequest:意外的响应代码 404