Unity adds Android ad summary, unityandroid Summary

Source: Internet
Author: User

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.

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.