Pipeline to build Android .so file on windows

Hello,

I currently have a unity app that uses a windows dll for native code functionality.

Even though I build the dll in visual studio, I generate the visual studio project with cmake.

I have not tried to build the code under Linux yet, but Im pretty sure the code is cross platform (I guess I’ll find out if thats true, huh? lol)

Anyway, since thats working well with my unity project, I want to also build the the dll for android. Whats the best way to go about this? I saw the documentation to build an ndk project, but Im not sure how I would actaully generate the .so file.

If I build the C++ code on Ubuntu, would that resulting .so file work with android, or do I need to build the code with android tools (or visual studio that uses android tools)

Any advice on this topic would be helpful.

Thanks!

So, I figured this out…

I tried to use old stack overflow threads that showed the old way to do things…basically the ndk command line stuff with the android make files, but I had no luck with that.

Then I realized I can use visual studio!

So, I added a new project in my solution that I used to create the C++ code. The new project was an android dynamic lib. I made some changes to my windows dll code (using #ifdef and the like) with the broiler plate code visual studio gave me for the android shared object code.

Once things built, I was now able to follow unity’s recommendation for adding native code to a Unity project.

A special shot out to visual studio becasue the broiler plate code was key to my success! (esp the printf/cout to logcat with the android __android_log_print() )

Anyway, that was it. Maybe someone else in the future will find this helpful.

Hi. This is great advice. Would you have an example of the changes you made to the cpp file?