Above:

  1. Unity3d project needs to call the native method of Android, while Unity3D does not provide these types of API, so it needs the support of the native code of Android, such as mobile phone vibration and other dynamic effects, or payment similar to third-party SDK.

  2. It is recommended that Android developers use Eclipse instead of AndroidStudio to package jars, because Eclipse is more convenient to package jars, and a bit more cumbersome than AndroidStudio. Of course, if you are a command line jar packaging guru, please ignore this.

Ideas:

Unity3d needs the support of Android, so we Android need to encapsulate the method, deal with some SDK call logic (initialization, registration list file, permission allocation, etc.), and then use the form of similar write interface to expose some interfaces for Unity3D call. Android needs to be packaged into jars and provided to the following resource files of Unity3D: libs, RES, Androidmanifest.xml. These items will be manually created by the developer in the Android directory of Unity3D in a folder similar to the structure of the Android project: libs, RES, androidmanifest.xml in this directory, it is worth noting that these three copies are copied from the Android project. There is also a bin directory that houses jars packaged with Android native code (how and what? This is definitely a pit, as we’ll see.)

Project environment construction:

Create eclipse android project: note

  • The package name must be the same as the unity3D project package name
  • If there is no special requirement, the project requires minSdkVersion to be 4.0.3 or above, avoiding importing V7 package
  • Have the Unity3D developer provide classes.jar
  • The project home page, the class that writes methods for unity3D calls, must inherit the UnityPlayerActivity class. Oncreate () only implements super.onCreate(savedInstanceState); , be careful not to implement setcontentView()
  • The list file needs to be configured as follows:
   <supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />
   <uses-feature android:glEsVersion="0x00020000" />
    <uses-feature
        android:name="android.hardware.touchscreen"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.touchscreen.multitouch"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.touchscreen.multitouch.distinct"
        android:required="false" />

Copy the code

The method class needs to be added to the node

   <activity
            android:name="com.xxxxx.xxx.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER"/>, </intent-filter> <meta-data android:name="unityplayer.UnityActivity"
                android:value="true" />
        </activity>
Copy the code

The specific implementation

Because it is still in the development stage, this code is not posted, and will be updated later.

How to package

  1. After ensuring that the project code is correct, right-click the project and select Export
  2. Click “JAR File” when the picture appears.
  3. Do not select any files! Do not select any files! Do not select any files! Select the SRC directory separately! Yes, we just need the SRC directory and nothing else at all!
  4. Right-click Finish to package, then go to the Eclipse project project directory and select the following three files to package and send to the unity3D developer