Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 7    Views: 103

dudave
Android Fan
Profile
Posts: 111
Reg: Mar 23, 2011
Israel, Netanya
1,110
03/19/13 11:37 AM (12 years ago)

Ads - need help integrating on android

i'v been trying to integrate several ads services the last couple of days, but i failed on each one of them. it seems to be the same principle with most services but there is obviously something big i am completely missing! i tried Admob, Tapjoy and Applovin i managed to import the jar files, i made the changes needed on the androidmanifest file and this is where things starts to get messy.... there are apparently some changes i need to make in some other files but can't figure wich ones. really need help! Thanks David
 
Dragon007
Lost but trying
Profile
Posts: 1509
Reg: Dec 17, 2011
London
20,590
like
03/19/13 12:02 PM (12 years ago)
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
03/19/13 12:49 PM (12 years ago)
Admob's the easiest as you can add the integration to xml rather than java files. So you've imported the jar file, good. Make sure the api is at least level 13. I set mine to api level 16 - it makes no difference to the build. Right click project > properties > android > tick google api level 16. In the manifest, somewhere before the closing application tag, add: <!-- start admob --> <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> <!-- end admob --> I'm using a tabbed layout as an example, as banners will show in at least 5 screens with only one xml entry. In act_root_tabs.xml add this line: xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" here, at the top of the file: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> Underneath the <TabWidget> entry add: <com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="123456789" ads:adSize="SMART_BANNER" ads:loadAdOnCreate="true"/> So it looks like: <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="0dip"/> <com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adUnitId="123456789" ads:adSize="SMART_BANNER" ads:loadAdOnCreate="true"/> Replace 123456789 with your ad id. That'll show a banner under the tabs. Other screens use the same principle, but you'll have to test where to put the banner xml. You'll probably get unexpected results because of the way bt uses a container view. *edit On other screens it may help to add: android:layout_alignParentBottom="true"> or android:layout_alignParentTop="true"> to the banner xml to anchor banners in place at top or bottom.
 
dudave
Android Fan
Profile
Posts: 111
Reg: Mar 23, 2011
Israel, Netanya
1,110
like
03/19/13 02:04 PM (12 years ago)
thanks for the explanation just when i tought it was working (saw some adds on the emulator) i got an error i never acounter on eclipse and i can't get rid of it! Unable to execute dex: Multiple dex files define Lcom/google/ads/Ad; have you ever had this kind of error?
 
jvalley
Aspiring developer
Profile
Posts: 456
Reg: Feb 16, 2013
Green Bay,Wi
9,360
like
03/19/13 02:30 PM (12 years ago)
take a look.. read through first.. your solution may be close to the bottom http://stackoverflow.com/questions/7870265/unable-to-execute-dex-multiple-dex-files-define-lcom-myapp-rarray
 
dudave
Android Fan
Profile
Posts: 111
Reg: Mar 23, 2011
Israel, Netanya
1,110
like
03/19/13 11:53 PM (12 years ago)
solved it, removed the admob jar from my lib folder and it solved the problem, the ads are showing as well! Thanks guys David
 
dudave
Android Fan
Profile
Posts: 111
Reg: Mar 23, 2011
Israel, Netanya
1,110
like
03/20/13 07:03 AM (12 years ago)
quick question, if the app isn't yet live (apk wasn't uploaded yet), would the adds still show on the app on my device?
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
03/20/13 07:53 AM (12 years ago)
Admob ads will show, not sure about the others. If you check logcat output you can see the ads being served.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.