OK @Pei116, here goes the full explanation :)
Look at https://github.com/monero-project/monero/blob/master/src/crypto/slow-hash.c#L1127
By default, the program use the stack :
> uint8_t long_state[MEMORY];
`MEMORY` is a define holding the size of the scratchpad, i.e. 2MB. On android, the default stack size is 1MB (when it’s not the main thread), hence the crash.
So the first natural thing to do is to increase the stack size (like suggested by hyc and mooo). Except sometimes you simply cannot control that parameter, like monero-wallet-gui (It’s done in Qt internals and clang does not support `-Wl,—stack`).
So if we can’t use the `stack`, we have to use the `heap`.
That’s what the define `FORCE_USE_HEAP` does. By activating it, the program will use `malloc` for allocating the memory of the variable `long_state`.
Now to answer your question, you have multiple ways to activate this flag: you can either:
— add the define flag to the cmake command, e.g. `cmake -DFORCE_USE_HEAP=1 ….`
— make sure that `ANDROID` and `BUILD_GUI_DEPS` are defined
— modify `src/crypto/CMakeLists.txt` to include `add_definitions(-DFORCE_USE_HEAP=1)` on the conditions that suits you
— modify `src/crypto/slow-hash.c` to always use `malloc` (most uggly solution, but might be usefull to make sure that this is indeed the problem, before start debugging cmake :sweat_smile: )