Android support experiments #549
LeonMatthesKDAB
started this conversation in
Show and tell
Replies: 2 comments 4 replies
-
Was the import scanner required for |
Beta Was this translation helpful? Give feedback.
3 replies
-
How did you get around the android permissions? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I've recently been able to get the Markdown-combine app ( #371 ) compiling and running for Android!
There were a few issues along the way, but none caused by CXX-Qt itself actually.
I think for now we shouldn't state this constitutes "official Android support", but if you're determined, you should be able to get this to work in a day or two worths of work.
TLDR: I've attached an example config here: CMakeLists.txt
Setting up Qt Creator for Android cross-compilation
Bascially, I followed this guide.
I did have to use Qt Installer to install Qt again with full Android support, as the one from my package manager (Fedora w/ dnf) didn't include everything necessary.
Also, I used the Android SDK & NDK provided by Qt Creator, as it wouldn't accept the one I already had installed.
Do not require QQmlImportScanner
For some reason requiring CMake to find QQmlImportScanner didn't work, so I just removed it.
Honestly don't know why it was needed in the first place.
Maybe someone can shine a light on that.
Figure out the right CMake flags for corrosion to fix Rust compilation errors
For some reason the way we usually set up QMake wasn't working for my case.
I believe this has something to do with the two versions of Qt that are now installed on my system.
I.e. this code:
Instead, I had to use the environment variables provided by Qt Creator (see the
Projects
tab after opening the project in Qt Creator):I also had to point the cxx_build crate to the right AR executable, see: https://stackoverflow.com/questions/69945638/do-rust-and-cargo-1-56-simply-not-work-with-android-ndk-r23-without-binutils
And something required C++17, so I enabled that as well.
Use Corrosion 0.4-beta2 to fix linker errors
Corrosion hard-codes a few linker flags for rustc to link to Rusts stdlib.
However, these flags are simply not correct for Android compilation.
In Corrosion 0.4, this has actually already been fixed.
So just update corrosion to the right version (still in beta at the time of writing).
Use
qt_add_executable
, instead ofadd_executable
Otherwise, Qt doesn't know what to package as the "application".
We should consider making this the default for all Cxx-Qt examples!
Profit
The app now builds and runs on my Galaxy S9+ under Android 10 🥳
Rust's
std::fs
module has a few issues accessing files that are outside of my app directory, but that's really got to do with Androids restrictive permissions, and is not an issue with the build itself.Simply using
println!
also doesn't show up in the debug output of the Android app.I suspect I should be using something like android_logger should fix this though.
Overall, this journey wasn't easy, but was also less impossible than I thought.
Beta Was this translation helpful? Give feedback.
All reactions