AdvertisingIdClient.getAdvertisingIdInfo(context) is thworing NoClassDefFoundError

拟墨画扇 提交于 2019-12-19 03:39:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/25258049/advertisingidclient-getadvertisingidinfocontext-is-thworing-noclassdeffounderr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!