beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.48k stars 353 forks source link

Inconsistent behaviour between Android emulator on different platforms #1779

Closed JaxkDev closed 2 months ago

JaxkDev commented 2 months ago

Describe the bug

So on my Macbook Air M1 I made some android specific functions to take videos (this works in both environments, and uses MediaStore.ACTION_VIDEO_CAPTURE)

However when I made the choosing pictures and videos from gallery it worked perfectly on my mac emulators, using MediaStore.ACTION_PICK_IMAGES.

When then testing it on windows, It comes up saying ACTION_PICK_IMAGES doesn't exist...

Steps to reproduce

Code used to 'pick an image' from the phones gallery:

from android.content import Intent # type: ignore
from android.provider import MediaStore # type: ignore

def file_chosen(code, data):
    print("tmp")

intent = Intent(MediaStore.ACTION_PICK_IMAGES)
intent.setTypeAndNormalize("image/*") #Takes a MIME type to filter the users choices
self.app._impl.start_activity(intent, on_complete=file_chosen)

Expected behavior

The choose a picture/video pop up to show, as shown below.

Screenshots

Expected Result (As on Mac M1):

Screenshot 2024-05-06 at 21 12 31

Actual Result (As on Win11 machine):

Screenshot 2024-05-06 at 21 13 30

(Notification showing it 'would' crash)

if(not hasattr(MediaStore, 'ACTION_PICK_IMAGES')):
    self.app.main_window.error_dialog("Unsupported Device", "Unfortunately this device does not allow access to gallery.\nTo test this functionality use the default emulator that comes as standard.")

Environment

Working Version:

Not Working Version:

Logs

Working Macbook Air log: briefcase.2024_05_06-21_20_58.run.log

Not Working Windows log: briefcase.2024_05_06-21_21_39.run.log

Additional context

Attempted updating android sdk as suggested in discord, no updates available.

mhsmith commented 2 months ago

The ACTION_PICK_IMAGES documentation says it was added in API level 33, which only came out in late 2022. If you want your app to be usable across a wide range of devices, you should probably use a different API.

Assuming the emulator on both machines was created by Briefcase, you probably created one of them with an older version of Briefcase, and it therefore uses an older API level. Try upgrading Briefcase, then run briefcase run android and select "Create a new Android emulator".

JaxkDev commented 2 months ago

Both use the default of Pixel 3a with API 34 :(

Ironically the issue emulator is the newest made one but they both are the same as far as I know

mhsmith commented 2 months ago

Are you absolutely certain? The top screenshot has rounded corners and no navigation buttons at the bottom, while the bottom screenshot has square corners and navigation buttons, which suggests it's older. Check the Android version number in "Settings > About phone".

JaxkDev commented 2 months ago

I shall check now, I know the top is def 34 confirmed in android studio, havent got android studio installed on windows so went off name which said 34

May take a few to check apologies.

JaxkDev commented 2 months ago

Interesting while i was setting up again,

It seems this might all have been because of a stupid typo in the android sdk.

(Running briefcase run android with absolutely nothing on system)

Obviously you have to accept a load of tos and it installs the sdk emulator etc. And the default device it lists:

Select device:

  1) @INFO    | Storing crashdata in: C:\Users\COMPUT~1\AppData\Local\Temp\\AndroidEmulator\emu-crash-34.2.13.db, detection is enabled for process: 14724 (emulator)
  2) @Pixel_3a_API_34_extension_level_7_x86_64 (emulator)
  3) Create a new Android emulator

> 2

In future, you can specify this device by running:

    $ briefcase run android -d "@Pixel_3a_API_34_extension_level_7_x86_64"

However it then goes to download I assume the API 30 based off this next line:

[android_sdk] Downloading the 'system-images;android-30;google_apis_playstore;x86_64' Android system image...

So i do have a feeling it is indeed the wrong API

JaxkDev commented 2 months ago
Screenshot 2024-05-07 at 16 10 17

@mhsmith

JaxkDev commented 2 months ago
Screenshot 2024-05-07 at 16 13 46

Yup, apologies everyone.

Issue was just a stupid type from Android...

mhsmith commented 2 months ago

I'm not sure what the root cause of this could be. Did you create this emulator with Android Studio? Maybe you changed its API level at some point but the name remained the same.