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

Usage on Android #122

Open
megamidge opened this issue Sep 19, 2018 · 10 comments
Open

Usage on Android #122

megamidge opened this issue Sep 19, 2018 · 10 comments

Comments

@megamidge
Copy link

How do i go about using this in an Android Xamarin app? I have it working for a Windows Application if i copy out one of the packaged freetype dll's to the output directory, but this isn't so simple on Android.
On Android i get a crash when trying to instantiate the Library object:
System.DllNotFoundException: libfreetype.so.6

Help appreciated.

@HinTak
Copy link
Contributor

HinTak commented Sep 19, 2018

You build freetype for android, using the android NDK.

@Robmaister
Copy link
Owner

Yup, I ship pre-built FreeType dll's on Windows since it needs patching on 64-bit. Android uses FreeType internally but doesn't expose it to apps, so you'll have to build your own. Here's a fairly specific guide that should still work despite the dated NDK version:

https://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Android_NDK#FreeType

Plenty of other guides/articles/repos show up if you look

@megamidge
Copy link
Author

Alright thanks, i'll look into this. The problem i had when initially searching was that i just could not find anything that related to FreeType, Android AND Xamarin. As it stands, i don't really find anything for Xamarin + NDK, but i have been able to install NDK. Using it however is proving to be a headache and seems to require to a lot of jumping around :/ Not that is an issue with SharpFont of course.

@megamidge
Copy link
Author

I've since hit a wall. I cross-compiled freetype but now have no idea how to use it..
I can't just add "LOCAL_STATIC_LIBRARIES := freetype" to my projects Android.mk, because Xamarin doesn't use that way of building. I thought that perhaps i needed to use ndk-build to build the freetype that i compiled (which doesn't make sense anyway aha), this of course wasn't the answer and did nothing. I'm really at a loss here as to what the next step would be. Sorry to be a hassle

@HinTak
Copy link
Contributor

HinTak commented Sep 24, 2018

If you cross compile correctly you should end up with a libfreetype.so.<numbers>. rename and remove the numbers part so it ends in .so. Copy to the same directory as SharpFont.dll.

@megamidge
Copy link
Author

I see. So i have an issue that that straight up doesn't exist for me after following the provided link, i'll have a further look around though. Fairly sure i cross-compiled it, just hasn't produced any .so files so perhaps not.

@HinTak
Copy link
Contributor

HinTak commented Sep 24, 2018 via email

@megamidge
Copy link
Author

Ah yes i seem to have been blind. There is 'libfreetype.so' within my compiled folder as well as my uncompiled freetype. Woops.
Help has been much appreciated.

Will close once confirmed working.

@megamidge
Copy link
Author

megamidge commented Sep 25, 2018

So it seems i didn't have any 'libfrreetype.so.[X]' but do have one without the number. I added this to my project in /lib/armeabi/ and set it's build action to AndroidNativeLibrary. I still get a crash on the first call inside my DLL that complains about not finding libfreetype.so.6. I had a go about going into the SharpFont.dll.config file and making it look for just libfreetype but this of course did not work.

I have given dropping the libfreetype.so file into the output directory of both my DLL (/bin/Release) and my Android Application (/bin/Debug) where SharpFont.dll is dumped on build, but this hasn't worked either. The only thing i found in my freetype build was pkgconfig which didn't say anything about a shared library, and couldn't find any directory or file name configure or config.

(EDIT)
Was able to reproduce my problem with a new Xamarin Android application that references SharpFont directly.

@megamidge
Copy link
Author

I re-tried my process again, based on the link provided again.
I had to run the NDK's make_standalone_toolchain.py in CMD, but the rest i was able to perform in Cygwin.
Everything seemed to build (but again, no freetype.so.[X]). I tried to cut out a SharpFont as a middle man in a test project and put this in my code:
[DllImport("libfreetype.so")] private static extern Error FT_Init_FreeType(out IntPtr alibrary);
Calling this produces the same error as before. In my csproj I have this:
<ItemGroup> <AndroidNativeLibrary Include="C:\NDK\freetype\freetype-2.9.1\objs\.libs\libfreetype.so"> <Abi>armeabi</Abi> </AndroidNativeLibrary> </ItemGroup>

as per this documentation.
The error in the output window is this pastebin.
I'm not sure what's going on but i would think i must be building wrong? But i can't see where im going wrong!

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

No branches or pull requests

3 participants