firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
236 stars 39 forks source link

I bought a google pixel3, app crash also:Cause: null pointer dereference #73

Closed iningwei closed 2 years ago

iningwei commented 3 years ago

Not long ago,i post a crash bug:https://github.com/firebase/firebase-unity-sdk/issues/68 But no more feedback from you. In case of the bug is caused by mobie devices of China,i bought a google pixel3 from amazon.com. But it turns out the same.If i fetch fcm token the firsttime,without vpn open,it mush crash.If i used vpn,it can success get token,and not crash. The log as follows, please check it,thanks.

FATAL EXCEPTION: UnityMain Process: com.tj.sgame, PID: 4303 java.lang.Error: Version '2020.3.0f1 (c7b5465681fb)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'arm64-v8a' Build fingerprint: 'google/blueline/blueline:9/PQ1A.181105.017.A1/5081125:user/release-keys' Revision: 'MP1.0' ABI: 'arm64' Timestamp: 2021-10-13 23:09:25-0400 pid: 4303, tid: 4384, name: Thread-12 >>> com.tj.sgame <<< uid: 10160 signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8 Cause: null pointer dereference x0 0000000000000008 x1 00000076166c5cb0 x2 0000000000000004 x3 00000076166c5d29 x4 00000076166c5c68 x5 0000000000000000 x6 455e5e6472606164 x7 7f7f7f7f7f7f7f7f x8 0000000000000000 x9 00000076166c5d29 x10 00000076379abf80 x11 0000007611295a30 x12 0000000012fda888 x13 0000000000000002 x14 0000000000003198 x15 0000000000000000 x16 0000007616af13a8 x17 00000076ba344c40 x18 0000000000000024 x19 0000000000000000 x20 00000076166c5cb0 x21 00000076166c5c68 x22 0000000000000000 x23 00000076166c5d29 x24 0000000000000004 x25 0000000000000008 x26 00000076166c5d28 x27 0000000000000001 x28 0000000000000000 x29 00000076166c5e98 sp 00000076166c5c10 lr 00000076169c43ac pc 00000076ba344c40

backtrace:
      #00 pc 0000000000082c40  /system/lib64/libc.so (pthread_mutex_lock) (BuildId: d045a7ba5823f9952aea98759165b9c3)
      #01 pc 00000000001fe3a8  /data/app/com.tj.sgame-I31tSapNkC5Co1TxBbqWxA==/lib/arm64/libFirebaseCppApp-8_3_0.so (firebase::Mutex::Acquire()+4) (BuildId: 8209be713e18b8cc0f0f9cdc20b6d1f4)
      #02 pc 0000000000203c8c  /data/app/com.tj.sgame-I31tSapNkC5Co1TxBbqWxA==/lib/arm64/libFirebaseCppApp-8_3_0.so (void firebase::ReferenceCountedFutureImpl::CompleteInternal<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, void firebase::ReferenceCountedFutureImpl::CompleteWithResultInternal<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >(firebase::FutureHandle const&, int, char const*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)::'lambda'(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*)>(firebase::FutureHandle const&, int, char const*, void firebase::ReferenceCountedFutureImpl::CompleteWithResultInternal<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >(firebase::FutureHandle const&, int, char const*, std::__ndk1::basic_string<char, std::__ndk1::char_trai...
      #03 pc 0000000000203c40  /data/app/com.tj.sgame-I31tSapNkC5Co1TxBbqWxA==/lib/arm64/libFirebaseCppApp-8_3_0.so (void firebase::ReferenceCountedFutureImpl::CompleteWithResultInternal<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >(firebase::FutureHandle const&, int, char const*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)+64) (BuildId: 8209be713e18b8cc0f0f9cdc20b6d1f4)
      #04 pc 0000000000270820  /data/app/com.tj.sgame-I31tSapNkC5Co1TxBbqWxA==/lib/arm64/libFirebaseCppApp-8_3_0.so (firebase::messaging::CompleteStringCallback(_JNIEnv*, _jobject*, firebase::util::FutureResult, char const*, void*)+136) (BuildId: 8209be713e18b8cc0f0f9cdc20b6d1f4)
      #05 pc 0000000000286c18  /data/app/com.tj.sgame-I31tSapNkC5Co1TxBbqWxA==/lib/arm64/libFirebaseCppApp-8_3_0.so (firebase::util::JniResultCallback_nativeOnResult(_JNIEnv*, _jobject*, _jobject*, unsigned char, unsigned char, _jstring*, long, long)+172) (BuildId: 8209be713e18b8cc0f0f9cdc20b6d1f4)
      #06 pc 0000000000002214  /data/data/com.tj.sgame/cache/oat/arm64/app_resources_lib.odex

    at libc.pthread_mutex_lock(pthread_mutex_lock:0)
    at libFirebaseCppApp-8_3_0.firebase::Mutex::Acquire()(Acquire:4)

2021-10-14 11:09:22.400 4303-4335/? I/chatty: uid=10160(com.tj.sgame) UnityMain identical 14 lines

iningwei commented 3 years ago

Here i give you a easy test rule: After app installed,then close internet connection, then launch app. it crash either.

tienhagioi commented 3 years ago

Same issue on Note 10+

iningwei commented 3 years ago

I have made a demo project,and uploaded it to github:FCMCrashFeedbackDemo,also a demo apk included.

Please check it!!!

Otarius0 commented 3 years ago

I had the same problem. Solution add to androidmanifest:

<meta-data android:name="firebase_messaging_auto_init_enabled" android:value="false" />
<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />

Why does the crash happen on my device?

Firebase at start game tries to get a token, but gets error

2021/10/28 18:51:59.949 22133 22631 Info firebase Firebase Cloud Messaging API Initialized
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId Failed to get FIS auth token
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.android.gms.tasks.Tasks.zza(com.google.android.gms:play-services-tasks@@17.2.1:5)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@17.2.1:8)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.firebase.iid.GmsRpc.setDefaultAttributesToBundle(com.google.firebase:firebase-iid@@21.1.0:11)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.firebase.iid.GmsRpc.startRpc(com.google.firebase:firebase-iid@@21.1.0:1)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.firebase.iid.GmsRpc.getToken(com.google.firebase:firebase-iid@@21.1.0:1)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.firebase.iid.FirebaseInstanceId.lambda$getInstanceId$2$FirebaseInstanceId(com.google.firebase:firebase-iid@@21.1.0:1)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.firebase.iid.FirebaseInstanceId$$Lambda$3.start(Unknown Source:10)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.firebase.iid.RequestDeduplicator.getOrStartGetTokenRequest(com.google.firebase:firebase-iid@@21.1.0:7)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.firebase.iid.FirebaseInstanceId.lambda$getInstanceId$3$FirebaseInstanceId(com.google.firebase:firebase-iid@@21.1.0:5)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.firebase.iid.FirebaseInstanceId$$Lambda$0.then(Unknown Source:6)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.android.gms.tasks.zze.run(com.google.android.gms:play-services-tasks@@17.2.1:1)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.6.0:2)
2021/10/28 18:51:59.975 22133 23093 Error FirebaseInstanceId    at java.lang.Thread.run(Thread.java:784)

Then I call initialization from the application code to get the token and the game crashes

2021/10/28 18:51:59.998 22133 22247 Info Unity Firebase Cloud Messaging API Initialized
2021/10/28 18:52:00.022 22133 22631 Warn firebase Future with handle 1 still exists though its backing API 0xCFF3DC0 is being deleted. Please call Future::Release() before deleting the backing API.
2021/10/28 18:52:00.086 22133 22631 Error CRASH *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2021/10/28 18:52:00.086 22133 22631 Error CRASH Version '2020.3.18f1 (a7d1c678663c)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'arm64-v8a'
2021/10/28 18:52:00.086 22133 22631 Error CRASH Build fingerprint: 'HUAWEI/WAS-LX1/HWWAS-H:8.0.0/HUAWEIWAS-LX1/394(C10):user/release-keys'
2021/10/28 18:52:00.086 22133 22631 Error CRASH Revision: '0'
2021/10/28 18:52:00.086 22133 22631 Error CRASH ABI: 'arm64'
2021/10/28 18:52:00.086 22133 22631 Error CRASH Timestamp: 2021-10-28 18:52:00+0300
2021/10/28 18:52:00.086 22133 22631 Error CRASH pid: 22133, tid: 22631, name: Thread-60  >>> XXXXXXX <<<
2021/10/28 18:52:00.086 22133 22631 Error CRASH uid: 10602
2021/10/28 18:52:00.086 22133 22631 Error CRASH signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x8
2021/10/28 18:52:00.086 22133 22631 Error CRASH Cause: null pointer dereference
2021/10/28 18:52:00.086 22133 22631 Error CRASH     x0  0000000000000008  x1  0000007ddba03d90  x2  0000000000000004  x3  0000007ddba03e09
2021/10/28 18:52:00.086 22133 22631 Error CRASH     x4  0000007ddba03d48  x5  0000000000000000  x6  455e5e6472606164  x7  7f7f7f7f7f7f7f7f
2021/10/28 18:52:00.086 22133 22631 Error CRASH     x8  0000000000000000  x9  0000007ddba03e09  x10 0000007dd1170340  x11 0000000000000003
2021/10/28 18:52:00.086 22133 22631 Error CRASH     x12 0000007eac930e08  x13 0000007ed2d172c0  x14 0000007ed2d17320  x15 0000000000000000
2021/10/28 18:52:00.086 22133 22631 Error CRASH     x16 0000007cf90ae3a8  x17 0000007ed574cba4  x18 0000007ddba04160  x19 0000000000000000
2021/10/28 18:52:00.086 22133 22631 Error CRASH     x20 0000007ddba03d90  x21 0000007ddba03d48  x22 0000000000000000  x23 0000007ddba03e09
2021/10/28 18:52:00.086 22133 22631 Error CRASH     x24 0000000000000004  x25 0000000000000008  x26 0000007ddba03e08  x27 0000000000000001
2021/10/28 18:52:00.086 22133 22631 Error CRASH     x28 0000000000000009  x29 0000007ddba03f78
2021/10/28 18:52:00.086 22133 22631 Error CRASH     sp  0000007ddba03cf0  lr  0000007cf8f813ac  pc  0000007ed574cba4
2021/10/28 18:52:00.086 22133 22631 Error CRASH 
2021/10/28 18:52:00.086 22133 22631 Error CRASH backtrace:
2021/10/28 18:52:00.086 22133 22631 Error CRASH       #00 pc 0000000000067ba4  /system/lib64/libc.so (pthread_mutex_lock) (BuildId: 7a10b679c536bc225fd448e8d7f4768e)
2021/10/28 18:52:00.086 22133 22631 Error CRASH       #01 pc 00000000001fe3a8  /data/app/XXXXXXX-Z_FOT4MpWK9XrtZc--AajA==/lib/arm64/libFirebaseCppApp-8_3_0.so (firebase::Mutex::Acquire()+4) (BuildId: 8209be713e18b8cc0f0f9cdc20b6d1f4)
2021/10/28 18:52:00.087 22133 22631 Error CRASH       #02 pc 0000000000203c8c  /data/app/XXXXXXX-Z_FOT4MpWK9XrtZc--AajA==/lib/arm64/libFirebaseCppApp-8_3_0.so (void firebase::ReferenceCountedFutureImpl::CompleteInternal<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, void firebase::ReferenceCountedFutureImpl::CompleteWithResultInternal<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >(firebase::FutureHandle const&, int, char const*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)::'lambda'(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >*)>(firebase::FutureHandle const&, int, char const*, void firebase::ReferenceCountedFutureImpl::CompleteWithResultInternal<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >(firebase::FutureHandle const&, int, char const*, std::__ndk1::basic_string<char, s...
2021/10/28 18:52:00.087 22133 22631 Error CRASH       #03 pc 0000000000203c40  /data/app/XXXXXXX-Z_FOT4MpWK9XrtZc--AajA==/lib/arm64/libFirebaseCppApp-8_3_0.so (void firebase::ReferenceCountedFutureImpl::CompleteWithResultInternal<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >(firebase::FutureHandle const&, int, char const*, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)+64) (BuildId: 8209be713e18b8cc0f0f9cdc20b6d1f4)
2021/10/28 18:52:00.087 22133 22631 Error CRASH       #04 pc 0000000000270820  /data/app/XXXXXXX-Z_FOT4MpWK9XrtZc--AajA==/lib/arm64/libFirebaseCppApp-8_3_0.so (firebase::messaging::CompleteStringCallback(_JNIEnv*, _jobject*, firebase::util::FutureResult, char const*, void*)+136) (BuildId: 8209be713e18b8cc0f0f9cdc20b6d1f4)
2021/10/28 18:52:00.087 22133 22631 Error CRASH       #05 pc 0000000000286c18  /data/app/XXXXXXX-Z_FOT4MpWK9XrtZc--AajA==/lib/arm64/libFirebaseCppApp-8_3_0.so (firebase::util::JniResultCallback_nativeOnResult(_JNIEnv*, _jobject*, _jobject*, unsigned char, unsigned char, _jstring*, long, long)+172) (BuildId: 8209be713e18b8cc0f0f9cdc20b6d1f4)
2021/10/28 18:52:00.087 22133 22631 Error CRASH       #06 pc 00000000000023d4  /data/data/XXXXXXX/cache/oat/arm64/app_resources_lib.odex
iningwei commented 3 years ago

@Otarius0 THANKS for your kind reply. I have done as you mentioned,yes it indeed not crash any long.But after i used , i can not get token which i need pass it to my server.

iningwei commented 3 years ago

Finally,i do it as follows: 1,add firebase_messaging_auto_init_enabled false at menifest.xml file 2,In app,i check whether internet connect to google.com if yes, i set FirebaseMessaging.TokenRegistrationOnInitEnabled = true, and regist TokenReceived and MessageReceived event.After get token id,i send it to my server. or not, do nothing.

ANY HOW:hope firebase devloper can solve this issue in their sdk.

Otarius0 commented 3 years ago

@iningwei You can try to manual get token used this code

FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{  
    if (task.Result == DependencyStatus.Available)
    {
        _firebaseApp = FirebaseApp.DefaultInstance;

        FirebaseMessaging.TokenReceived += OnTokenReceived;
        FirebaseMessaging.MessageReceived += OnMessageReceived;

        #if UNITY_ANDROID
        FirebaseMessaging.GetTokenAsync().ContinueWithOnMainThread( getTokenTask => {
                if (getTokenTask.IsCompleted)
                {
                    SetToken(getTokenTask.Result);
                }
            }
        );
        #endif
    }
}
iningwei commented 3 years ago

@iningwei You can try to manual get token used this code

FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{  
    if (task.Result == DependencyStatus.Available)
    {
        _firebaseApp = FirebaseApp.DefaultInstance;

        FirebaseMessaging.TokenReceived += OnTokenReceived;
        FirebaseMessaging.MessageReceived += OnMessageReceived;

        #if UNITY_ANDROID
        FirebaseMessaging.GetTokenAsync().ContinueWithOnMainThread( getTokenTask => {
                if (getTokenTask.IsCompleted)
                {
                    SetToken(getTokenTask.Result);
                }
            }
        );
        #endif
    }
}

thanks for your kind reply.

iningwei commented 3 years ago

Finally,i do it as follows: 1,add firebase_messaging_auto_init_enabled false at menifest.xml file 2,In app,i check whether internet connect to google.com if yes, i set FirebaseMessaging.TokenRegistrationOnInitEnabled = true, and regist TokenReceived and MessageReceived event.After get token id,i send it to my server. or not, do nothing.

ANY HOW:hope firebase devloper can solve this issue in their sdk.

here i still have a question:sometimes the first launch of app still crash, the same error log.The ratio is low,but it really exist. @Otarius0 does your app not crash forever?

iningwei commented 3 years ago

@TBarendt Thanks for your reply, the random crash is indeed caused by FirebaseMessaging.TokenRegistrationOnInitEnabled = true;, i removed it and all works fine.

iningwei commented 3 years ago

Finally summary: 1, add following to AndroidManifest.xml < meta - data android: name = "firebase_messaging_auto_init_enabled" android: value = "false" />
< meta - data android: name = "firebase_analytics_collection_enabled" android: value = "false" />

this can aviod firebase auto init case crash while no internet connect when first launch. 2, FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => { var dependencyStatus = task.Result; if (dependencyStatus == Firebase.DependencyStatus.Available) { Debug.Log("--->Firebase sdk result:Available"); Firebase.FirebaseApp app = Firebase.FirebaseApp.DefaultInstance; isAvailable = true; InitializeFCM(); } else { Debug.LogError(System.String.Format( "Firebase sdk init fail. Could not resolve all Firebase dependencies: {0}", dependencyStatus)); } });

    public void InitializeFCM()
    { 
        **//FirebaseMessaging.TokenRegistrationOnInitEnabled = true;**//never set this, otherwise there is some chances to crash while first launch app.
        FirebaseMessaging.GetTokenAsync().ContinueWithOnMainThread(getTokenTask =>
        {
            if (getTokenTask.IsCompleted)
            {
                string token = getTokenTask.Result;
                Debug.LogError("--->FCM Token is:" + token); 
            }
        });

        Debug.Log("Register firebase message receive!");
        Firebase.Messaging.FirebaseMessaging.MessageReceived += FirebaseMessaging_MessageReceived;
    }
Otarius0 commented 3 years ago

@iningwei Looking at Crashlytics, crashes still happen. But I think they on the devices who are updated to the new version of SDK and they still have TokenRegistrationOnInitEnabled = true. Firebase version 6.2.1

iningwei commented 3 years ago

Update: Do not set < meta - data android: name = "firebase_analytics_collection_enabled" android: value = "false" /> at AndroidManifest.xml, it will cause firebase events can not be sent to google server!!!!

I have tested remove it.And all works fine.

@Otarius0 currently,no crashes.

chkuang-g commented 2 years ago

@iningwei

Do you still need the workaround you mentioned in https://github.com/firebase/firebase-unity- sdk/issues/73#issuecomment-979775159 with the latest Firebase SDK, ex. 9.4.0?

I suspect these patches are related to your situations. https://firebase.google.com/support/release-notes/unity#fcm_2 https://firebase.google.com/support/release-notes/unity#fcm_3

Please let us know.

google-oss-bot commented 2 years ago

Hey @iningwei. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 2 years ago

Since there haven't been any recent updates here, I am going to close this issue.

@iningwei if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.