|
| 1 | +# Unreal Jni Adapter |
| 2 | + |
| 3 | +The feature "jni" provides the jni adaption layer for the android messenger communication, which for each interface must be generated with ApiGear java template. |
| 4 | +The android build requires the modules provided with the java template. They are compiled within an unreal application with its build system. <br/> |
| 5 | +Make also sure that your unreal app has proper settings selected to make it available to run on android devices (like allowing large obb files or some android permissions enabled). |
| 6 | + |
| 7 | +## Code generation |
| 8 | + |
| 9 | +Java template provides features: |
| 10 | +**api, stub, android, jnibridge** - which a required for the unreal jni feature to work. <br> |
| 11 | +You can also take a look at the **testclientapp** and **testserviceapp** features which generates a simple example of client or service android app. Those apps only serve first defined interface, and require user to fill partially code for buttons - you need to provide the arguments values. You may use those apps as a starting point to test your unreal side app. |
| 12 | + |
| 13 | +The code generated by java template starting form the top-level folder for the module should be placed in your modules Jni plugin under android folder. |
| 14 | +For example for the module named `"HelloWorld"` the generated folder `helloworld` the path should be: |
| 15 | +``` |
| 16 | +YourProject/Plugins/HelloWorld/Source/HelloWorldJni/android |
| 17 | +``` |
| 18 | +You can achieve this by configuring your `*.solution.yaml` file e.g. like that |
| 19 | + |
| 20 | +``` |
| 21 | +schema: "apigear.solution/1.0" |
| 22 | +name: helloworld |
| 23 | +version: "0.1.0" |
| 24 | +
|
| 25 | +layers: |
| 26 | + - name: unreal |
| 27 | + inputs: |
| 28 | + - myhelloworld.module.yaml |
| 29 | + output: ../relative-path-to/YourProject |
| 30 | + template: apigear-io/template-unreal //TODO MINIMAL VERSION |
| 31 | + features: ["api","jni","stubs"] |
| 32 | + - name: java |
| 33 | + inputs: |
| 34 | + - myhelloworld.module.yaml |
| 35 | + output: ../relative-path-to/YourProject/Plugins/HelloWorld/Source/HelloWorldJni/android |
| 36 | + template: apigear-io/template-java |
| 37 | + features: ["api","android","stubs","jnibridge"] |
| 38 | +``` |
| 39 | +Remember that re-generation may overwrite all your manual changes to generated files. |
| 40 | + |
| 41 | +### Versions |
| 42 | +Currently minimum supported sdk version for android is 33. <br> |
| 43 | +Currently tested UE version is 5.5. |
| 44 | + |
| 45 | +## How to use |
| 46 | + |
| 47 | +Generated code provides: |
| 48 | +* Jni Service Adapter |
| 49 | +* Jni Client |
| 50 | + |
| 51 | +Have in mind the most probably you'll need only one side in your app. The generated objects are a *game subssystems* and they are always started. Moreover the android service starts during the Service Adapter initialization. It will not collide with your client trying to connect other implementation of the service as you need to specify package from which you'd like to use the service, but still may be not wanted overhead in your app. |
| 52 | + |
| 53 | +### Jni Service Adapter |
| 54 | + |
| 55 | +The Jni Service Adapter treats exposes your Local Implementation of the api (requires setting a backend) as an android service. It is generated per interface described in your `*.module.yaml` <br> |
| 56 | +When the Jni Service Adapter is initialized it creates an android service, with a jni backend implemented by that Jni Service Adapter. |
| 57 | +Notice that there will be as many `andorid services` as the interfaces declared in the `*.module.yaml` file. When it comes to threads - no extra thread is spawned for each service, they are all in the applications thread. <br> |
| 58 | +All the services are already exposed in the unreal app `AndroidManifest.xml`. |
| 59 | + |
| 60 | +### Jni Client |
| 61 | +Jni Client adapter is generated per interface. It uses the same interfaces as other ApiGear generated versions (OlinkClient, MessageBusClient or the local implementation).<br> |
| 62 | +It is recommended to use it through that interface, which allows you to easy change of the "data input" and test your application first on your desktop e.g. using OLink simulation.<br> |
| 63 | +To make your client work you need to bind to a **running service**. <br> |
| 64 | +The client does not start any service while trying to bind. The re-connection is not automated neither when service died nor when it wasn't started at all.<br> |
| 65 | +The binding may be performed from the blueprints. It requires the package name of the app that provides (and starts) the requested android service and a unique connection Id (among the this service).<br> |
| 66 | +The client unbinds automatically on deinitialization. |
| 67 | +All the necessary queries and permissions are configured in the unreal app` AndroidManifest.xml`. |
| 68 | + |
| 69 | +## Application permissions |
| 70 | + |
| 71 | +Here is a suggested configuration of the unreal project for automotive. |
| 72 | +You can use settings in unreal editor or you can change your DefaultEngine.ini file. |
| 73 | + |
| 74 | +/*** |
| 75 | + |
| 76 | +[/Script/AndroidRuntimeSettings.AndroidRuntimeSettings] |
| 77 | +PackageName=your.pacakge.[PROJECT] |
| 78 | +... |
| 79 | +MinSDKVersion=33 |
| 80 | +TargetSDKVersion=33 |
| 81 | +... |
| 82 | +bDisableVerifyOBBOnStartUp=False |
| 83 | +bForceSmallOBBFiles=False |
| 84 | +bAllowLargeOBBFiles=True |
| 85 | +... |
| 86 | +ExtraApplicationNodeTags=android:requestLegacyExternalStorage="true" |
| 87 | +ExtraPermissions=android.permission.READ_MEDIA_IMAGES |
| 88 | +ExtraPermissions=android.permission.WRITE_EXTERNAL_STORAGE |
| 89 | +ExtraPermissions=android.permission.READ_MEDIA_VIDEO |
| 90 | +ExtraPermissions=android.permission.READ_MEDIA_AUDIO |
| 91 | +ExtraPermissions=android.permission.READ_EXTERNAL_STORAGE |
| 92 | +ExtraPermissions=android.permission.MANAGE_EXTERNAL_STORAGE |
| 93 | + |
| 94 | +***/ |
| 95 | + |
| 96 | +Remember to fill the `PackageName` field with `your.pacakge.[PROJECT]` especially when providing the service side. `your.package` is the package name that all the client should provide on binding to bind this service. |
| 97 | + |
| 98 | +The minimum target version should not be lower than the one that is required for java template. |
| 99 | + |
| 100 | +The OBB settings allow the unreal app to start on android device. By default android does not allow large OBB files, but unreal apps usually have them large. |
| 101 | + |
| 102 | +Unreal app also requires some extra permissions. |
0 commit comments