Android platform advertisement adding using wanpu platform in Cocos2d-x3.1

Source: Internet
Author: User

Android platform advertisement adding using wanpu platform in Cocos2d-x3.1

This article uses the universal advertising platform to add ads to Cocos2d-x3.1 projects. Universal SDK for Cocos2d-x function is quite comprehensive, but the use of the official documentation instructions in the use of the Cocos2d-x engine is 2.0.1, the platform is Windows, a little old, this article mainly introduces Mac10.9.5 + XCode6.0.1 + Cocos2d-x to add an advertisement using the universal. First, I would like to give a thumbs-up to our staff and register for use the first night. The next day I will call to ask if there is any problem ~

1, register the http://www.waps.cn wanpu account, wanpu in fact can not login to register, you can also download the relevant SDK. 2. Download the SDK. Download the SDK on the right of the news announcement. Select the corresponding SDK Based on the mobile phone system to be tested. I am using Android For Cocos2dx and more than 100 MB. Download and decompress the package. A libs, demo, development manual, and an update document are displayed. 3. Create an application on the official website
Simply enter the application name and platform, and click Next To Get The APP_ID. You do not need to download the SDK.
4. Create a Cocos2d-x Project

This does not need to be explained. The cocos new command in the console is created.

5. Copy the AppOffer_2.1.1.jar in libs under the Jar package WapsOffer_ForCocos2dx_1.1 to the Android directory of the Cocos project created in the previous step. In this case, proj. there is no libs directory under the android directory. We need to create a new libs directory and put the copied jar package under this directory. 6. Open the proj. android project in ADT.

First, two problems occur: 1) Unable to resolve target 'android-10 '. Solution: Modify the target attribute in project. properties to exist for your ADT. Next, change AndroidManifest. xml to android: minSdkVersion = '11' android: maxSdkVersion = '18', which also exists in your ADT. 2) AppActivity. java under org. cocos2dx. cpp reports an error. Solution: Click the project directory> Properties> Java Build Path> Source/Link Source/Browse. Select cocos/platform/android/java/src under the engine directory. OK. Modify the Folder name. Just enter one. OK.

7. Modify the AppActivity. java code. Only one mini advertisement is added here to describe the platform configuration.
Import org. cocos2dx. lib. cocos2dxActivity; import org. cocos2dx. lib. cocos2dxEditText; import org. cocos2dx. lib. cocos2dxGLSurfaceView; import org. cocos2dx. lib. cocos2dxRenderer; import android. app. activityManager; import android. content. context; import android. content. pm. configurationInfo; import android. OS. bundle; import android. util. log; import android. view. gravity; import android. view. viewGroup; import android. widget. frameLayout; import android. widget. linearLayout; import cn. waps. appConnect; public class AppActivity extends Cocos2dxActivity {private Cocos2dxGLSurfaceView mGLView; private static Context mContext; @ Override protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stub super. onCreate (savedInstanceState); mContext = this; if (detectOpenGLES20 () {// The first parameter is the Application id, and the second parameter is the channel id, the reference table AppConnect contains the channel ID. getInstance ("510a67751f53b4c4d05ed9f56373cc92", // APP_ID" default ", this); // FrameLayout ViewGroup. layoutParams framelayout_params = new ViewGroup. layoutParams (ViewGroup. layoutParams. FILL_PARENT, ViewGroup. layoutParams. FILL_PARENT); FrameLayout framelayout = new FrameLayout (this); framelayout. setLayoutParams (framelayout_params); // Cocos2dxEditText layout ViewGroup. layoutParams edittext_layout_params = new ViewGroup. layoutParams (ViewGroup. layoutParams. FILL_PARENT, ViewGroup. layoutParams. WRAP_CONTENT); Cocos2dxEditText edittext = new Cocos2dxEditText (this); edittext. setLayoutParams (edittext_layout_params );//... add to FrameLayout framelayout. addView (edittext); // Cocos2dxGLSurfaceView mGLView = new Cocos2dxGLSurfaceView (this );//... add to FrameLayout framelayout. addView (mGLView); mGLView. setEGLContextClientVersion (2); mGLView. setCocos2dxRenderer (new Cocos2dxRenderer (); // mGLView. setTextField (edittext); // Set framelayout as the content view setContentView (framelayout); // mini ad LinearLayout adMiniLayout = new LinearLayout (this); adMiniLayout. setOrientation (LinearLayout. VERTICAL); FrameLayout. layoutParams lp_mini = new FrameLayout. layoutParams (FrameLayout. layoutParams. FILL_PARENT, FrameLayout. layoutParams. WRAP_CONTENT); // sets the floating position of adMiniLayout. The developer can set lp_mini.gravity = Gravity as needed. TOP | Gravity. CENTER_HORIZONTAL; this. addContentView (adMiniLayout, lp_mini); LinearLayout miniLayout = new LinearLayout (this); miniLayout. setGravity (Gravity. CENTER_HORIZONTAL); adMiniLayout. addView (miniLayout); // Add the mini ad AppConnect. getInstance (this ). showMiniAd (this, miniLayout, 10);} else {Log. d ("activity", "don't support gles2.0"); finish () ;}} private boolean detectOpenGLES20 () {ActivityManager am = (ActivityManager) getSystemService (Context. ACTIVITY_SERVICE); ConfigurationInfo = am. getDeviceConfigurationInfo (); return (info. reqGlEsVersion> = 0x20000);} static {System. loadLibrary ("cocos2dcpp ");}}
8. Add permission to AndroidManifest. xml
 // Allow the program to open the network socket
 // Allow the program to access GSM Network Information
 // Allow programs to access Wi-Fi network information
 // Read the mobile phone status permission
 // Mobile phone SD card write permission
 // Allows a program to obtain information about the current or recent running tasks. Status of a scaling task, waiting for activity
9. Compile a real machine test 

Various problems may occur during compilation.

1) CDT problem: Click the Project Name> Properties> Builders to remove the check box for CDT Builder.

2) NDK path problem: the ADT is placed at the front of the screen. The ADT-> Preferences-> Android-> NDK Location box adds the relative path of the NDK.

3) NDK command problem: Click the project name-> Properties-> C/C ++ Build-> Environment, Add, Add name: NDK_ROOT, value: NDK relative path, you can use the command line to obtain the information.

4) NDK module problem: Click the Project Name> Properties> Java Build Path/Source/Link Source. In essence, this step is solved in step 1.

5) Other problems: if the target problem persists, increase the minimum NDK value of AndroidManifest. xml, or restart ADT.

10,


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.