Android Project Combat (39): Android integrated Unity3d project (GRAPHIC)

Source: Internet
Author: User

Original: Android Project Combat (39): Android integrated Unity3d project (GRAPHIC)

  Demand:

Unity3d is generally used for games and is cross-platform. Originally designed for Android application side A (native development) to do some business processing, and finally by a open Android app side B (unity3d game development) for game operation.

 

  This causes the problem:

1, a application open B application, the transmission between the data is not convenient

2, normal shutdown, abnormal closing of the interaction and technical processing trouble

3, version iterations, need to consider separately

4. Poor experience

5 ...............

Eventually merge into one Android app to improve the user experience. Realize the idea that Android Engineering inherits (introduces) the Unity3d project (dependent Android project generates a class library).

  

Here's how to start the detailed steps:

  Unity3d Engineer to build a class library of the project

It's not much to say, let the Unity3d engineer do it, we just need this class library.

  

Second, the Android Project import class library

    

    Note: All three must be selected

After the import succeeds, there will be some errors to be modified

    

Third, modify

  (1), locate the Build.gradle file in the class library directory

Change the first line: Apply plugin: ' Com.android.application ' to: Apply plugin: ' Com.android.library '

Change compilesdkversion and Buildtoolsversion to match the bottom build.gradle of the app directory

Delete the ApplicationID line under defaultconfig{}

Sync now ...

The end result is as follows:

      

    

(2), locate the Androidmanifest.xml file in the class library directory

Delete a few properties under application

Android:debuggable= "false"

Android:label= ""

Android:theme= ""

android:icon= "@mipmap/ic_launcher"

    

Find the main entry activity is <intent-filter></intent-filter>, add a property:android:process= "E.unity3d", This is to allow Unity3d's main activity to exit the Android part of the time, or there will be an abnormal problem

Then delete all parts of the <intent-filter> inside, this part is labeled the activity as the main entrance and displayed on the phone desktop, removed, not on the desktop display, because the Android part calls this into the Unity3d section, So the default has the function of the main entrance.

The effect is as follows:

<application android:allowbackup="true"Android:name="com.xxxxx.SensorS.XApplication"Android:supportsrtl="true"Android:isgame="true"> <Activity android:configchanges="orientation|keyboardhidden|screensize"Android:name="com.xxxxx.SensorS.MainActivity"android:process="E.unity3d"android:screenorientation="Landscape"> </activity>
  
//... Attention
Open the Mainactivity interface is in a new process, see parameter android:process= "E.unity3d"
If the other service or activity interface needs to be in the same process also need to add android:process= "E.unity3d"
</application>

    

(3), depending on the class library

      

Select Class Library Dependency

      

   

(4), Android part switch open Unity3d main activity, that is, open an activity in the class library

New Intent (); // main activity of the Unity3d section                              
Intent.setclass (tasklistactivity.this,mainactivity.class); startactivity (intent);

  

Another: Errors that may occur

 1, your hardware does not support!

  

This chance is relatively large, first look at the Unity3d class library file directory, only armeabi-v7a and x86 two folders

  

So what we have to solve is to look at the app directory and all the class library under the Libs folder or the Jnilibs folder can only have these two folders, more need to delete

Also pay attention to:

If you have the following code in your app directory or in the Build.gradle folder in the module directory:

NDK {            // Select the. So library for the corresponding CPU type to be added.             abifilters  'armeabi-v7a' ,' x86 '        }

Remember also must only have these two, many also want to delete.

As long as it is consistent, the problem is solved.

  

2, jar package conflict, this is a common problem, the class library and the app to keep one on the line, not much to say.

3. buildconfig.class file conflicts

 for ' : Ipark2:transformclasseswithjarmergingfordebug ' . Duplicate Entry:com/xxxxx/xxxxx/xxxx/buildconfig.class

This will tell you that the Buildconfig.class file in your com/xxxxx/xxxxx/xxxx/directory is conflicting. Generally in the class library, the jar package has such a file, and the original project is not, is to generate the class library when the system is generated.

The workaround is to remove the file from the jar package.

Example:

1. Now there is a jar package

2. Open the directory where the file is located, press Shift + right mouse button to select ' Open Command Window from here '

Input command: jar XF sensors. Jar Note:sensors is the name of your jar package

After executing the command, you will find that the directory has more than one jar package extracted files, under that folder to find the Buildconfig.class file, delete

3. Re-compress the processed folder into a jar package

Jar CVF sensorsss. jar com Note:sensorsss is the name of the regenerated jar package, and com is the folder to be compressed into the jar package (that is, the original jar package unzipped Shrink the file and delete the Buildconfig.class file)

Finally, the processed jar package is replaced with the original

Android Project Combat (39): Android integrated Unity3d project (GRAPHIC)

Related Article

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.