This article uses the Wanpo ad platform to add ads to the cocos2d-x3.1 project. Wanpo's SDK for Cocos2d-x features quite full, just the official document usage instructions used in the Cocos2d-x engine is 2.0.1, the platform is under Windows, the age is a bit long, this article mainly introduces mac10.9.5+xcode6.0.1+ Cocos2d-x use Wanpo to add ads. First of all, like Wanpo staff, the first day of the night registration, the next day on the phone to greet there is no problem ~
1. Register Wanpo Accounthttp://www.waps.cn, Wanpo can actually not login to register, the same can download the relevant SDK. 2. Download the SDKdownload in the press release to the right of the SDK download, according to the phone system to be tested to choose the appropriate SDK, I am using the Android version for cocos2dx,100 multi m stuff. Download it and unzip it, there will be Libs, demo, development manuals and an updated document. 3, Wanpo website to create the application
very simple, enter the application name and application platform, click Next to get app_id, no need to click the SDK download.
4. Create Cocos2d-x Project
This does not need to be explained, the Cocos New command under the console is created.
5. Copy jar Packagewapsoffer_forcocos2dx_1.1 directory under Libs Appoffer_2.1.1.jar in the Cocos Project created in the previous step under the Android directory, Now that there is no Libs directory under the Proj.android directory, we need to create a new libs directory and place the copied jar package in that directory. 6. ADT Opens Proj.android Project
First two questions appear: 1) Unable to resolve target ' android-10 '. Workaround: Modify the target property in Project.Properties for your ADT presence. Second, modify the androidmanifest.xml to android:minsdkversion= ' one ' android:maxsdkversion= ' 18 ', and change the same to your ADT presence. 2) Org.cocos2dx.cpp under the Appactivity.java error. Solution: Click on the Project Catalog->properties->java Build path->source/link source/browse. Select the engine directory under COCOS/PLATFORM/ANDROID/JAVA/SRC. OK, modify the folder name and write one. Ok.
7. Modify the Appactivity.java codeonly one mini ad is added here to illustrate the configuration of the platform
<span style= "FONT-SIZE:14PX;" >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 s Uper.oncreate (savedinstancestate); Mcontext = this; if (detectOpenGLES20 ()) {///The first parameter is the ID of the app, the second parameter is the channel ID, and the reference manual has the channel identification table Appconnect.getinstance ("</span><span style=" font-family:arial, Microsoft ya Black; "><strong><span style=" Font-size:12px;color: #cc0000; " >510a67751f53b4c4d05ed9f56373cc92</span></strong></span><span style= "FONT-SIZE:14PX;" > ",//app_id" default ", this); Framelayout viewgroup.layoutparams framelayout_params = new Viewgroup.layoutparams (V IewGroup.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); Set the adminilayout position, the specific location of the developer to set lp_mini.gravity = GraVity. TOP | Gravity.center_horizontal; This.addcontentview (Adminilayout, Lp_mini); LinearLayout minilayout = new LinearLayout (this); Minilayout.setgravity (gravity.center_horizontal); Adminilayout.addview (minilayout); Add 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 (Cont Ext. Activity_service); Configurationinfo info = Am.getdeviceconfigurationinfo (); Return (info.reqglesversion >= 0x20000); } static {system.loadlibrary ("cocos2dcpp"); }} </span>
8, Androidmanifest.xml plus permissions
<uses-permission android:name= "Android.permission.INTERNET"/>//Allow program to open network sockets <uses-permission Android:name = "Android.permission.ACCESS_NETWORK_STATE"/>//Allow programs to access information about GSM network <uses-permission android:name= " Android.permission.ACCESS_WIFI_STATE "/>//Allow programs to access WiFi network information <uses-permission android:name=" Android.permission.READ_PHONE_STATE "/>//Read phone state permission <uses-permission android:name=" Android.permission.WRITE_ External_storage "/>//phone SD card Write permission <uses-permission android:name=" Android.permission.GET_TASKS "/>// Allows a program to get information about current or most recently run tasks. An abbreviated task state, whether the activity waits
9, compiling the real machine test
You may encounter various problems during the compilation process.
1) CDT problem: Click on the project name->properties->builders to remove the CDT builder tick.
2) ndk path problem: ADT is placed at the front of the screen, adding the relative path to the NDK in the ADT->PREFERENCES->ANDROID->NDK->NDK location box.
3) NDK command issue: Click on the project name->properties->c/c++ build->environment,add, add name:ndk_root,value:ndk relative path, get can be obtained from the command line.
4) NDK module problem: Click on the project name->properties->java Build Path/source/link Source. The problem of this step in essence is solved in the 6th step.
5) Other questions: If you are still prompted with the target problem, increase the minimum ndk value of the androidmanifest.xml, or restart ADT.
10.
cocos2d-x3.1 using the Wanpo platform to add ads to Android platforms