开发者社区> 问答> 正文

【移动热修复】移动热修复-补丁加载成功后apache网络库请求报错

移动热修复-补丁加载成功后apache网络库请求报错

展开
收起
EMAS支持组 2022-09-27 15:09:59 2062 0
1 条回答
写回答
取消 提交回答
  • 使用热修复3.2.7及以上版本,补丁加载成功后,使用apache网路库进行请求,在Android 9或以上可能会报错,处理方法:

    删除有关apache的所有jar依赖包

    在gradle的android标签下添加useLibrary 'org.apache.http.legacy',示例:

    android {
        compileSdkVersion 28
        useLibrary 'org.apache.http.legacy'
        defaultConfig {
            applicationId "xxx.xxx.xxx"
            minSdkVersion 14
            targetSdkVersion 28
            //...
        }
    }
    

    在AndroidManifest.xml文件下添加如下示例的uses-library:

     <application
            android:name=".SophixStubApplication"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme"
            tools:ignore="GoogleAppIndexingWarning">
            <uses-library
                android:name="org.apache.http.legacy"
                android:required="false" />
            //...
    </application>
    

    如开启了混淆,添加apache相关混淆规则,如:

    #apache
    -keep class org.dom4j.** { *; }
    -dontwarn org.apache.*
    -keep class org.apache.** { *; }
    -dontwarn org.xmlpull.*
    -keep class org.xmlpull.** { *; }
    -dontwarn com.jcraft.*
    -keep class com.jcraft.** { *; }
    -dontwarn android.net.compatibility.**
    -dontwarn android.net.http.**
    -dontwarn com.android.internal.http.multipart.**
    -dontwarn org.apache.commons.**
    -dontwarn org.apache.http.**
    -dontwarn org.apache.http.protocol.**
    -keep class android.net.compatibility.*{ *; }
    -keep class android.net.http.*{ *; }
    -keep class com.android.internal.http.multipart.{ *; }
    -keep class org.apache.commons.{ *; }
    -keep class org.apache.org.{ *; }
    -keep class org.apache.harmony.{ *; }
    

    上述步骤操作完毕后,重新打新旧apk包及补丁,然后再次使用新生成的这个旧包去加载对应补丁,应该不会再出现apache请求失败的问题了。

    如上述方法未解决apache请求报错问题,请联系技术支持解决。


    更多官方信息

    EMAS官网介绍:https://www.aliyun.com/product/emas

    Devops:https://www.aliyun.com/product/emascrash/mobile_devops

    移动热修复:https://www.aliyun.com/product/hotfix

    移动测试:https://www.aliyun.com/activity/emas/mqcexpert

    移动推送:https://www.aliyun.com/product/cps

    HTTPDNS:https://www.aliyun.com/product/httpdns

    EMAS 控制台: https://emas.console.aliyun.com/products

    2022-09-27 15:21:10
    赞同 展开评论 打赏
来源圈子
更多
收录在圈子:
基于阿里巴巴以及合作伙伴的最佳实践,围绕大前端、云原生领域的相关技术热点(小程序、Serverless、应用中间件、低代码、DevOps)展开行业探讨,与开发者一起探寻云原生时代应用研发的新范式。
问答排行榜
最热
最新

相关电子书

更多
Apache Flink技术进阶 立即下载
Apache Spark: Cloud and On-Prem 立即下载
Hybrid Cloud and Apache Spark 立即下载

相关镜像