其他分享
首页 > 其他分享> > android – AdvertisingIdClient.getAdvertisingIdInfo(context)正在考虑NoClassDefFoundError

android – AdvertisingIdClient.getAdvertisingIdInfo(context)正在考虑NoClassDefFoundError

作者:互联网

我正在尝试使用AdvertisingIdClient来获取我的AIR应用程序的广告ID.所以我确实喜欢AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context).
我没有得到任何编译时错误.我从中生成了ANE.当控件遇到此语句时,它会立即抛出NoClassDefFoundError.我不知道到底发生了什么.
这是我的扩展代码

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;
        }
    }
}

当我在生成ANE后执行此操作时,我将获得此输出:

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)

我觉得这里的问题是,它无法在运行时找到某个类的路径.所以我尝试了所有选项:
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
不幸的是,它们都没有奏效.如果你们有人这样做,请帮助我.
我正在使用Flash Builder 4.7和AIR SDK 14.0.

解决方法:

在创建ANE时,您最好从JAR中提取google-play-services类,并将它们包含在ANE的JAR中.见this.

如果最终APK本身内的类仍然缺失,请查看类似问题的my question(以及随后的答案).我试图将最新的Google Play服务SDK集成到我们的游戏中,我注意到AIR SDK中的dx工具正在剥离Google Play类.您可以使用this tool来确认这一点,以验证最终APK中是否确实缺少这些类.

更新:

我之前使用上面提到的相同的dex2jar工具将所需的类注入到APK中.但这不是必要的.您只需更新AIR SDK中的dx工具即可.

标签:android,google-play-services,air,advertising,air-native-extension
来源: https://codeday.me/bug/20190703/1363573.html