Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building the sample for Android on Linux #80

Open
lemonmojo opened this issue Aug 21, 2024 · 9 comments
Open

Building the sample for Android on Linux #80

lemonmojo opened this issue Aug 21, 2024 · 9 comments
Labels
documentation Improvements or additions to documentation generator

Comments

@lemonmojo
Copy link
Member

lemonmojo commented Aug 21, 2024

  1. Install .NET 9 RC SDK.
    https://dotnet.microsoft.com/en-us/download/dotnet/9.0

  2. Ensure dotnet --version works.

  3. Install Android NDK.
    https://developer.android.com/ndk/downloads

  4. Set environment variable ANDROID_NDK_HOME to the path of the NDK installation.
    ie. nano ~/.bashrc, add line export ANDROID_NDK_HOME="$HOME/dev/android-ndk-r27".

  5. Clone beyondnet.
    ie. git clone https://github.com/royalapplications/beyondnet.git.

  6. cd to beyondnet/Generator/Beyond.NET.CodeGenerator.CLI.

  7. Run ./publish_linux_arm64 or ./publish_linux_x64 depending on the host platform.

  8. Add a symlink to beyondnetgen so that it's on the PATH.
    ie. sudo ln -s ~/dev/beyondnet/Generator/Beyond.NET.CodeGenerator.CLI/bin/Release/net9.0/linux-arm64/publish/beyondnetgen /usr/local/bin/beyondnetgen.

  9. Check if invoking beyondnetgen works and shows usage info.

  10. cd to beyondnet/Samples/Beyond.NET.Sample.Managed.

  11. Run ./publish_managed.

  12. cd to beyondnet/Samples.

  13. Run beyondnetgen Beyond.NET.Sample_Config.json.

  14. cd to beyondnet/Samples/Beyond.NET.Sample.Native.

  15. Run ./publish_android_arm64.
    NOTE: It appears that the Android NDK is currently unavailable for ARM64-based Linux machines and at least for me, the compilation fails within Parallels with the following error EXEC : rosetta error : failed to open elf at /lib64/ld-linux-x86-64.so.2 [/home/fx/dev/beyondnet/Samples/Beyond.NET.Sample.Native/Beyond.NET.Sample.Native.csproj].

  16. Open beyondnet/Samples/Beyond.NET.Sample.Android in Android Studio and try to build/run OR to build from the command line, cd to beyondnet/Samples/Beyond.NET.Sample.Android and run ./build.sh.

@lemonmojo lemonmojo added documentation Improvements or additions to documentation generator labels Aug 21, 2024
@lemonmojo
Copy link
Member Author

lemonmojo commented Aug 21, 2024

NOTE: Targeting Android 15 does not work at the moment because JNA hasn't yet added support for 16 KB page size on Android. See java-native-access/jna#1618

Using the Android 14 SDK is fine though.

@eiabea
Copy link
Contributor

eiabea commented Sep 2, 2024

I walked through the process and everything worked fine on my Debian 12 machine (Kernel 6.9.8-amd64). Only issue I have is that no object from beyondnet can be found in the MainActivity.kt, e.g.: System_Guid, even though it can be found in the Generated_Kotlin.kt file 🤔

@lemonmojo
Copy link
Member Author

lemonmojo commented Sep 2, 2024

@eiabea Yup, forgot to document this but you need to increase the max file size of Android Studio/IntelliJ: https://stackoverflow.com/a/23058324/1025706

Btw I think I increased it to something like 500MB and everything's fine. That's on an M2 Ultra though so your mileage may vary. 😉

@lemonmojo
Copy link
Member Author

@eiabea FYI: Ultimately (once the code generator reaches a certain level) I would like to add automatic build support just like what we have for Swift already. So that instead of including the generated Kotlin code file and the native binary, it would be just a single pre-compiled library that includes both parts. Once we have that, there'll be no more need for the IntelliJ file size tweak.

@eiabea
Copy link
Contributor

eiabea commented Sep 2, 2024

@eiabea Yup, forgot to document this but you need to increase the max file size of Android Studio/IntelliJ: https://stackoverflow.com/a/23058324/1025706

Btw I think I increased it to something like 500MB and everything's fine. That's on an M2 Ultra though so your mileage may vary. 😉

Thanks, I already was that desperate to set this value, but now the IDE seems stuck 😅

@lemonmojo
Copy link
Member Author

@eiabea Really?! The file isn't that huge so maybe try something like 50MB?

@lemonmojo
Copy link
Member Author

@eiabea I just checked. On my MacBook Air M2 I set it to 999999 (KB) so roughly 1GB and have no issues whatsoever. Since the actual file is only around 7MB you can probably get away with a much lower value for quite a while. If that changes anything about performance on your machine, I don't know of course.

@eiabea
Copy link
Contributor

eiabea commented Sep 2, 2024

I know you want to see my good old Thinkpad in flames @lemonmojo, but it seems like there is some kind of other issue 🤔
Looks like the Generated_Kotlin.kt never gets compiled, even though i get some warnings

@lemonmojo
Copy link
Member Author

@eiabea After updating to .NET 9 RC1 and recompiling the generator, don't forget to update your symlink to beyondnetgen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation generator
Projects
None yet
Development

No branches or pull requests

2 participants