EDIT: The following post solved my problems: http://forum.unity3d.com/threads/67817-I-will-pay-someone-to-show-me-how-to-integrate-admob – Much appreciating for finding this post again and posting the solution!
I have seen the two threads already available on the forums
http://forum.unity3d.com/threads/62699-Android-AdMob?highlight=android+admob
http://forum.unity3d.com/threads/58620-Unity-Android-amp-Banner-Ads-(AdMob)
, but I’m still having some issues with it. My game just crashes. I’m using the beta tester package located here:
http://beta.unity3d.com/erik/AndroidAdIntegration.unitypackage
I’ve checked the output using adb (I ran it real time to see whats happening). My current guess is that Java isn’t compiling a new version of the plugin, and I’m not quite sure how to get it to do that. I have come this conclusion because I have changed AdPlugin
Here’s some code to give you guys an idea-- you’ll notice that it crashes on line 48:
E/AndroidRuntime( 2219): at com.some_company.plugin.AdPluginActivity.setupAds(AdPluginActivity.java:4
I/DEBUG ( 1153): Build fingerprint: 'google/passion/passion/mahimahi:2.1/ERD79/22607:user/release-keys'
I/DEBUG ( 1153): pid: 2219, tid: 2225 >>> com.some_company.plugin <<<
I/DEBUG ( 1153): signal 11 (SIGSEGV), fault addr 449a8000
I/DEBUG ( 1153): r0 44845610 r1 449a8000 r2 000019b8 r3 00000008
I/DEBUG ( 1153): r4 8182c570 r5 00000200 r6 00000100 r7 00000200
I/DEBUG ( 1153): r8 00000100 r9 449699d8 10 00040000 fp 0011ac48
I/DEBUG ( 1153): ip 00000000 sp 4755fd10 lr 8105b704 pc afe0df5c cpsr 20000010
D/AndroidRuntime( 2219): Shutting down VM
W/dalvikvm( 2219): threadid=3: thread exiting with uncaught exception (group=0x4001b178)
E/AndroidRuntime( 2219): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 2219): java.lang.NoClassDefFoundError: com.qwapi.adclient.android.view.QWAdView
[COLOR=darkorange]E/AndroidRuntime( 2219): at com.some_company.plugin.AdPluginActivity.setupAds(AdPluginActivity.java:48)[/COLOR]
E/AndroidRuntime( 2219): at com.some_company.plugin.AdPluginActivity.onCreate(AdPluginActivity.java:29)
E/AndroidRuntime( 2219): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 2219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
E/AndroidRuntime( 2219): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime( 2219): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 2219): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 2219): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2219): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2219): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 2219): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2219): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2219): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 2219): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 2219): at dalvik.system.NativeStart.main(Native Method)
I/Process ( 71): Sending signal. PID: 2219 SIG: 3
I/dalvikvm( 2219): threadid=7: reacting to signal 3
E/dalvikvm( 2219): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
Now, here is the entirety of AdPluginActivity.java-- to save you some time, I’ll note that line 48 is:
adView.setAdListener( new SimpleAdListener()
Additionally, I print our some debug that does not appear in the Android log above on line 37 (a bunch of H’s)
package com.some_company.plugin;
import com.qwapi.adclient.android.data.Ad;
import com.qwapi.adclient.android.data.Status;
import com.qwapi.adclient.android.requestparams.*;
import com.qwapi.adclient.android.view.QWAdView;
import com.admob.android.ads.AdView;
import com.admob.android.ads.SimpleAdListener;
import com.admob.android.ads.AdManager;
import com.unity3d.player.UnityPlayerActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;
// Both AdMob and Quattro Wireless (and this activity) dumps information to the 'logcat'.
// Please inspect it using 'adb logcat' from the command line/terminal, to track down faulty behavior.
public class AdPluginActivity extends UnityPlayerActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setupAds();
}
final private boolean useQWads = true;
final private boolean gravityBottom = true;
private void setupAds()
{
[COLOR=darkorange] System.out.println"HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");[/COLOR]
RelativeLayout layout = new RelativeLayout(this);
addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
if (gravityBottom)
layout.setGravity(Gravity.BOTTOM);
// Please read http://developer.admob.com/wiki/Android before trying this code,
// especially the part about how to use test mode, and add test devices (below).
// Also, a valid publisher id is needed, even in test mode it seems.
AdView adView = new AdView(this);
[COLOR=darkorange] adView.setAdListener( new SimpleAdListener()[/COLOR]
{
public void onFailedToReceiveAd(com.admob.android.ads.AdView adView)
{
Log.d("AdListener", "onFailedToReceiveAd: " + adView.toString());
super.onFailedToReceiveAd(adView);
}
public void onFailedToReceiveRefreshedAd(com.admob.android.ads.AdView adView)
{
Log.d("AdListener", "onFailedToReceiveRefreshedAd: " + adView.toString());
super.onFailedToReceiveRefreshedAd(adView);
}
public void onReceiveAd(com.admob.android.ads.AdView adView)
{
Log.d("AdListener", "onReceiveAd: " + adView.toString());
super.onReceiveAd(adView);
}
public void onReceiveRefreshedAd(com.admob.android.ads.AdView adView)
{
Log.d("AdListener", "onReceiveRefreshedAd: " + adView.toString());
super.onReceiveRefreshedAd(adView);
}
} );
adView.setBackgroundColor(0xff000000);
adView.setPrimaryTextColor(0xffffffff);
adView.setSecondaryTextColor(0xffcccccc);
adView.setKeywords("Android game");
adView.setRequestInterval(15);
adView.setVisibility(android.view.View.VISIBLE);
adView.requestFreshAd();
// AdManager.setTestDevices( new String[] { "<add test device ids here>" } );
// AdManager.setPublisherId( "<add publisher id here>" );
layout.addView(adView);
}
}
Now, I’ve tried a couple of things; I noticed on one of the forum posts, someone mentioned changing this:
#!/bin/sh
javac src/com/some_company/plugin/AdPluginActivity.java -classpath [COLOR=darkorange]"/Applications/Unity/Unity.app/Contents/PlaybackEngines/AndroidPlayer/bin/classes.jar;./admob-sdk-android.jar"[/COLOR] -bootclasspath $ANDROID_SDK_ROOT/platforms/android-8/android.jar -d .
jar cvfM plugin.jar com/
To this (same thing as above but no quotes, and semi-colon replaced with colon)
#!/bin/sh
javac src/com/some_company/plugin/AdPluginActivity.java -classpath [COLOR=darkorange]/Applications/Unity/Unity.app/Contents/PlaybackEngines/AndroidPlayer/bin/classes.jar:./admob-sdk-android.jar[/COLOR] -bootclasspath $ANDROID_SDK_ROOT/platforms/android-8/android.jar -d .
jar cvfM plugin.jar com/
That did not work either. I also tried running the above from the terminal:
./build_plugin.sh
(I’m on the dreadful Mac OSX if you haven’t noticed), and this is what I get for an error:
Fatal Error: Unable to find package java.lang in classpath or bootclasspath
com : no such file or directory
java.util.zip.ZipException: ZIP file must have at least one entry
at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:304)
at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:146)
at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:321)
at sun.tools.jar.Main.create(Main.java:468)
at sun.tools.jar.Main.run(Main.java:180)
at sun.tools.jar.Main.main(Main.java:1149)
Thanks for your help in advance. If someone stumbles upon this post in the future, I hope it has or does assist you in setting it up admob.
Thanks
-Rob