environment
- Unity 2019.4.8
- Android Studio 4.0.1
1. Configure the environment of the Unity project
Create the OverrideUnityActivity.java file and place it in the Unity project. The directory structure is as shown above and the
file content is as follows
package com.company.product;
import android.os.Bundle;
import android.widget.FrameLayout;
import com.unity3d.player.UnityPlayerActivity;
public abstract class OverrideUnityActivity extends UnityPlayerActivity
{
public static OverrideUnityActivity instance = null;
abstract protected void showMainActivity(String setToColor);
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
instance = this;
}
@Override
protected void onDestroy() {
super.onDestroy();
instance = null;
}
}
You will know the function of this file as follows
2. Unity export Android project
The exported directory structure is as follows
3. Import Android Studio
Create an empty Android project with no restrictions on the package name and API Level
Import the unityLibrary folder under the unity export file directory into Android Studio as a module
4. Modify build.gradle(module:app)
5. Modify build.gradle (Module: NativeAndroidApp)
6. Modify strings.xml (Module: app)
This step is very important, although I don't know what it does
7. Delete part of the code in AndroidManifest ( module:unityLibrary )
Delete the code specified in the AndroidManifest, this part of the code will cause two icons to appear after the packaged APK is installed
8. Create the MainUnityActivity class (Module: app)
This class inherits from OverrideUnityActivity
9. Modify AndroidManifest (Module: app)
<activity android:name=".MainUnityActivity"
android:screenOrientation="fullSensor"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"
android:hardwareAccelerated="false"
android:process=":Unity"
android:label="UnityProject">
</activity>
10. Call up the Unity scene
At this point, you can see some phased results
References
Unity official case
https://github.com/Unity-Technologies/uaal-example
The unknown master
https://blog.csdn.net/u014361280/article/details/91888091#æ¡ ˆä¾‹æµ‹è¯•çŽ¯å¢ƒï¼š[
https://www.cnblogs.com/zhxmdefj/p/13273560.html
Special thanks to Brother Zhang, who gave me a lot of guidance in Android Studio.