Unity adds Android ad summary, unityandroid Summary
There are several ways to add ads to Unity games:
- Import Android Jar package
- Export the game as an Android Project (select the Google Android Project during Build. For this method, refer to porting the Unity3D game to the Android platform)
- Use the Unity Ad plug-in (see Asset Store, for example, Google Mobile Ads SDK)
Among them, the first is the most common, and I also use this one.
The entire process of the first method is roughly as follows:
This process can be referred to the two articles: unity3d insert android rice ads and Unity 3D about the APK package advertising process.
If you successfully add an advertisement by following the steps, you can skip the following section. I encountered several problems in this process.
The first is CommandInvokationFailure: Failed to re-package resources.
This problem occurs because Android resources are not well integrated. First, check the file hierarchy:
Assetes/
-------- Plugins/
---------------- Android/
------------------------ AndroidManifest. xml
------------------------ SDK File
------------------------ Exported Jar package
If the problem persists, check if it is related to AppCompat. I don't know much about Android, and the solution is not brilliant:
- Do not create a topic when creating an Android project.
- The minimum version is 4.0 or later.
Okay, the problem is solved.
In Java projects, some methods are generally well written according to the SDK documentation, which allows you to easily create ad strips, interstitial ads, and so on.
Select a GameObject in Unity and use the following code to obtain the Java class object:
jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
Use the Call method of AndroidJavaObject, for example:
jo.Call("showSpot");
The last is the icon and name of the game.
After the advertisement code is added, the icon of the Unity project will be overwritten by the Android project. Therefore, it is most convenient to determine the Icon when creating an Android project.
The game name is still in the Unity project.
All of the above are obtained by referring to others' blogs and self-exploration when I try to add advertisements to Unity. If there is any error, please point it out. Please refer to the advertisement SDK document.