# Build for android using unity

**URL:** https://discourse.kitware.com/t/build-for-android-using-unity/268
**Category:** Pulse Physiology Engine
**Created:** [June 17, 2019, 11:30pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268 "2019-06-17T23:30:40Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![Ben\_Engel](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ben_engel/32/111_2.png) [@Ben\_Engel](https://discourse.kitware.com/u/Ben_Engel)
#### Post date: [June 17, 2019, 11:30pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/1 "2019-06-17T23:30:40Z")

</div>

everything works perfectly inside of my HTC vive when using the unity plugin, but then I go and build it for android to get it working in my oculus quest and none of the pulse engine stuff works at all. How do I go about getting these things working on an android platform?

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [June 18, 2019, 11:21am UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/2 "2019-06-18T11:21:14Z")

</div>

I took a stab at building the PulseUnity asset in Unity for Android.  
I had to install a few andoid sdk packages including the nDK since Pulse is C++ based  
I got pretty far, but it was getting pretty bogged down getting my environment setup, and never got back around to it.

I will take a shot at this again and put a little more effort into it and let you know where I get

Thanks for the feedback!

---

<div class="post-metadata">

### Author: ![Ben\_Engel](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ben_engel/32/111_2.png) [@Ben\_Engel](https://discourse.kitware.com/u/Ben_Engel)
#### Post date: [June 18, 2019, 7:50pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/3 "2019-06-18T19:50:26Z")

</div>

If you just let me know what I would need to do to get started on it I will do my best. I have my android environment fully setup. I think I just need to get those .dll files into .so? I just don’t know how to go about doing that. I’ve never developed using these before, always just in unity and web.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [June 19, 2019, 11:33am UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/4 "2019-06-19T11:33:59Z")

</div>

I am not entirely sure  
dll and so are really both shared library objects, one for windows and one for \*nix systems  
I already have a JNI interface for Pulse, so we might just need to get that built for the target android system and figure out how to get it into Gradle to package with your APK

---

<div class="post-metadata">

### Author: ![alexis.girault](https://discourse.kitware.com/user_avatar/discourse.kitware.com/alexis.girault/32/75_2.png) [@alexis.girault](https://discourse.kitware.com/u/alexis.girault)
#### Post date: [June 19, 2019, 1:40pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/5 "2019-06-19T13:40:01Z")

</div>

@abray would you say it’s simply a matter of finding the proper CMake commands/toolchains to build the [native plugins](https://gitlab.kitware.com/physiology/PulseUnityAsset/tree/master/PulsePhysiologyEngine/Plugins/Native) (so the [PulseC](https://gitlab.kitware.com/physiology/engine/blob/master/PulseC.cmake) lib from the [PulseEngine](https://gitlab.kitware.com/physiology/engine/) repo) for Android?

If yes, maybe this can help:

- [https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling-for-android](https://cmake.org/cmake/help/v3.7/manual/cmake-toolchains.7.html#cross-compiling-for-android)

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [June 19, 2019, 1:51pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/6 "2019-06-19T13:51:50Z")

</div>

No, there’s a jni interface already, so we don’t have to build pulseC in the ndk

I believe what the ndk is doing is creating a jni interface on regular C++ classes for access to Java. Pulse already has that (and it’s well thought out), so really we need to understand the native Android build process and see where we can integrate our provided jni .so file into that build process.

The regular pulse build will build the pulseJNI.so

Then we can also import the Pulse jar file for access to it in the Android Java space

I think

---

<div class="post-metadata">

### Author: ![Ben\_Engel](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ben_engel/32/111_2.png) [@Ben\_Engel](https://discourse.kitware.com/u/Ben_Engel)
#### Post date: [June 19, 2019, 8:38pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/7 "2019-06-19T20:38:42Z")

</div>

So I am building it all in unity, and yeah it does already have a pulseC.so but I have tried building an apk with both mono and IL2CPP on each cpu target architecture and none of it seems to work. But I also don’t get any errors no matter what I am doing I have no idea what is going on.

I am going to go and build in some debugging stuff into some of the unity scripts and see if that tells me anything.

---

<div class="post-metadata">

### Author: ![alexis.girault](https://discourse.kitware.com/user_avatar/discourse.kitware.com/alexis.girault/32/75_2.png) [@alexis.girault](https://discourse.kitware.com/u/alexis.girault)
#### Post date: [June 20, 2019, 3:54pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/8 "2019-06-20T15:54:59Z")

</div>

That `PulseC.so` was built on Linux (by @abray), I doubt that will work with Android.

**Edit** : Congrats on being [New User of the Month](https://discourse.kitware.com/badges/44/new-user-of-the-month?username=ben_engel) @Ben_Engel 🥳 Thanks for your contributions so far! (pretty cool feature by Discourse right there…)

---

<div class="post-metadata">

### Author: ![Ben\_Engel](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ben_engel/32/111_2.png) [@Ben\_Engel](https://discourse.kitware.com/u/Ben_Engel)
#### Post date: [June 25, 2019, 4:50pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/9 "2019-06-25T16:50:05Z")

</div>

So what do I need to do to start working on this to make it run on android? Where can I get the source for it? I’ll go through all of the hard work of porting it as long as I know what I am trying to port. I’d like to add a few other things as well to make expand it into fitting my use case. But that can come later, after it is running on the required hardware.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [June 25, 2019, 6:02pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/10 "2019-06-25T18:02:07Z")

</div>

You can grab pulse source code here : [https://gitlab.kitware.com/physiology/engine](https://gitlab.kitware.com/physiology/engine)  
You should try building the PulseJNI target  
or the PulseEngine target if you want the ndk to automatically wrap it in some JNI thing it needs…

---

<div class="post-metadata">

### Author: ![Ns1358](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ns1358/32/144_2.png) [@Ns1358](https://discourse.kitware.com/u/Ns1358)
#### Post date: [August 6, 2019, 4:52am UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/11 "2019-08-06T04:52:26Z")

</div>

Hello! Just wondering if any traction on this since the last post? 🙂 Figured I’d ask before I try to reinvent the wheel

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [August 6, 2019, 2:48pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/12 "2019-08-06T14:48:35Z")

</div>

I have not done anything since the last post.

I am trying to get my android environment setup today

Are you just selecting the Android target in the Unity build menu?

---

<div class="post-metadata">

### Author: ![Ns1358](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ns1358/32/144_2.png) [@Ns1358](https://discourse.kitware.com/u/Ns1358)
#### Post date: [August 6, 2019, 2:59pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/13 "2019-08-06T14:59:32Z")

</div>

Thanks for quick response. I actually just stumbled upon Pulse a few days ago and haven’t gotten around to even building it to Android yet. I was actually holding off until I heard back here. I can try it this evening and let you know. But yes target is Android for build in Unity.

P.s. thanks so much for making this open source and available in Unity. There is so much potential with this engine!

---

<div class="post-metadata">

### Author: ![Ns1358](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ns1358/32/144_2.png) [@Ns1358](https://discourse.kitware.com/u/Ns1358)
#### Post date: [August 7, 2019, 2:51am UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/14 "2019-08-07T02:51:03Z")

</div>

I did attempt build for Android and had the same issue. No errors, but it won’t grab streaming assets.

From what I gather in unity docs, this is apparently a common issue when apps are using StreamingAssets and are built to Android. I am going to mess around with the below this week and see where I land.

 ![image](https://discourse.kitware.com/uploads/default/original/1X/4e53fe2afe7a7ecd286ccd50b74bac088abbbd0f.png)

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [August 7, 2019, 12:40pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/15 "2019-08-07T12:40:46Z")

</div>

Thanks for the info.

I got to the point of building my simple asset harness and unity complained about not knowing which plugin to load (with the same name) I assume its referring to the PulseC plugins…

What all did you do in setting up Android for unity? (Just in case I am missing something, which I probably am)

---

<div class="post-metadata">

### Author: ![Ns1358](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ns1358/32/144_2.png) [@Ns1358](https://discourse.kitware.com/u/Ns1358)
#### Post date: [August 7, 2019, 8:46pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/16 "2019-08-07T20:46:39Z")

</div>

I actually followed a video back when I set it up. I believe I:

1. Downloaded JDK
2. Installed Android Studio and downloaded appropriate SDKs
3. I think I remember pointing Unity to the SDK directory. In the Unity docs it looks like that may have been **Unity** \> **Preferences** \> **External Tools**. (Sorry I’m away from computer)
4. Changed build platform in Unity to target Android. Set minimum target to Marshmellow in Player Settings.

Hopefully that’s helpful. Sorry, this has partly been an interesting learning experience for me as of late. Let me know if that works for you.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [August 18, 2020, 8:15pm UTC](https://discourse.kitware.com/t/build-for-android-using-unity/268/17 "2020-08-18T20:15:36Z")

</div>

Note that our 3.0 asset now has Android support.  
Sorry this is coming so late, but should now be supported

(I can probably answer any other other ndk questions you may have as well!)
