Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash mismatch when using Android Hybrid app #2369

Closed
eseidel opened this issue Jul 19, 2024 · 14 comments · Fixed by shorebirdtech/docs#291
Closed

Hash mismatch when using Android Hybrid app #2369

eseidel opened this issue Jul 19, 2024 · 14 comments · Fixed by shorebirdtech/docs#291

Comments

@eseidel
Copy link
Contributor

eseidel commented Jul 19, 2024

Hi @bryanoltman @yilugesanghua i am also facing the same problem. I am following this link https://docs.shorebird.dev/guides/hybrid-apps/android/ for generating the aar. I am successfully generate the aar (shorebird release aar --release-version 1.0.25+90). I am generating the aar from different flutter project. Now i am open my native android project and updated settings.gradle file

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven{
            url 'https://download.shorebird.dev/download.flutter.io'
        }
        maven{
            url '../../../shout/release'
        }
    }
}
rootProject.name = "datingapp"
include ':app'
setBinding(new Binding([gradle: this]))

Now updating project level build.gradle file and pasting these lines:

  maven{
            url '../../../shout/release'
        }

My app level build.gradle file:

minSdkVersion 23
targetSdkVersion 34
versionCode 90
versionName "1.0.25"

After that syncing the project . i am installing the release apk on my device. Its successful install on my device.

Now i am creating patch request (shorebird release aar --release-version 1.0.25+90). Its successfully generate the patch and shows on shorebird console.

Now i am killing the app and launch it again. I am getting this error:

updater::network: Sending patch check request: PatchCheckRequest { app_id: "05db7e16-a620-4d2d-9d92-2f0c6f59e0bb", channel: "stable", release_version: "1.0.25+90", patch_number: None, platform: "android", arch: "aarch64" }
E  updater::updater: Update failed: This app reports version 1.0.22+88, but the binary is different from the version 1.0.22+88 that was submitted to Shorebird.
Caused by:
Update rejected: hash mismatch. Update was downloaded but contents did not match the expected hash. This is most often caused by using the same version number with a different app binary. Path: "/data/user/0/com.shout.dating/code_cache/shorebird_updater/downloads/2.full", expected: ed3c901808e67bb82a9db50423a3440caa741fbf73e7996faebadf218be1b6f5, got: 42aa04f10de2e4b199e48922916e68cc295938f82814df2cb0a8a48c23948746
2024-07-18 17:51:05.988 13918-13983 

I tried multiple times to open and close the app. Please help me. I am facing problem from last three days.

@yilugesanghua how you resolve this. what is remote packaging. can you also please help me on this.

We will be very grateful to you.

Originally posted by @vineetpal88 in #2232 (comment)

@eseidel
Copy link
Contributor Author

eseidel commented Jul 19, 2024

@vineetpal88 notes that it worked for their friend on Mac, but not on their own windows machine.

@eseidel
Copy link
Contributor Author

eseidel commented Jul 19, 2024

There is also a support thread for this issue on Discord: https://discord.com/channels/1030243211995791380/1239852081343631412

@sunragav
Copy link

sunragav commented Sep 5, 2024

I too face the exact similar issue. What is remote packaging as mentioned as solved in the other thread? It is not working for me in both mac as well as windows. I am using the aar from the flutter module's release folder exactly as mentioned in the doc.

`
updater::c_api: Error downloading update: This app reports version 7.17.0+2, but the binary is different from the version 7.17.0+2 that was submitted to Shorebird.
Caused by:
Update rejected: hash mismatch. Update was downloaded but contents did not match the expected hash. This is most often caused by using the same version number with a different app binary.

code_cache/shorebird_updater/downloads/1.full", expected: 123df52fb3b03d6a98417bd7ead446fca0434376359108b275d83e0e3c9dbb2e, got: 27be7b08def3f91618e74b59c9953f7825d0fc43ae73cd827cad8df4cbadd53b`

@sunragav
Copy link

sunragav commented Sep 6, 2024

I am using Windows 11, Android studio Android Studio Koala | 2024.1.1 Patch 1

PS C:\Users\sunragav> flutter --version
Flutter 3.24.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 4cf269e36d (3 days ago) • 2024-09-03 14:30:00 -0700
Engine • revision a6bd3f1de1
Tools • Dart 3.5.2 • DevTools 2.37.2

PS C:\Users\sunragav> shorebird --version
Shorebird 1.3.2 • git@github.com:shorebirdtech/shorebird.git
Flutter 3.24.2 • revision 9239d8659dedccd1dbe8527d1cf5b002720141bc
Engine • revision bfa5520fdd9129edc3b7c3e6fc5e44a61302e670
PS C:\Users\sunragav> dart --version
Dart SDK version: 3.5.2 (stable) (Wed Aug 28 10:01:20 2024 +0000) on "windows_x64"

I could reproduce the issue with the sample https://github.com/shorebirdtech/samples/tree/main/add_to_app as well.
The only thing I modified was compileSdk 34 in the AndroidAddToAppDemo app build.gradle file.


8489-8489  flutter                 com.example.addtoappdemo             I  updater::cache::updater_state: No existing state file found: File /data/user/0/com.example.addtoappdemo/files/shorebird_updater/state.json does not exist, creating new state.
2024-09-06 17:43:11.744  8489-8489  flutter                 com.example.addtoappdemo             I  [INFO:flutter/shell/common/shorebird/shorebird.cc(161)] Shorebird updater: no active patch.
2024-09-06 17:43:11.744  8489-8489  flutter                 com.example.addtoappdemo             I  updater::updater: Reporting launch start.
2024-09-06 17:43:11.744  8489-8489  flutter                 com.example.addtoappdemo             I  [INFO:flutter/shell/common/shorebird/shorebird.cc(184)] Starting Shorebird update
2024-09-06 17:43:11.745  8489-8840  flutter                 com.example.addtoappdemo             I  updater::network: Sending patch check request: PatchCheckRequest { app_id: "8928d6c7-0043-4c16-ab6e-0981fb9bc494", channel: "stable", release_version: "1.0.0+2", platform: "android", arch: "x86_64" }
2024-09-06 17:43:11.769  8489-8489  flutter                 com.example.addtoappdemo             I  updater::updater: Reporting successful launch.
2024-09-06 17:43:12.839  8489-8840  flutter                 com.example.addtoappdemo             I  updater::updater: Patch check response: PatchCheckResponse { patch_available: false, patch: None, rolled_back_patch_numbers: Some([]) }
2024-09-06 17:43:12.839  8489-8840  flutter                 com.example.addtoappdemo             I  updater::updater: Update thread finished with status: No update
2024-09-06 17:45:14.510  8489-8489  flutter                 com.example.addtoappdemo             I  updater::updater: Reporting successful launch.
2024-09-06 17:45:26.311  8489-8489  flutter                 com.example.addtoappdemo             I  updater::updater: Reporting successful launch.
2024-09-06 17:46:05.357  8999-9024  flutter                 zygote64                             E  updater::updater: Update failed: This app reports version 1.0.0+2, but the binary is different from the version 1.0.0+2 that was submitted to Shorebird.
                                                                                                    
                                                                                                    Caused by:
                                                                                                        Update rejected: hash mismatch. Update was downloaded but contents did not match the expected hash. This is most often caused by using the same version number with a different app binary. Path: "/data/user/0/com.example.addtoappdemo/code_cache/shorebird_updater/downloads/1.full", expected: 298ad79d4d0284ab9cd2f6cbd0c8b94bedb7d6e5459e66c90b9b86f11ae9df92, got: f37a6a90c5391fdc71d42afa93d83a4e8165c31055b4d0b7ee684c93adce0d19

`

@sunragav
Copy link

sunragav commented Sep 6, 2024

I followed the instructions exactly as mentioned here.
The following are the commands I ran:
PS C:\Users\sunragav\Downloads\shorebird-samples-main\add_to_app\my_flutter_module> shorebird release aar --release-version 1.0.0+2
✓ Downloading patch... (0.1s)
✓ Extracting patch... (0.1s)
✓ Fetching apps (0.3s)
✓ Downloading patch... (48ms)
✓ Extracting patch... (38ms)
✓ Built aar with Flutter 3.24.2 (9239d8659d) (13.9s)
✓ Fetching releases (0.2s)

🚀 Ready to create a new release!

📱 App: my_flutter_module (8928d6c7-0043-4c16-ab6e-0981fb9bc494)
📦 Release Version: 1.0.0+2
🕹️ Platform: android
🐦 Flutter Version: 3.24.2 (9239d8659d)

Would you like to continue? (y/N) Yes
✓ Fetching releases (0.2s)
✓ Creating release (0.5s)
✓ Updating release status (0.2s)
✓ Creating artifacts (63ms)
✓ Creating artifacts (6.0s)
✓ Updating release status (1.8s)

✅ Published Release 1.0.0+2!

Your next steps:

  1. Add the aar repo and Shorebird's maven url to your app's settings.gradle:

Note: The maven url needs to be a relative path from your settings.gradle file to the aar library. The code below assumes your Flutter module is in a sibling directory of your Android app.


dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
+       maven {
+           url '../my_flutter_module/release'
+       }
+       maven {
-           url 'https://storage.googleapis.com/download.flutter.io'
+           url 'https://download.shorebird.dev/download.flutter.io'
+       }
    }
}


2. Add this module as a dependency in your app's build.gradle:
dependencies {
  // ...
  releaseImplementation 'com.example.my_flutter_module:flutter_release:1.0'
  // ...
}

To create a patch for this release, run shorebird patch --platforms=aar --release-version=1.0.0+2
PS C:\Users\sunragav\Downloads\shorebird-samples-main\add_to_app\my_flutter_module> shorebird patch --platforms=aar --release-version=1.0.0+2
✓ Downloading patch... (0.2s)
✓ Extracting patch... (0.1s)
✓ Fetching apps (0.3s)
✓ Fetching releases (0.2s)
✓ Fetching aar artifact (0.2s)
✓ Downloading aar (1.1s)
✓ Downloading patch... (31ms)
✓ Extracting patch... (17ms)
✓ Building patch with Flutter 3.24.2 (9239d8659d) (11.5s)
✓ Verifying patch can be applied to release (12ms)
✓ Fetching release artifacts (0.7s)
✓ Downloading release artifacts (2.5s)
✓ Creating artifacts (0.7s)

🚀 Ready to publish a new patch!

📱 App: my_flutter_module (8928d6c7-0043-4c16-ab6e-0981fb9bc494)
📦 Release Version: 1.0.0+2
🕹️ Platform: android [arm32 (1.15 KB), arm64 (1.06 KB), x86_64 (1.05 KB)]
🟢 Track: Production

Would you like to continue? (y/N) Yes
✓ Creating patch (1.9s)
✓ Uploading artifacts (1.6s)
✓ Fetching channels (0.2s)
✓ Promoting patch to stable (0.2s)

✅ Published Patch 1!

The patch is uploaded correctly. But I don't know what could cause the patch difference.

image

@bryanoltman
Copy link
Contributor

Was able to reproduce this locally. After looking through our CLI code, nothing is jumping out at me as obviously wrong. I'm going to poke around in our updater code later to see if there are any clues there.

@bryanoltman
Copy link
Contributor

It appears as though the hash of the libapp.so on my machine is different than what is ending up on the device:

My machine:

bryanoltman@moltman ~/shorebirdtech/samples/add_to_app/my_flutter_module/build/host/outputs/repo/com/example/my_flutter_module/flutter_release/1.0/flutter_release-1.0/jni/arm64-v8a (main) ✗
⑆ sha256sum libapp.so
c82d982db07c024ca3fcbb8c683b8c351ffcbee4b4ef3292cb214b98ed8150be  libapp.so

The emulator:

root@emulator64_arm64:/data/app/~~jtJ_CjQLdKUAdm5QwnPMAQ==/com.example.addtoappdemo-BT2x4Cre0m48aBctRRiZEw==/lib/arm64-v8aBctRRiZEw==/lib/arm64-v8a$ sha256sum libapp.so
7dbfed170bd60bdb73d393ab80ea05aefe67b504531d059ad8db63587da9acef  libapp.so

On the bright side, these are the numbers I see in the error message after creating a patch with no changes, so that part looks like it's working correctly.

Error message:

2024-09-06 16:45:53.016  2391-2424  flutter                 com.example.addtoappdemo             E  updater::updater: Update failed: This app reports version 1.0.0+8, but the binary is different from the version 1.0.0+8 that was submitted to Shorebird.                                                                                                    
 Caused by:
   Update rejected: hash mismatch. Update was downloaded but contents did not match the expected hash.
This is most often caused by using the same version number with a different app binary.
Path: "/data/user/0/com.example.addtoappdemo/code_cache/shorebird_updater/downloads/1.full"
expected: c82d982db07c024ca3fcbb8c683b8c351ffcbee4b4ef3292cb214b98ed8150be
got:      7dbfed170bd60bdb73d393ab80ea05aefe67b504531d059ad8db63587da9acef

@bryanoltman
Copy link
Contributor

Screenshot 2024-09-06 at 4 59 54 PM

The differences between the two seem to be small and isolated to the end of the file.

@bryanoltman
Copy link
Contributor

Screenshot 2024-09-06 at 5 12 25 PM

The string table appears to be different as well

@bryanoltman
Copy link
Contributor

On a lark, I tried reproducing with an older version of Flutter (3.22.3), and the issue reproduces there as well.

@bryanoltman
Copy link
Contributor

Workaround

Setting the project's targetSdk to 33 in the app's build.gradle resolves this issue.

Obviously, we should support newer versions of android as well, and Flutter seems to have been targeting 34 for a little while now.

@sunragav
Copy link

sunragav commented Sep 6, 2024

I have the targetSdk set to 33. But compileSdk to 34. I still have the same issue

@bryanoltman
Copy link
Contributor

This should be fixed by updating your app's build.gradle like so:

    buildTypes {
        release {
            // ...
            // Add this line
            packaging.jniLibs.keepDebugSymbols.add("**/libapp.so")
        }
    }

Please reopen if this does not work.

@sunragav
Copy link

@bryanoltman Thanks a lot for solving this. Works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants