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

fix: resolve crash on Play Store version #894

Closed
wants to merge 2 commits into from

Conversation

anhappdev
Copy link
Collaborator

@anhappdev anhappdev commented Jun 22, 2024

@anhappdev anhappdev requested a review from a team as a code owner June 22, 2024 02:59
Copy link

github-actions bot commented Jun 22, 2024

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@anhappdev anhappdev marked this pull request as draft June 22, 2024 03:18
@mohitmundhragithub
Copy link
Contributor

@anhappdev do you want me to try out this version of the app from the playstore?

@anhappdev
Copy link
Collaborator Author

@anhappdev do you want me to try out this version of the app from the playstore?

Yes. Please.

@mohitmundhragithub
Copy link
Contributor

@anhappdev do you want me to try out this version of the app from the playstore?

Yes. Please.

i see the play store version was updated on 18th June. Can you push the apk with these fixes as well to playstore?

@anhappdev

This comment was marked as outdated.

@mohitmundhragithub

This comment was marked as outdated.

@anhappdev
Copy link
Collaborator Author

@mohitmundhragithub Ok. Thanks for the feedback. Is the crash occurred on any Android devices with the QTI backend or only on the Galaxy S23?

@mohitmundhragithub
Copy link
Contributor

mohitmundhragithub commented Jun 24, 2024

I tried the apk on another device (Samsung galaxy tab s8+, SD8Gen1). It crashes there as well.

Sadly I am still unable to upload the device logs... but following up with IT team internally.

@freedomtan
Copy link
Contributor

@anhappdev please add [email protected] for internal testing

@mohitmundhragithub
Copy link
Contributor

Galaxy S23 Ultra.txt

Hi Anh,

Finally able to upload the logs. Can you please check?

@anhappdev
Copy link
Collaborator Author

Galaxy S23 Ultra.txt

Hi Anh,

Finally able to upload the logs. Can you please check?

It looks like the same issue we have here:
#859 (comment)

For this issue, I still cannot find a solution.

@mohitmundhragithub
Copy link
Contributor

mohitmundhragithub commented Jul 2, 2024

actually the symptom (final log) for failure is same. But the reason would be different. Seems like when uploading to playstore, the DSP access gets denied but not otherwise.

Seems like we are missing some checks when uploading to playstore?

@freedomtan
Copy link
Contributor

freedomtan commented Jul 2, 2024

Let's see if we can

  1. aab (in the CI) -> apk
  2. try to get technical support from Play Store?
  3. @freedomtan to try on MTK devices (or Samsung devices).

@freedomtan
Copy link
Contributor

Works on

  • MTK devices: both newer .dla and older TFLite Neuron Delegate work
  • Pixel 8 Pro: works

@AhmedTElthakeb and @Mostelk: please check if the Play Store apk works on Exynos devices.

@anhappdev
Copy link
Collaborator Author

I opened a support ticket on Google Play, but they don't provide support for this kind of issue. Here is their answer:

Thanks for reaching out to Google Play Technical Support.
Although I’m happy to answer any questions about managing your apps on the Google Play Console, our team isn’t trained to provide technical support for app development questions.

@freedomtan
Copy link
Contributor

@AhmedTElthakeb will try to run the in Play Store one w/ SELinux disabled (if that works, we are almost sure that there is some kind of permission setting problem).

Copy link

@anhappdev
Copy link
Collaborator Author

I don't know if it makes a different, but I deployed the app to the closed testing channel.
Compared to the internal testing channel, a user still needs to be invited to join the testing program (so it's not public), but the app is reviewed by Google on every release, so I hope maybe the app will not be classified as "untrusted app" anymore.

@mohitmundhragithub @AhmedTElthakeb Can you please test the app (v4.1.0 (164)) again:
https://play.google.com/apps/testing/org.mlcommons.android.mlperfbench

@mohitmundhragithub
Copy link
Contributor

I don't know if it makes a different, but I deployed the app to the closed testing channel. Compared to the internal testing channel, a user still needs to be invited to join the testing program (so it's not public), but the app is reviewed by Google on every release, so I hope maybe the app will not be classified as "untrusted app" anymore.

@mohitmundhragithub @AhmedTElthakeb Can you please test the app (v4.1.0 (164)) again: https://play.google.com/apps/testing/org.mlcommons.android.mlperfbench

didn't work on GS23Ultra.

@freedomtan
Copy link
Contributor

on rooted device, adb shell then setenfoce 0, and adb shell setenforce 0 (meaning disabling all the permission checks by the SELinux). @mohitmundhragithub and @AhmedTElthakeb

@anhappdev anhappdev added this to the v4.1 milestone Oct 22, 2024
@mohitmundhragithub
Copy link
Contributor

I think I found one workaround for the issue.

For QTI backend, if we push few of the dependent libs to the "files" folder, instead of packing it in the apk's "lib" folder, then the issue gets resolved for qti backend.
I want to try it out for the app to be downloaded from the play store.

@anhappdev, i will push a change to this PR... can you please help to push the aab file to the playstore? i can test with that.

@anhappdev anhappdev closed this Oct 24, 2024
@anhappdev anhappdev force-pushed the anh/debug-play-store-version branch from 72e6ba1 to fad36c1 Compare October 24, 2024 09:56
@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2024
@mlcommons mlcommons unlocked this conversation Oct 24, 2024
@anhappdev

This comment was marked as outdated.

@anhappdev

This comment was marked as outdated.

@freedomtan
Copy link
Contributor

@mohitmundhragithub The link is in this comment: #893 (comment)

Please noted the “internaltest” in the url.

@mohitmundhragithub I am told the one from Play Store works on a Samsung S24+ (8 Gen 3 inside).

@mohitmundhragithub
Copy link
Contributor

@mohitmundhragithub The link is in this comment: #893 (comment)
Please noted the “internaltest” in the url.

@mohitmundhragithub I am told the one from Play Store works on a Samsung S24+ (8 Gen 3 inside).

That's surprising. Not sure how that could happen. The apk when sideloaded should work fine, but not the app from play store.

@mohitmundhragithub
Copy link
Contributor

mohitmundhragithub commented Oct 25, 2024

@mohitmundhragithub The link is in this comment: #893 (comment)

Please noted the “internaltest” in the url.

Thanks a lot @anhappdev. This link worked fine. I am able to download the updated app now.

The workaround that i had worked fine. Now we need to have a proper fix for the same.
Basically, with Android SDK 29 and onwards, the app can't use few libs from the /data/.../mlperf/libs folder. Workaround is to have the lib file present in the /sdcard/Android/data/...mlperfbench/files folder.

My suggestion is,

  1. Add a field in the backend settings, and list the required dependent library.
  2. We need to host the required dependent library somewhere, which the app downloads and saves in "/sdcard/Android/data/org.mlcommons.android.mlperfbench/files".
  3. The above path needs to be known to the backend. So, either we can have a fixed path or pass the dynamic download location path to the backend, so that the backend can use this path. For QTI backend, we set the env variable "ADSP_LIBRARY_PATH" to do this.

@mohitmundhragithub
Copy link
Contributor

@mohitmundhragithub The link is in this comment: #893 (comment)
Please noted the “internaltest” in the url.

Thanks a lot @anhappdev. This link worked fine. I am able to download the updated app now.

The workaround that i had worked fine. Now we need to have a proper fix for the same. My suggestion is,

  1. Add a field in the backend settings, and list the required dependent library.
  2. We need to host the required dependent library somewhere, which the app downloads and saves in "/sdcard/Android/data/org.mlcommons.android.mlperfbench/files".
  3. The above path needs to be known to the backend. So, either we can have a fixed path or pass the dynamic download location path to the backend, so that the backend can use this path. For QTI backend, we set the env variable "ADSP_LIBRARY_PATH" to do this.

NB: the other minSDK 30 issue also gets resolved with this workaround.

@mohitmundhragithub
Copy link
Contributor

mohitmundhragithub commented Oct 28, 2024

@anhappdev, @freedomtan I have pushed the changes to download the libs directory as listed in the backend setting. Can you please review once?
This is a potential fix for the play store issue as well as the minSDKVersion issue.

After this change, we will need a way to host the required .so files somewhere, either in github or somewhere else. The backends will need to update the required files in the settings (just like the model files).

@mohitmundhragithub mohitmundhragithub requested a review from a team October 28, 2024 11:19
Copy link

@anhappdev
Copy link
Collaborator Author

The workaround that i had worked fine. Now we need to have a proper fix for the same. Basically, with Android SDK 29 and onwards, the app can't use few libs from the /data/.../mlperf/libs folder. Workaround is to have the lib file present in the /sdcard/Android/data/...mlperfbench/files folder.

My suggestion is,

  1. Add a field in the backend settings, and list the required dependent library.
  2. We need to host the required dependent library somewhere, which the app downloads and saves in "/sdcard/Android/data/org.mlcommons.android.mlperfbench/files".
  3. The above path needs to be known to the backend. So, either we can have a fixed path or pass the dynamic download location path to the backend, so that the backend can use this path. For QTI backend, we set the env variable "ADSP_LIBRARY_PATH" to do this.

Another solution is to download the libs in the build step and put them in the same place where the native libs are:

flutter_android_libs_folder=flutter/android/app/src/main/jniLibs/arm64-v8a
.PHONY: flutter/android/libs/copy
flutter/android/libs/copy:
rm -rf ${flutter_android_libs_folder}
mkdir -p ${flutter_android_libs_folder}
@# macos doesn't support --target-directory flag
cp -f \
${backend_tflite_android_files} \
${backend_mediatek_android_files} \
${backend_pixel_android_files} \
${backend_qti_android_files} \
${backend_samsung_android_files} \
${BAZEL_LINKS_PREFIX}bin/flutter/cpp/flutter/libbackendbridge.so \
${flutter_android_libs_folder}
@# macos doesn't support --recursive flag
chmod -R 777 ${flutter_android_libs_folder}

More info at https://developer.android.com/ndk/guides/abis#am

@freedomtan
Copy link
Contributor

freedomtan commented Oct 29, 2024

The cause of this issue is that the App cannot access some of the .so libraries in devices (e.g., in either /system or /vendor partition).

Why this restriction: there is some kind of SELinux rule(s) which prevent libraries not listed in a white list to be accessed by an App from the Play Store.

@mohitmundhragithub's solution is to copy the libraries the app needs to the App's library directory. However, I think this is a hack.

Long term solution: fix the "whitelist".

debugging hint: ld debug options (Android specific) to get more verbose ld outputs (which may help find the libraries been accessed), @freedomtan to find the options from Android documentation site

@mohitmundhragithub
Copy link
Contributor

The workaround that i had worked fine. Now we need to have a proper fix for the same. Basically, with Android SDK 29 and onwards, the app can't use few libs from the /data/.../mlperf/libs folder. Workaround is to have the lib file present in the /sdcard/Android/data/...mlperfbench/files folder.

My suggestion is,

  1. Add a field in the backend settings, and list the required dependent library.
  2. We need to host the required dependent library somewhere, which the app downloads and saves in "/sdcard/Android/data/org.mlcommons.android.mlperfbench/files".
  3. The above path needs to be known to the backend. So, either we can have a fixed path or pass the dynamic download location path to the backend, so that the backend can use this path. For QTI backend, we set the env variable "ADSP_LIBRARY_PATH" to do this.

Another solution is to download the libs in the build step and put them in the same place where the native libs are:

flutter_android_libs_folder=flutter/android/app/src/main/jniLibs/arm64-v8a
.PHONY: flutter/android/libs/copy
flutter/android/libs/copy:
rm -rf ${flutter_android_libs_folder}
mkdir -p ${flutter_android_libs_folder}
@# macos doesn't support --target-directory flag
cp -f \
${backend_tflite_android_files} \
${backend_mediatek_android_files} \
${backend_pixel_android_files} \
${backend_qti_android_files} \
${backend_samsung_android_files} \
${BAZEL_LINKS_PREFIX}bin/flutter/cpp/flutter/libbackendbridge.so \
${flutter_android_libs_folder}
@# macos doesn't support --recursive flag
chmod -R 777 ${flutter_android_libs_folder}

More info at https://developer.android.com/ndk/guides/abis#am

we have already been doing this. all the .so files are already part of the libs/abi folder. It used to work till now. however from, sdk 29 and above, there is an additional W^X restrictions.

there are a few libs required to access npu (suffixed skel.so), which have become inaccessible, from android 29 onwards.

i think there is similar restrictions for samsung stack as well.

when we copy the libs to files folder, the app is able to access those. this change facilitates that.

if we can find a way to pack these libs during build time to the files folder, then we dont need to download them separately.

@anhappdev
Copy link
Collaborator Author

anhappdev commented Oct 29, 2024

we have already been doing this. all the .so files are already part of the libs/abi folder. It used to work till now. however from, sdk 29 and above, there is an additional W^X restrictions.

there are a few libs required to access npu (suffixed skel.so), which have become inaccessible, from android 29 onwards.

Really? Did you try copy the *skel.so file to ${flutter_android_libs_folder} and test the app. All *.so files in ${flutter_android_libs_folder} should be executable else the native backends would not work.

Updated: I just checked the unified APK and the *skel.so files really already there. It doesn't make sense that it not works.

Execution of files from the writable app home directory is a W^X violation. Apps should load only the binary code that's embedded within an app's APK file.

https://developer.android.com/about/versions/10/behavior-changes-10#execute-permission

@anhappdev
Copy link
Collaborator Author

Did we try to specify all the libs in the AndroidManifest.xml with either uses-native-library or uses-library tag?
I don't know if it works, but maybe it's worth a try.

@anhappdev
Copy link
Collaborator Author

anhappdev commented Oct 29, 2024

@mohitmundhragithub
Copy link
Contributor

mohitmundhragithub commented Oct 29, 2024

Did we try to specify all the libs in the AndroidManifest.xml with either uses-native-library or uses-library tag?
I don't know if it works, but maybe it's worth a try.

yes. already tried this earlier.
androidmanifest.xml is meant for accessing any libs present in system's lib folder.

@mohitmundhragithub
Copy link
Contributor

mohitmundhragithub commented Oct 29, 2024

tried it. didnt work on galaxy s23 ultra.

@mohitmundhragithub
Copy link
Contributor

there is a IPC involved when trying to invoke the skel files. may be thats resulting in this behaviour.

same issue is seen for both playstore version and for apps with minsdkversion >= 29

@anhappdev
Copy link
Collaborator Author

Ok. Let move on with @mohitmundhragithub's solution: let the app download the *.so files.
But I will do it a bit different. I will push some new commits later.

@anhappdev
Copy link
Collaborator Author

anhappdev commented Nov 1, 2024

@mohitmundhragithub Did we try to set android:extractNativeLibs="true" in the AndroidManifest.xml?

  1. Set android:extractNativeLibs="true" as in https://stackoverflow.com/a/64792194
  2. Set android.bundle.enableUncompressedNativeLibs=false as in https://stackoverflow.com/a/56551499

@mohitmundhragithub
Copy link
Contributor

@mohitmundhragithub Did we try to set android:extractNativeLibs="true" in the AndroidManifest.xml?

  1. Set android:extractNativeLibs="true" as in https://stackoverflow.com/a/64792194
  2. Set android.bundle.enableUncompressedNativeLibs=false as in https://stackoverflow.com/a/56551499

the apk uploaded to play store (252) using PR #893 seems to resolve the play store issue at least on Galaxy S23 ultra.
Would be worthwhile to check if this can resolve the minSDKVersion 29 issue as well or not.

@anhappdev
Copy link
Collaborator Author

Would be worthwhile to check if this can resolve the minSDKVersion 29 issue as well or not.

Yes. It also resolved the issue with QTI backend in the PR #859.

@anhappdev
Copy link
Collaborator Author

@anhappdev anhappdev closed this Nov 12, 2024
@anhappdev anhappdev deleted the anh/debug-play-store-version branch November 12, 2024 06:34
@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test Android Play Store version
3 participants