基于U8SDK安卓打包反编译,回编错误记录

目录

1:dex2smali dex文件转smail文件报错

2:jar2dex   jar转dex过程报错

3:recompileApk回编译,Could not smali file:

4:打包签名加密方式,命令行代码:

5:splitDex 分包的过程中,要copy的文件找不到

6:回编结束,aapt copyRootResFiles过程报错

7:dex2smali,报警告信息

8:合并R文件,R资源

9:运行找不到渠道SDK的R.styleable.xxxx

10:合并R资源,aapt报:

 11:分包ok,回编译报65536问题,别的渠道dex总数更大,回编译也没问题,只有360有问题

12:jar转dex,jar过大,需要分批加载问题


1:dex2smali dex文件转smail文件报错

Exception in thread "main" org.jf.util.ExceptionWithContext: F:\xxxx\xxxx\workspace\xxxx\xxxx\tiancity\sdk\xxxx\classes.dex is not an apk, dex file or odex file.
        at org.jf.dexlib2.DexFileFactory.loadDexFile(DexFileFactory.java:111)
        at org.jf.dexlib2.DexFileFactory.loadDexFile(DexFileFactory.java:54)
        at org.jf.baksmali.main.main(main.java:252)

 解决:去github 上换新的baksmali.jar

2:jar2dex   jar转dex过程报错

java -jar baksmali-2.5.2.jar -o smali classes.dex

Exception in thread "main" com.beust.jcommander.MissingCommandException: Expected a command, got -o
        at com.beust.jcommander.JCommander.parseValues(JCommander.java:725)
        at com.beust.jcommander.JCommander.parse(JCommander.java:304)
        at com.beust.jcommander.JCommander.parse(JCommander.java:287)
        at org.jf.baksmali.Main.main(Main.java:90)

解决:命令行使用错误

java -jar baksmali-2.5.2.jar disassemble -o smali classes.dex

3:recompileApk回编译,Could not smali file:

"F:/xxxx/xxxx/tool/win/jre/bin/java" -jar -Xms512m -Xmx512m "F:/xxxx/xxxx/tool/win/apktool_2.6.0.jar" -q b -f "F:/xxxx/xxxx/workspace/xxxx/xxxx/xxx/decompile" -o "F:/xxxx/xxxx/workspace/xxxx/xxxx/xxxx/output.apk"
workspace\xxxx\xxxx\xxxx\decompile\smali\com\xxxx\mob\component\base\livedata\ProtectedUnPeekLiveData.smali[154,4] null
Could not smali file: com/xxxx/mob/component/base/livedata/ProtectedUnPeekLiveData.smali
2021-11-30 14:47:46,164: *******ERROR*******
2021-11-30 14:47:46,164:
b'workspace\\xxxx\\xxxx\\xxxx\\decompile\\smali\\com\\xxxx\\mob\\component\\base\\livedata\\ProtectedUnPeekLiveData.smali[154,4] null\r\nCould not smali file: com/xxxx/mob/component/base/livedata/ProtectedUnPeekLiveData.smali\r\n'
2021-11-30 14:47:46,165: *******************

解决

dx.工具不支持java8语法,需要D8工具语法脱糖

莱姆达表达式 反编译 回编有错误,smali ->apk过程

4:打包签名加密方式,命令行代码:

apksigner.jar所在位置:安卓SDK\build-tools\25.0.0\lib\

#V2签名,默认V1V2,Android7.0 ,tool里使用的是25.0.0

#V3签名,8.0的apksigner.jar,如果使用27以上的 ,默认包含V1,V2,V3签名

安卓SDK提供的apksigner.jar工具,v1v2签名

java -jar apksigner.jar sign -verbose --ks zs.keystore --v1-signing-enabled false --v2-signing-enabled true --ks-pass pass:123123 --ks-key-alias zs.keystore --key-pass pass:123123 --out test_dst.apk test_src.apk

jarsigner.exe 所在目录:jdk1.8.0_281\bin

JDK提供的jarsigner.exe工具,v1签名

jarsigner -digestalg SHA1 -sigalg MD5withRSA -keystore ${keystore} -storepass  ${keystore.password} -keypass ${keypass} -signedjar ${signed.apkfile} ${unsigned.apkfile} ${keyalias} 

5:splitDex 分包的过程中,要copy的文件找不到

如果母包已经有多个smail,导致合并渠道SDK后,dex数量超过65536去分包,顺序混乱找不到文件。

比如要拷贝的IntrinsicsKt__IntrinsicsJvmKt$createCoroutineUnchecked$$inlined$buildContinuationByInvokeCall$IntrinsicsKt__IntrinsicsJvmKt$1.smali'这个文件 是在smali_classes2这里,但是从smali_classes2_classes2这里去copy,就会找不到目录

FileNotFoundError: [Errno 2] No such file or directory: 'F:/PycharmProject/pythonAPK2.0/workspace/xxx/xxxx/

decompile/smali_classes2_classes2/kotlin/coroutines/

experimental/intrinsics/IntrinsicsKt__IntrinsicsJvmKt$

createCoroutineUnchecked$$inlined$buildContinuationByInvokeCall$

IntrinsicsKt__IntrinsicsJvmKt$1.smali'

基于U8SDK安卓打包反编译,回编错误记录_第1张图片

基于U8SDK安卓打包反编译,回编错误记录_第2张图片

 解决方案:

在反编译后,把smali_classes2目录下的文件 copy到smail里

def decompileApk(source, targetdir, apktool="apktool_2.6.0.jar"):
    """
    Decompile apk
    """
    apkfile = file_utils.getFullPath(source)
    targetdir = file_utils.getFullPath(targetdir)
    apktool = file_utils.getFullToolPath(apktool)

    if os.path.exists(targetdir):
        file_utils.del_file_folder(targetdir)
    if not os.path.exists(targetdir):
        os.makedirs(targetdir)
    #添加–only-main-classes参数,针对有的母包assets下面也有dex文件而导致错误
    #cmd = '"%s" -jar -Xms%sm -Xmx%sm "%s" -v d -b -f "%s" --only-main-classes -o "%s"' % (file_utils.getJavaCMD(), heapSize, heapSize, apktool, apkfile, targetdir)
    cmd = '"%s" -jar -Xms512m -Xmx512m "%s" -q d -b -f "%s" -o "%s"' % (file_utils.getJavaCMD(), apktool, apkfile, targetdir)
    ret = file_utils.execFormatCmd(cmd)

    # -->如果母包中已经拆分出多个smali,复制到第一个smali,并删除,以便于重新计算
    smaliDir = targetdir + "/smali"
    smali2Dir = targetdir + "/smali_classes2"
    if os.path.exists(smali2Dir):
        file_utils.copy_files(smali2Dir, smaliDir)
        file_utils.del_file_folder(smali2Dir)
    return ret
6:回编结束,aapt copyRootResFiles过程报错

Unable to add 'kotlin/annotation/annotation.kotlin_builtins' to 'F:/PycharmProject/pythonAPK2.0/workspace/xxx/xxx/output.apk': already exists in archive

基于U8SDK安卓打包反编译,回编错误记录_第3张图片

基于U8SDK安卓打包反编译,回编错误记录_第4张图片

 解决方案:需要忽略基于U8SDK安卓打包反编译,回编错误记录_第5张图片

igoreFiles = ['AndroidManifest.xml','apktool.yml','smali','res','original','lib','build','assets','META-INF',
            'unknown',"smali_classes2","smali_classes3","smali_classes4","smali_classes5","kotlin"]
7:dex2smali,报警告信息

基于U8SDK安卓打包反编译,回编错误记录_第6张图片

 解决方案:

# cmd = '"%s" -jar "%s" disassemble -o "%s" "%s"' % (file_utils.getJavaCMD(), smaliTool, targetdir, dexFile)
改为
cmd = '"%s" -jar "%s" -o "%s" "%s"' % (file_utils.getJavaCMD(), smaliTool, targetdir, dexFile)
8:合并R文件,R资源

doGenerateR
First type is not attr!
A/        (14756): First type is not attr!
*******ERROR*******

b''

b'First type is not attr!\r\nA/        (14180): First type is not attr!\r\n'

*******************

基于U8SDK安卓打包反编译,回编错误记录_第7张图片

 原因是aapt 去合并 aapt2编译的包,resource.arsc文件,不能以attr开头。

基于U8SDK安卓打包反编译,回编错误记录_第8张图片:apktool工具地址:https://bitbucket.org/iBotPeaches/apktool/downloads/

9:运行找不到渠道SDK的R.styleable.xxxx

No static field AppCompatTheme_windowActionBar of type I in class Lcom/xxx/sdk/thirdparty/R$styleable; 
or its superclasses (declaration of 'com.xxxx.sdk.thirdparty.R$styleable' appears in /data/app/com.xxxx.xxx.xx-i22o2TufgzlaUEjh6xl9AQ==/base.apk!classes2.dex)

基于U8SDK安卓打包反编译,回编错误记录_第9张图片

 解决方案:

基于U8SDK安卓打包反编译,回编错误记录_第10张图片U8SDK——declare-styleable自定义资源的合并

10:合并R资源,aapt报:

error::"F:/PycharmProject/pythonAPK2.0/tool/win/aapt_64" p -f -m -J "F:/PycharmProject/pythonAPK2.0/workspace/xxx/xxx/temp/gen" -S "F:/PycharmProject/pythonAPK2.0/workspace/xx/xxx/temp/res" -I 
"F:/PycharmProject/pythonAPK2.0/tool/win/android.jar" -M "F:/PycharmProject/pythonAPK2.0/workspace/xxx/xxxx/decompile/AndroidManifest.xml"  !!!exec Fail!!!  
apk generate fail

基于U8SDK安卓打包反编译,回编错误记录_第11张图片

 解决方案:基于U8SDK安卓打包反编译,回编错误记录_第12张图片

 11:分包ok,回编译报65536问题,别的渠道dex总数更大,回编译也没问题,只有360有问题

2023-06-27 13:12:43,449: =======================分包=======================
testtestthe total func num:66869
split dex success. the classes.dex num:2
2023-06-27 13:16:04,353: 分包花费时长:200.9034秒
2023-06-27 13:16:04,354: =======================回编=======================
Exception in thread "main" org.jf.util.ExceptionWithContext: Exception occurred while writing code_item for method Lqihoohttp/okhttp3/internal/http2/ErrorCode;->values()[Lqihoohttp/okhttp3/internal/http2/ErrorCode;
        at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:1047)
        at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:346)
        at org.jf.dexlib2.writer.DexWriter.writeTo(DexWriter.java:301)
        at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:58)
        at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:37)
        at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:426)
        at brut.androlib.Androlib.buildSources(Androlib.java:357)
        at brut.androlib.Androlib.build(Androlib.java:309)
        at brut.androlib.Androlib.build(Androlib.java:276)
        at brut.apktool.Main.cmdBuild(Main.java:255)
        at brut.apktool.Main.main(Main.java:81)
Caused by: org.jf.util.ExceptionWithContext: Error while writing instruction at code offset 0x2
        at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1320)
        at org.jf.dexlib2.writer.DexWriter.writeDebugAndCodeItems(DexWriter.java:1043)
        ... 10 more
Caused by: org.jf.util.ExceptionWithContext: Unsigned short value out of range: 65536
        at org.jf.dexlib2.writer.DexDataWriter.writeUshort(DexDataWriter.java:116)
        at org.jf.dexlib2.writer.InstructionWriter.write(InstructionWriter.java:356)
        at org.jf.dexlib2.writer.DexWriter.writeCodeItem(DexWriter.java:1280)
        ... 11 more

2023-06-27 13:16:39,949: *******ERROR*******

基于U8SDK安卓打包反编译,回编错误记录_第13张图片

 解决方案:

 maxFuncNum = 65535 设置的过于临近,改为50000试试。

def splitDex(workDir,decompileDir,multidex="android-support-multidex.jar"):
    smaliPath = decompileDir + "/smali"
    multidexFilePath = file_utils.getFullPath(smaliPath + "/android/support/multidex/MultiDex.smali")
    if not os.path.exists(multidexFilePath):
        dexJar = file_utils.getFullToolPath(multidex)
        if not os.path.exists(dexJar):
            log_utils.error("the method num expired of dex, but no android-support-multidex.jar in u8.apk or in local folder")
            return
        targetPath = file_utils.getFullPath(workDir+"/local")
        if not os.path.exists(targetPath):
            os.makedirs(targetPath)
            
        file_utils.copy_file(dexJar, targetPath+"/libs/android-support-multidex.jar") 

        jar2dex(targetPath, targetPath)
        smaliPath = file_utils.getFullPath(decompileDir + "/smali")
        ret = dex2smali(targetPath + '/classes.dex', smaliPath)
    
    allFiles = []
    allFiles = file_utils.list_files(decompileDir, allFiles, [])    

    maxFuncNum = 50000
    currFucNum = 0
    totalFucNum = 0

    currDexIndex = 1

    allRefs = []

    #保证U8Application等类在第一个classex.dex文件中
    for f in allFiles:
        f = f.replace("\\", "/")
        if "/com/lhcit/game/api" in f or "/android/support/multidex" in f:
            currFucNum = currFucNum + smali_utils.get_smali_method_count(f, allRefs)

    totalFucNum = currFucNum
    for f in allFiles:

        f = f.replace("\\", "/")
        if not f.endswith(".smali"):
            continue

        if "/com/lhcit/game/api" in f or "/android/support/multidex" in f:
            continue

        thisFucNum = smali_utils.get_smali_method_count(f, allRefs)
        totalFucNum = totalFucNum + thisFucNum
        if currFucNum + thisFucNum >= maxFuncNum:
            currFucNum = thisFucNum
            currDexIndex = currDexIndex + 1
            newDexPath = os.path.join(decompileDir, "smali_classes"+str(currDexIndex))
            os.makedirs(newDexPath)
        else:
            currFucNum = currFucNum + thisFucNum


        if currDexIndex > 1:
            targetPath = f[0:len(decompileDir)] + "/smali_classes"+str(currDexIndex) + f[len(smaliPath):]
            file_utils.copy_file(f, targetPath)
            file_utils.del_file_folder(f)


    print("the total func num:"+str(totalFucNum))
    print("split dex success. the classes.dex num:"+str(currDexIndex))

    return currDexIndex 
12:jar转dex,jar过大,需要分批加载问题

原因是,接入抖音渠道SDK,提供的jar包很大,大约30多M,导致打包在jar转dex这一步,因为dex只能装载65535个函数,而需要分批加载,具体错误如下:

2023-07-14 11:04:01,859: =======================jar to dex=======================
Error: Cannot fit requested classes in a single dex file. Try supplying a main-dex list.
# methods: 93544 > 65536
Compilation failed
2023-07-14 11:04:47,584: *******ERROR*******
2023-07-14 11:04:47,584: b'Error: Cannot fit requested classes in a single dex file. Try supplying a main-dex list.\r\n# methods: 93544 > 65536\r\nCompilation failed\r\n'
2023-07-14 11:04:47,584: ******************* 基于U8SDK安卓打包反编译,回编错误记录_第14张图片

 解决方案:

基于U8SDK安卓打包反编译,回编错误记录_第15张图片

基于U8SDK安卓打包反编译,回编错误记录_第16张图片

你可能感兴趣的:(U8SDK打包,Android,游戏程序)