Cocos2dx-3.1 access domob ad sdk + Android (1), cocos2dx Access sdk

Source: Internet
Author: User

Cocos2dx-3.1 access domob ad sdk + Android (1), cocos2dx Access sdk

After a few days of research, coupled with the guidance of the great gods, cocos finally connected to the domob advertising sdk.

To connect to a third-party sdk, you must first understand some eclipse usage, and understand some java code, and some xml. C ++ calls Java-Layer Code through jni. There is an article worth reading: http://blog.csdn.net/ku?999/article/details/38553889click to open the link

1. Create an empty helloworld project, in the D: \ cocos2d-x-3.1.1 \ tools \ cocos2d-console directory, open the command window, enter:

Cocos new NB-p com. test. NB-l cpp-d D: cocos2dx_original \ cocos2dx_projects.

2. register the domob account and add an application. We will have a Publisher ID to create an ad space and we will get the ad space ID.

3. Import the cocos project in eclipse. Import steps: 1) Right click-> Import-> android-> existing android code into workspace and click Next to import your proj. android

Click Finish, and then import the cocos dependency library. The import path is your project D: \ cocos2dx_projects \ Pig \ cocos2d \ cocos \ platform \ android \ java.

Click OK.

4. Click project-clear, right-click, and choose running mode-android application.

5. You will see an additional libs folder under your project, and add the domob_android_sdk.jar you downloaded from the domob network to your libs directory.

6. In eclipse, right-click "properties"> "java build path"> "Database" and add it to jar.

7. Add the following code to AndroidManifest. xml:

<! -- Network access permission --> <uses-permission android: name = "android. permission. INTERNET"/> <! -- Obtain the network information status, such as whether the current network connection is valid --> <uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE"/> <! -- Read the mobile phone status --> <uses-permission android: name = "android. permission. READ_PHONE_STATE"/> <! -- Allow programs to write files to external storage, such as files written to the SD card --> <uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/> <! -- Get the error location --> <uses-permission android: name = "android. permission. ACCESS_COARSE_LOCATION"/> <! -- Get WiFi status --> <uses-permission android: name = "android. permission. ACCESS_WIFI_STATE"/> <! -- The following permissions are optional. They are mainly used for brand ads. If you do not add them, brand ads requiring these effects will not be placed on your applications. --> <! -- Shake permission --> <uses-permission android: name = "android. permission. VIBRATE"/>
  <activity            android:name="cn.domob.android.ads.DmActivity"            android:theme="@android:style/Theme.Translucent" >        </activity>

The code location is as follows:

<? Xml version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "com. test. pig "android: versionCode =" 1 "android: versionName =" 1.0 "> <uses-sdk android: minSdkVersion =" 9 "/> <uses-feature android: glEsVersion = "0x00020000"/> <! -- Network access permission --> <uses-permission android: name = "android. permission. INTERNET"/> <! -- Obtain the network information status, such as whether the current network connection is valid --> <uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE"/> <! -- Read the mobile phone status --> <uses-permission android: name = "android. permission. READ_PHONE_STATE"/> <! -- Allow programs to write files to external storage, such as files written to the SD card --> <uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/> <! -- Get the error location --> <uses-permission android: name = "android. permission. ACCESS_COARSE_LOCATION"/> <! -- Get WiFi status --> <uses-permission android: name = "android. permission. ACCESS_WIFI_STATE"/> <! -- The following permissions are optional. They are mainly used for brand ads. If you do not add them, brand ads requiring these effects will not be placed on your applications. --> <! -- Shake permission --> <uses-permission android: name = "android. permission. VIBRATE "/> <application android: label =" @ string/app_name "android: icon =" @ drawable/icon "> <! -- Tell Cocos2dxActivity the name of our. so --> <meta-data android: name = "android. app. lib_name "android: value =" cocos2dcpp "/> <activity android: name =" org. cocos2dx. cpp. appActivity "android: label =" @ string/app_name "android: screenOrientation =" landscape "android: theme =" @ android: style/Theme. noTitleBar. fullscreen "android: configChanges =" orientation "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> </activity> <activity android: name =" cn. domob. android. ads. dmActivity "android: theme =" @ android: style/Theme. translucent "> </activity> </application> <supports-screens android: anyDensity =" true "android: smallScreens =" true "android: normalScreens =" true "android: largeScreens = "true" android: xlargeScreens = "true"/> <uses-permission android: name = "android. permission. INTERNET "/> </manifest>

In this way, you can add an advertisement. Let's go. Er and so on are just cainiao. The next article introduces code in VS and calls java

Of course, the premise is that your java environment should be configured first


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.