android 回编后包体报错:you need to use a theme.appcompat theme (or descendant) with this activity

如果是通过public.xml的方式逆向修改R文件的话,public.xml的属性值可以对应逆向修改

["R$xml.smali", "R$style.smali", "R$string.smali", "R$raw.smali", "R$layout.smali",
                            "R$id.smali",
                            "R$drawable.smali", "R$dimen.smali", "R$color.smali", "R$attr.smali", "R$array.smali",
                            "R$anim.smali"]

以上R文件的值,并且可以对应上,但是R$styleable.smali 文件的跟其它R文件不一样,所以无法直接修改到里边的值,所以会报错找不到,例如

<declare-styleable name="AppCompatTheme">

<!-- ============= -->
<!-- Window styles -->
<!-- ============= -->
<eat-comment/>

<!-- Flag indicating whether this window should have an Action Bar
in place of the usual title bar. -->
<attr format="boolean" name="windowActionBar"/>

.....

AppCompatTheme里边的windowActionBar 就会找不到,因为R$styleable.smali的值没有修改到

如何修改R$styleable.smali的值:

1.记录母包(已经合并过重新生成的值)和sdk包的public.xml中type为attr 的值

2.母包attr的属性名称,SDK中也包含,那么比较一下它们的值是不相等,则把R$styleable.smali 文件中 sdk中attr的值,替换成母包sdk的

代码片段

def change_smali_with_styleable(public_xml_path, sdk_xml_path, smali_path):
    """
    母包的public.xml typ类型为 attr的 和sdk包的public.xml对比,如果值一样,不操作;
        值不一样,则修改母包的所有R$styleable.smali 中有public的值,替换成母包的值
    """
    file_name = 'R$styleable.smali'
    file_path = os.path.join(smali_path, file_name)
    if not os.path.exists(file_path):
        return
    with open(file_path, 'r') as file:
        content = file.read()
    mUniqueIdMapping = getPublicAttrs(public_xml_path)
    cUniqueIdMapping = getPublicAttrs(sdk_xml_path)
    new_content = ''
    for attr in mUniqueIdMapping:
        # sdk有这个属性名称
        if attr in cUniqueIdMapping:
            # 对比下下值是否相等
            if mUniqueIdMapping[attr] != cUniqueIdMapping[attr]:
                old_value = cUniqueIdMapping[attr]
                new_value = mUniqueIdMapping[attr]
                # 在文件内容中替换旧值为新值
                new_content = content.replace(old_value, new_value)
                content = new_content

    with open(file_path, 'w') as file:
        file.write(new_content)

修改完既可完美解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值