5

I am trying to use AdvertisingIdClient to fetch the advertisement id of my AIR app. So i did like AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context). I am not getting any compile time error. I generated ANE from this. When control encounters this statement, it immediately throws NoClassDefFoundError. I am not getting what exactly is happening. Here is my extension code

public class GetAdvertismentID implements FREFunction
{
    @Override
    public FREObject call(FREContext arg0, FREObject[] arg1)
    {
        Activity activity = arg0.getActivity();
        Context context = activity.getApplicationContext();

        String advertId = "initializeByGet\n";

        try
        {
            AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);
            //if (!adInfo.isLimitAdTrackingEnabled())
                    //advertId = advertId + adInfo.getId();
        } catch(Error e) {

            String stackTrace = "";
            StackTraceElement[] stackArray = e.getStackTrace();
            for(int i = 0; i < stackArray.length; i++)
                stackTrace += stackArray[i].toString() + "\n";

            advertId += "Error::::::::::::::::";
            advertId += "\nLocalized Message : " + e.getLocalizedMessage();
            advertId += "\nMessage : " + e.getMessage();
            advertId += "\ntoString() : " + e.toString();
            advertId += "\nCause : " + e.getCause();
            advertId += "\nStack Trace : " + stackTrace;

        } catch (Throwable t) {

            advertId += "\nThrowable::::::::::::";
            advertId += "\nLocalized Message : " + t.getLocalizedMessage();
            advertId += "\nMessage : " + t.getMessage();
            advertId += "\ntoString() : " + t.toString();
        }


        try
        {
            return FREObject.newObject(advertId);
        }
        catch(Exception e)
        {
            return null;
        }
    }
}

When i execute this after generating ANE, i will get this output:

initializeByGet
Error::::::::::::::::
Localized Message : com.google.android.gms.ads.identifier.AdvertisingIdClient
Message : com.google.android.gms.ads.identifier.AdvertisingIdClient
toString() : java.lang.NoClassDefFoundError: com.google.android.gms.ads.identifier.AdvertisingIdClient
Cause : null
Stack Trace : com.games24x7.extension.GetAdvertismentID.call(GetAdvertismentID.java:28)
com.adobe.air.Entrypoints.EntryMainWrapper(Native Method)
com.adobe.air.Entrypoints.EntryMainWrapper(Native Method)
com.adobe.air.Entrypoints.EntryMain(Entrypoints.java:139)
com.adobe.air.AndroidActivityWrapper.LaunchApplication(AndroidActivityWrapper.java:997)
com.adobe.air.AndroidActivityWrapper.onSurfaceInitialized(AndroidActivityWrapper.java:1196)
com.adobe.air.AIRWindowSurfaceView.surfaceChanged(AIRWindowSurfaceView.java:746)
android.view.SurfaceView.updateWindow(SurfaceView.java:554)
android.view.SurfaceView.access$000(SurfaceView.java:81)
android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1793)
android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2695)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:156)
android.app.ActivityThread.main(ActivityThread.java:4987)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
dalvik.system.NativeStart.main(Native Method)

I feel the problem here is, it is not able to find the path of some class at runtime. So I tried all the options like: Using the new Android Advertiser id inside an SDK , How do I disable proguard for building my Android app? , http://jmsliu.com/2143/add-admob-ads-in-flash-based-android-apps.html Unfortunately, none of them worked. Please help me if any of you have done this. I am using Flash Builder 4.7 with AIR SDK 14.0.

Community
  • 1
  • 1
Santu
  • 55
  • 1
  • 4
  • Are you sure that you embedded Google Play Service in your ANE? When you compile the ANE file, it will not throw any exception even you don't include the Google Play Service Lib inside. – James Aug 12 '14 at 08:36
  • Hi James. I came to know that it is not embedding Google Play Service in my ANE. When i extracted the ANE, the google-play-services.jar is present, but not able to access any of the classes of it. I checked it with AdView class. Same error. And i don't know how to embed it. – Santu Aug 12 '14 at 09:16

1 Answers1

2

When creating the ANE you should ideally extract the google-play-services classes from the JAR and include them inside your ANE's JAR. See this.

If the classes are still missing inside the final APK itself, check out my question (and subsequently my answer) to a similar issue. I was trying to integrate the latest Google play services SDK into our game and I noticed that the dx tool in the AIR SDK was stripping out the Google play classes. You can confirm this by using this tool to verify whether those classes are indeed missing in the final APK.

UPDATE:

I previously injected the required classes into the APK using the same dex2jar tool mentioned above. But that is not necessary. You can simply update the dx tool inside the AIR SDK.

Community
  • 1
  • 1
SNce
  • 2,453
  • 1
  • 16
  • 14
  • Ok SNce. Let me try this. Thanks for the response. – Santu Aug 12 '14 at 13:37
  • Thanks a lot SNce. It worked. Actually replacing dx.jar worked for me. – Santu Aug 12 '14 at 15:43
  • Hi SNce. That issue got fixed but now i'm facing another new issue. I am getting this error "A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the element: " Although i have added the meta-data in the AndroidManifest.xml of java application. If i add this in Application-app.xml, it will hang without any error. – Santu Aug 13 '14 at 12:16
  • This metadata tag should be added in the AndroidManifest.xml. This is what I have in mine --> instead of the version value you can alternatively use "@integer/google_play_services_version" if you have properly set up "packagedResources" in your platform.xml – SNce Aug 13 '14 at 17:06
  • Actually I have already added that in my AndroidManifest.xml. Still i am getting this error. But i didn't get how to set up "packagedResources" in platform.xml. Also i have posted a new question. Here is its link: http://stackoverflow.com/questions/25287764/advertisingidclient-asking-for-meta-data-although-it-has-been-included Please help me in getting rid of this issue... :( – Santu Aug 13 '14 at 18:09
  • @Santu Answered that question. – SNce Sep 04 '14 at 11:39
  • Thanks SNce. Actually the problem with me was different. I had added that meta-data tag at some other place.. :) – Santu Sep 05 '14 at 11:53