1. Create a new Android Studio project and select empty activity
2. Create a module
3. Copy the Unity dependent jar package to the Libs of the project
4. Add Java code
The content is modified as follows
Package com.example.mylibrary; /* */import Com.unity3d.player.unityplayeractivity;import Android.app.activity;import Android.os.Bundle; Public class Mainactivity extends Unityplayeractivity { @Override protectedvoid OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); // Setcontentview (r.layout.activity_main); }}
5, modify the gradle of mylibary, increase
Task Makejar (type:copy) { //delete existing delete ' Build/libs/mylibrary.jar ' //Set copy of file from (' build/ intermediates/bundles/debug/') //Enter the file directory after the jar package into (' build/libs/') //Put Classes.jar into the build/libs/directory //include, exclude parameter to set filter //(we only care about Classes.jar this file) include (' Classes.jar ') //rename rename (' Classes.jar ', ' Mylibrary.jar ')}makejar.dependson (build)
6, modify the app's gradle, increase
7. Enter Gradlew Makejar in the command line of Android Studio
8. View output
9 Copy Mysdk.jar to Unity project
10. Modify Androidmanifest file to start activity as Mainactivity
<activity android:label="@string/app_name"android:screenorientation="Fullsensor"Android:launchmode="Singletask"android:configchanges="mcc|mnc|locale|touchscreen|keyboard|keyboardhidden|navigation|orientation|screenlayout|uimode|screensize| Smallestscreensize|fontscale"Android:name=". Mainactivity"> <intent-filter> <action android:name="Android.intent.action.MAIN"/> <category android:name="Android.intent.category.LAUNCHER"/> <category android:name="Android.intent.category.LEANBACK_LAUNCHER"/> </intent-filter> <meta-data android:name="Unityplayer. Unityactivity"Android:value="true"/> </activity>
11. Export APK
Exporting jars to Unity3d with Android studio