Closed qinantong closed 3 months ago
There are two problems with the approach you've described.
The first problem is that you're using relative paths. "resources/screenshot.png" isn't an absolute location on your filesystem; it's a relative location that will be anchored relative to the current working directory. The current working directory for a BeeWare app is the user's home directory. If you want to reference files in your app, you need to provide an absolute path. Toga does this implicitly - when you describe an icon being in resources/icons
, Toga does the work to turn that into an absolute path relative to the app's location. If you're constructing paths yourself, you need to provide the full absolute path. On Android, there's the additional complication that you need to pick a location that you can actually read and/or write to. Android's filesystem doesn't allow arbitrary file system access; there are only some locations that are available for reading and writing.
The second problem is that you're describing that you want to use pyautogui on Android. That won't work, because pyautogui doesn't work an Android.
I'm going to close this ticket because you've opened it against the BeeWare project website, and this isn't an issue with the website. If you need additional support getting your app to work, please open a discussion topic on the Briefcase respository.
@qinantong: Although you're asking about Android: this log clearly shows that you're running the app on Windows using briefcase dev
. You might want to look at the mobile tutorial to learn how to run an app on a phone.
Android's filesystem doesn't allow arbitrary file system access; there are only some locations that are available for reading and writing.
See the Toga paths documentation for advice on which locations you should use.
The first problem is that you're using relative paths
It looks like the code is actually constructing an absolute path, but in a directory that doesn't exist yet.
The current working directory for a BeeWare app is the user's home directory.
Android doesn't have a user home directory, so the working directory is the root directory on every device I've seen, though I've never seen this officially documented. The paths documentation already says that the working directory is unpredictable.
Describe the bug
i want write an andorid app to run my game script.the script need to scrennshot and load some pictures.but android and windows's filesystem is not the same,so the code can run on my laptop cant open on my phone.i've read the doc and found resources folder๏ผthe REDME sad "Put any application resources (e.g., icons and resources) here;they can be referenced in code as 'resources/filename'".But when the app run,it actually create a new python envirment in system drive c and can't recognize my picture in the folder resources.i dont know what to do.some erro message like "FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\tqn\resources\screenshot.png'".and i totally cat not open my app on android phone.
Steps to reproduce
Expected behavior
i use pyautogui in my game script, i expect it can screnshot on my phone and the app can open and load my resources pictures.Anywawy, i hope my game script run on my android phone.
Screenshots
No response
Environment
Logs
Additional context
No response