google / archive-patcher

Automatically exported from code.google.com/p/archive-patcher
Apache License 2.0
534 stars 74 forks source link

On Android 12 devices, The file generated with the patch was different from the origin file; #183

Open guzhonL opened 2 years ago

guzhonL commented 2 years ago

On Android 12 devices(Almost all of android 12 devices), I found in certain cases the file generated with the patch was different from the origin file;

env: android os version:android12,archive-patcher version:v1.1

my test files as flows: old file:19onlyjar.zip patch file:patch-onlyjar.zip origin file:20onlyjar-ori.zip

how to reproduce: 1、unzip patch file first; 2、apply the patch with the following code: ` public static void applyPatch(File oldFile, File patchFile, File newFile, File tempDir) throws IOException {

   if(!tempDir.exists()){
       tempDir.mkdirs();
   }
    BufferedInputStream bufferedPatchIn = null;
    BufferedOutputStream bufferedNewOut = null;
    try{
        FileByFileV1DeltaApplier applier = new FileByFileV1DeltaApplier(tempDir);
        FileInputStream patchIn = new FileInputStream(patchFile);
        bufferedPatchIn = new BufferedInputStream(patchIn);
        FileOutputStream newOut = new FileOutputStream(newFile);
        bufferedNewOut = new BufferedOutputStream(newOut);
        applier.applyDelta(oldFile, bufferedPatchIn, bufferedNewOut);
        bufferedNewOut.flush();
    }finally {
        if(bufferedPatchIn != null){
            bufferedPatchIn.close();
        }
        if(bufferedPatchIn != null){
            bufferedPatchIn.close();
        }
    }
}`

3、compare the md5 between the origin file and the generated file in step2

19onlyjar.zip patch-onlyjar.zip 20onlyjar-ori.zip

sun804336516 commented 2 years ago

I also encountered this problem

hamidmansouri commented 2 years ago

me too

GreenPepperForPotato commented 2 years ago

me too

aravindakv commented 2 years ago

I also encountered this problem. Its issue with only Android 12, works fine in linux PC.

hamid97m commented 2 years ago

Any solution? @pspencil

pspencil commented 2 years ago

Any solution? @pspencil

Sorry I don't work on this anymore. I have some vague memories of Android 12 changing the underlying zip library. Perhaps you can try explicitly linking in your own zip lib. (Not sure how to do that though)

sisong commented 2 years ago

My solution 1: ApkDiffPatch; MIT license; C++; linking own zlib; only for own apk; (can't be used by Android app store, because it requires re-signing apks before diff);
My solution 2: sfpatcher; Business license; C++; linking own zlib; is designed for Android app store; patch speed up by a factor of xx than archive-patcher & run with O(1) memory & not need temp files & support large game apk & support android4.1--android13.

aravindakv commented 2 years ago

How to integrate sfpatcher; in android app? are there jar/aar files available?

hamid97m commented 2 years ago

Do you think the problem could be solved by changing the Zlib version in server side for generating diff?@pspencil If the answer is no, have you any idea about how link own Zlib (1.2.12) in my project? the archive-patcher is using deflater and changing the deflater is not possible, it is loading the zlib in static block. @pspencil

hamid97m commented 1 year ago

I finally fixed this problem; in the near future, I will make a PR

ityancs commented 1 year ago

I finally fixed this problem; in the near future, I will make a PR

Can you share how to fix it?more PR details?

ityancs commented 1 year ago

finally I copy the zlib jni code(below android 12) solved

aravindakv commented 1 year ago

finally I copy the zlib jni code(below android 12) solved

Can you submit changes and share PR details?

ityancs commented 1 year ago

finally I copy the zlib jni code(below android 12) solved

Can you submit changes and share PR details?

copy the zlib c code and use custom Deflater bind the custom zlib with jni。 https://cs.android.com/android/platform/superproject/+/android-10.0.0_r47:external/zlib/src/deflate.c https://cs.android.com/android/platform/superproject/+/master:libcore/ojluni/src/main/native/Deflater.c

hamid97m commented 1 year ago

It's fixed in my PR

berlix commented 1 year ago

Inspired by @hamid97m's solution, we addressed this issue by bundling zlib 1.2.13 binaries (the currently latest version) and creating a version of Deflater that uses those.

Sources: https://github.com/EIDU/archive-patcher-android

The library is on Maven Central. See the repo's README.md for usage instructions.