[QCM6125][Android13] 解决framework引用第三方jar包编译不通过的问题

文章目录

    • 开发平台基本信息
    • 问题描述
  • 问题分析
    • 解决方法

开发平台基本信息

芯片: QCM6125
版本: Android 13
kernel: msm-4.14

问题描述

有个自己添加的服务需要引用第三方jar库支持,而在安卓13的编译规则里面,jar解包出来的类名都必须是至少包含一个字母大写的,不然就抛出异常编译出错;模块厂商给的建议是找厂家重新适配安卓13的jar包,但是,像一些开源的jar包,不可能去做兼容,既然是编译规则引发的错误,那么就修改编译规则。

问题分析

FAILED: out/soong/hiddenapi/hiddenapi-stub-flags.txt.valid
out/host/linux-x86/bin/verify_overlaps --monolithic-flags out/soong/hiddenapi/hiddenapi-stub-flags.txt --module-flags
Traceback (most recent call last):
File “/home/hongxb/data/SC665S_Android13.0_r04_r020/QSSI.13/out/host/linux x86/bin/verify_overlaps/internal/stdlib/runpy.py”, line 196, in _run_module_as_main

File “/home/hongxb/data/SC665S_Android13.0_r04_r020/QSSI.13/out/host/linux-> x86/bin/verify_overlaps/signature_trie.py”, line 154, in signature_to_elements
Exception: Invalid signature ‘Lcom/esc/a;->a(Ljava/lang/String;)[B’: last element ‘a’ is lower case but should be an upper case class name or wildcard

从报错日志的最后一句话可以看出来,解包jar的类名为a,应该是混淆导致的,而编译规则要求必须为大写,一般编译规则都在build目录下,所以到该目录底下搜索错误日志相关的信息。

hongxb@R720-0-19:~/data5/SC665S_Android13.0_r04_r020/QSSI.13/build$ grep -rn "Invalid signature"
soong/scripts/hiddenapi/verify_overlaps_test.py:214:            "Invalid signature: Ljava/lang/Object, "
soong/scripts/hiddenapi/signature_trie.py:144:                raise Exception(f"Invalid signature '{signature}': invalid "
soong/scripts/hiddenapi/signature_trie.py:149:                raise Exception(f"Invalid signature '{signature}': contains "
soong/scripts/hiddenapi/signature_trie.py:154:            raise Exception(f"Invalid signature '{signature}': last element "
soong/scripts/hiddenapi/signature_trie.py:265:                f"Invalid signature: {signature}, does not identify a "

从搜索信息查找与报错日志相匹配的,可以定位在signature_trie.py第154行,具体代码如下:

        if "*" in last_element:
            if last_element not in ("*", "**"):
                raise Exception(f"Invalid signature '{signature}': invalid "
                                f"wildcard '{last_element}'")
            packages = elements[0:-1]
            # Cannot specify a wildcard and target a specific member
            if member:
                raise Exception(f"Invalid signature '{signature}': contains "
                                f"wildcard '{last_element}' and "
                                f"member signature '{member[0]}'")
            wildcard = [last_element]
        elif last_element.islower():
            raise Exception(f"Invalid signature '{signature}': last element "
                            f"'{last_element}' is lower case but should be an "
                            f"upper case class name or wildcard")
        else:
            packages = elements[0:-1]
            # Split the class name into outer / inner classes
            #  0 - Character
            #  1 - UnicodeScript
            classes = last_element.removesuffix(";").split("$")

在python语法中,str.islower()方法是判断文本是否包含大写字母,如果全部为小写字母则返回false,如果包含至少一个大写字母,则返回TRUE。而将jar解压出来,的确是能看到有些类名是只有小写字母的;所以,将这个判断条件去掉再试试看能不能编译通过。

解决方法

最终将编译规则的islower条件去掉之后,就能编译成功并且能够正常加载jar包。

--- a/QSSI.13/build/soong/scripts/hiddenapi/signature_trie.py
+++ b/QSSI.13/build/soong/scripts/hiddenapi/signature_trie.py
@@ -150,10 +150,10 @@ class InteriorNode(Node):
                                 f"wildcard '{last_element}' and "
                                 f"member signature '{member[0]}'")
             wildcard = [last_element]
-        elif last_element.islower():
-            raise Exception(f"Invalid signature '{signature}': last element "
-                            f"'{last_element}' is lower case but should be an "
-                            f"upper case class name or wildcard")
+        #  elif last_element.islower():
+        #      raise Exception(f"Invalid signature '{signature}': last element "
+        #                      f"'{last_element}' is lower case but should be an "
+        #                      f"upper case class name or wildcard")
         else:
             packages = elements[0:-1]
             # Split the class name into outer / inner classes

你可能感兴趣的:(Android13,Android13,高通6125,framework,jar,第三方jar,编译报错)