Exporting jars to Unity3d with Android studio

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.