xamarin / GooglePlayServicesComponents

Other
316 stars 147 forks source link

Xamarin.GooglePayServices.Ads + lite crash with call System.Datetime.Now on api21 some devices #265

Open pkolosov opened 5 years ago

pkolosov commented 5 years ago

Xamarin.Android Version (eg: 6.0):

10.0

Operating System & Version (eg: Mac OSX 10.11):

Win10, 1903 VS 2019 16.3.2

Google Play Services Version (eg: 8.4.0):

71.1720.1

Describe your Issue:

Xamarin.GooglePayServices.Ads or .Lite crash application with call System.Datetime.Now on api21 (maybe +api22 (5.1)) on Huawei P8 lite, Lenovo Vibe X3, some Asus devices, but work fine on simulators, other devices and api levels.

Steps to Reproduce (with link to sample solution if possible):

1) Create empty Xamarin.Android project in VS 2019.

2) Add standard rows to AndroidManifest.xml:

uses-permission android:name="android.permission.INTERNET"
uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" 

and inside application tag:

    <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544~3347511713" />
    <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />

3) Add two rows to MainActivity.OnCreate:

public class MainActivity : AppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        Android.Gms.Ads.MobileAds.Initialize(ApplicationContext);
        var now = System.DateTime.Now;      // Crash!
        . . . . .

4) Make apk and start test with Firebase Test Lab with device Huawei P8 Lite. Other devices and emulators in TestLab work fine! But users was detected this problem on real devices .

Include any relevant Exception Stack traces, build logs, adb logs:

Error in log:

FATAL EXCEPTION: main Process: ... , PID: 19473 android.runtime.JavaProxyThrowable: System.TypeInitializationException: The type initializer for 'AndroidTimeZones' threw an exception. ---> System.DllNotFoundException: libmono-native.so assembly: type: member:(null) at (wrapper managed-to-native) Interop+Sys.Stat(byte&,Interop/Sys/FileStatus&) at Interop+Sys.Stat (System.ReadOnlySpan1[T] path, Interop+Sys+FileStatus& output) [0x00028] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at System.IO.FileSystem.FileExists (System.ReadOnlySpan1[T] fullPath, System.Int32 fileType, Interop+ErrorInfo& errorInfo) [0x00007] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at System.IO.FileSystem.FileExists (System.ReadOnlySpan`1[T] fullPath) [0x00006] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at System.IO.File.Exists (System.String path) [0x00043] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at System.TimeZoneInfo+AndroidTimeZones.GetDefaultTimeZoneDB () [0x0000a] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at System.TimeZoneInfo+AndroidTimeZones..cctor () [0x00000] in <221cafd91f5b47629c873c1ba4c4bac1>:0 --- End of inner exception stack trace --- at System.TimeZoneInfo.CreateLocal () [0x00000] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at System.TimeZoneInfo.get_Local () [0x00009] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at System.TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc (System.DateTime time, System.Boolean& isAmbiguousLocalDst) [0x00000] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at System.DateTime.get_Now () [0x00008] in <221cafd91f5b47629c873c1ba4c4bac1>:0 at GoogleAdMobTest.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00012] in <99a92838782142789e7bc89d07ad483f>:0 at Android.App.Activity.n_OnCreate_Landroid_osBundle (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <5b63db25151a4501af69735ccbe747ac>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.3(intptr,intptr,intptr) at md5003edefcba496c9593b85de71899eb69.MainActivity.n_onCreate(Native Method) at md5003edefcba496c9593b85de71899eb69.MainActivity.onCreate(MainActivity.java:30) at android.app.Activity.performCreate(Activity.java:6013) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2466) at android.app.ActivityThread.access$1200(ActivityThread.java:152) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5538) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

moljac commented 5 years ago

@pkolosov

Repro sample would speed everything up.

Please

Just link some zip or public repo here...

pkolosov commented 5 years ago

Thanks.

Project zip

moljac commented 4 years ago

@pkolosov

Could you try uncommenting:

//Android.Gms.Ads.MobileAds.Initialize(ApplicationContext);

and see if maybe DateTime itself has issues. Log tells me nothing related to Google.Play.Services.

pkolosov commented 4 years ago

ОК.

Two devices tested with api21 on Firebase TestLab: Huawei P8 Lite & Nexus 5. Same apk with uncommented & commented MobileAds initialization loaded for test. Only uncommented verion on P8 has test fatal error. All journals attahed.

Uncommented Commented

Huawei TAG L21 Android 5.1 has same problem.

pkolosov commented 4 years ago

This is not a problem with bindings library. AdMob SDK initialization conflicts with Xamarin initialization on application start.

This test produces the same error: 1) Add aar sdk files (ads lite) to emty xamarin android project. 2) Add java file with simple static class-adapter to invoke initialization & show rewarded video 3) Make call from C# MainActivity.OnCreate with JNIEnv.CallStaticVoidMethod(). 4) Then DateTime.Now throw same exception.

But.

If skip initialization on app start, rewarded video works fine without any conflicts with mono libraries.