#### Note on authorship and language This text was translated into English and structured with the assistance of ChatGPT. The author is not a native English speaker and may struggle with written technical English; any wording issues are unintentional. #### Description This merge request is an experimental attempt to bring wineandroid.drv back to a minimally functional state on Android 7.1.x. It is primarily intended as a discussion starter rather than a final or polished solution. The current Android support appears to have bit-rotted over time, likely due to a combination of internal contract changes in Wine, toolchain and NDK evolution, and the absence of continuous Android testing. The changes proposed here aim to re-establish a working baseline and make the regressions more concrete and easier to reason about. At the moment, all changes are provided as a single patch. This is intentional: until at least one of the proposed changes is confirmed as a valid or acceptable fix, the patchset is kept consolidated to simplify iteration. Once individual changes are reviewed or agreed upon, the history can be rewritten (via force-push) to split them into logical, self-contained commits. #### Test environment and context All testing so far was performed on Android 7.1.2 x86 images from the Android-x86 project. The primary target is i386 Wine running on x86 Android userspace. Because no up-to-date official Android build scripts were available, Wine was built using Termux as an unsupported but convenient environment for rapid testing. The Java part (WineActivity and related glue code) was built with `sharedUserId = com.termux` purely for convenience (filesystem access and faster prototyping). **Termux is explicitly not considered a supported environment and is mentioned only to provide context for the testing setup.** The build uses Android NDK r29. Since the last known functional Android Wine builds, the NDK and linker behavior have changed multiple times, including symbol visibility and relocation handling. These changes appear to have directly affected several failure modes described below. There is also a known issue with wine-preloader producing excessively large binaries under recent toolchains; a workaround exists but is not included here and is mentioned only as additional context. #### Scope of changes This merge request currently modifies only Android-specific code: - `wineandroid.drv` (native code and Java glue, including WineActivity) - android-only paths in `dlls/ntdll/unix/loader.c` No non-Android platforms are affected. #### Summary of resolved issues 1. `virtual_alloc_first_teb` failure Wine frequently failed early during startup with: ``` err:virtual:virtual_alloc_first_teb wine: failed to map the shared user data: c0000018 ``` This failure was not observed on older Wine versions. It appears to be related to JNI interaction occurring too early during initialization, interfering with allocation of the shared user data region at the required fixed address. This was resolved by moving the call to `virtual_init()` earlier in `wine_init_jni()`, before JNI-related activity begins. 2. Missing exported JNI symbols The symbols `java_vm`, `java_object`, and `java_gdt_sel` were no longer visible when accessed via `dlopen`/`dlsym`. This appears to be a consequence of newer toolchain and linker behavior. The issue was resolved by explicitly exporting these symbols using `DECLSPEC_EXPORT`. 3. Desktop thread assertion during startup Wine aborted with the following assertion: ``` dlls/wineandroid.drv/window.c:519: int wait_events(int): assertion "GetCurrentThreadId() == desktop_tid" failed ``` The failure happens because `pCreateDesktop()` is now invoked before `pCreateWindow()`, while the existing code expected `desktop_tid` to be set during `pCreateWindow()`. As a result, the event waiting path may execute before `desktop_tid` is initialized. This was addressed by moving `init_event_queue()` and `start_android_device()` from `pCreateWindow()` into `pCreateDesktop()`, ensuring the event queue and device startup occur before `wait_events()` is used. 4. Recursive desktop recreation The change described above introduced a new problem: `create_desktop_window()` could be triggered repeatedly. Each Java-side content window creation/layout initialization caused additional resolution/configuration change notifications, which in turn could cause repeated desktop window recreation. This was mitigated by changing the Java/native glue so that when a window/view is being created, the code explicitly checks whether the target is the desktop window and passes this information to Java as a flag. This avoids triggering repeated content-window initialization paths during desktop recreation. 5. WineAndroid device path change Opening the device using `\\.\WineAndroid` no longer works. Switching to `\Device\WineAndroid` resolved the issue. The fix itself is simple but required for basic functionality. 6. Rendering stalls and USER lock assertion Rendering occasionally stalled or crashed with: ``` err:system:user_check_not_lock BUG: holding USER lock ``` Adding TRACE statements often caused the issue to disappear, making it difficult to debug and reproduce reliably. After extensive experimentation, it was discovered that inserting a full memory barrier: ``` __sync_synchronize(); ``` at a specific point makes the issue reliably disappear in the tested setup. This suggests a race or memory visibility/ordering problem. At this time it is unclear whether the root cause is an internal behavioral change in Wine, NDK toolchain/codegen changes, or some other interaction specific to the Android 7.1.x environment. The current change should be treated as a workaround and a starting point for further investigation rather than a definitive fix. #### Remaining issues - Window focus handling is partially broken: windows receive focus on click, but are not always raised to the front. - Despite the available desktop area being larger (e.g. 1024x696), Wine consistently reports a display resolution of 800x600. #### Limitations Wine on Android stopped functioning entirely starting with Android 8. As a result, all testing so far has been limited to Android 7.1.x. No claims are made about behavior on newer Android versions. #### Out of scope This merge request intentionally does not attempt to: - redesign IPC mechanisms - introduce new Android integration models - address Android 8+ compatibility The sole goal is to re-establish a minimally working baseline on Android 7.1.x and enable informed discussion about what regressed and how to proceed. **This is my first contribution to Wine, and I am aware that some parts of this analysis or implementation may be flawed. I would be grateful for any review comments or suggestions.** -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9874