1. Goals
1) Unity3D Callable Android Java Function (in. jar)
2) Java callable unity3d function
3) Unity3D callable android C function (in. so)
2. Test environment
1) Unity5.0
2) JDK: jdk-8u25-windows-i586
3) Android SDK
4) Eclipse: adt-bundle-windows-x86
3. Creating Java Engineering
Step 1:
Step 2:
Step 3:
Step 4: Configure Laucher Icon. Don't add your Image File here without any modification. It will force the size of the Image File to be changed and then put it directly into res/drawable.
Step 5:
Step 6: Blank Activity uses default values.
Step 7: Delete the following red markers
Note: If the base class is not Activity, right-click on PlugInTest on the left and select Properties to enter the following interface:
4. Modifying the Android Project
4.1 Import Unity5.0 classes.jar
C:\Program Files\Unity\Editor\Data\PlaybackEngines\androidplayer\com\unity3d\player)
2) classes.jar is located in: C: Program Files Unity Editor Data Playback Engines Android player release bin. Its import method is as follows:
4.2 Replace Launcher Icon
Overlay ic_launcher.png in the res/drawable-xxx directory.
4.3 Modify MainActivity.java
4.4 Export Android content to Unity 5.0
4.4.1 Generate plugintest.jar
1) Enter the Properties of PlugInTest and check "Is Library"
2) Project->Clean
3) Project->Build Project
4) See bin directory for generated plugintest.jar
4.4.2 Put PlugInTest content into Unity 5.0
Put the following in the AssetsPluginsAndroid directory of Unity Project.
1) plugintest.jar in bin directory
2) Android Manifest. XML in bin directory (additional Activities or permissions can be added as needed)
3) entire res directory
The results in Unity Project are as follows:
5. Modify Unity Project
5.1 Modify Android [Player Settings]
5.2 Access Java Interface
UnityEngine. Android JavaClass corresponds to java.lang.Class and its subclasses.
UnityEngine. Android JavaObject corresponds to java.lang.Object and its subclasses.
5.3 Export apk
File->Build Run
When exporting an apk, you may encounter the following problems:
Unable to find unity activity in manifest. You need to make sure orientation attribute is set to fullSensor manually.
Add a line to Android Manifest:All Android Manifests are as follows:
6. Android Native Plug
For Active Plugin of Android Platform (armv7,x86), lib*.so should be placed in the following directory:
1) X86 Platform: Assets/Plugins/Android/libs/x86/
2) armv7 platform: Assets/Plugins/Android/libs/armeabi-v7a/