Quickstart-unity: Support android.arch.lifecycle:extensions:1.1.1

Created on 15 Jul 2018  路  5Comments  路  Source: firebase/quickstart-unity

If I add the following myDependencies.xml file to my unity project (or the quickstart project), Firebase is no longer able to initialize:

```



https://maven.google.com



logcat error:

07-12 15:57:26.153: W/System.err(9036): java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.arrowsd.horizonexplorer. Make sure to call FirebaseApp.initializeApp(Context) first.
07-12 15:57:26.154: W/System.err(9036): at com.google.firebase.FirebaseApp.getInstance(Unknown Source:56)
07-12 15:57:26.154: W/System.err(9036): at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
07-12 15:57:26.154: W/System.err(9036): at com.unity3d.player.UnityPlayer.c(Unknown Source:0)
07-12 15:57:26.154: W/System.err(9036): at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source:72)
07-12 15:57:26.154: W/System.err(9036): at android.os.MessageQueue.next(MessageQueue.java:394)
07-12 15:57:26.154: W/System.err(9036): at android.os.Looper.loop(Looper.java:142)
07-12 15:57:26.154: W/System.err(9036): at com.unity3d.player.UnityPlayer$e.run(Unknown Source:32)
07-12 15:57:26.154: E/firebase(9036): new_app
07-12 15:57:26.154: E/Unity(9036): new_app
07-12 15:57:26.154: E/Unity(9036):
07-12 15:57:26.154: E/Unity(9036): (Filename: ./Runtime/Export/Debug.bindings.h Line: 43)
07-12 15:57:26.154: E/firebase(9036): Failed to initialize the default Firebase App.
07-12 15:57:26.184: E/Unity(9036): InitializationException: Firebase app creation failed.
07-12 15:57:26.184: E/Unity(9036): at Firebase.FirebaseApp.CreateAndTrack (Firebase.CreateDelegate createDelegate, Firebase.FirebaseApp existingProxy) [0x00000] in :0
07-12 15:57:26.184: E/Unity(9036): at Firebase.FirebaseApp.Create () [0x00000] in :0
07-12 15:57:26.184: E/Unity(9036): at Firebase.FirebaseApp.get_DefaultInstance () [0x00000] in :0
07-12 15:57:26.184: E/Unity(9036): at Firebase.Analytics.FirebaseAnalytics..cctor () [0x00000] in :0
07-12 15:57:26.184: E/Unity(9036): Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Firebase.Analytics.FirebaseAnalytics
07-12 15:57:26.184: E/Unity(9036): at CustomAnalytics.sendFirebaseCustomEvent (System.String eventName, IDictionary`2 parameters) [0x00000] in :0
07-12 15:57:26.184: E/Unity(9036): at CustomAnalytics.Update () [0x00000] in :0


Unity Android dependency resolver shows a warning:

Some conflicting dependencies were found.
The following dependency versions were modified:
com.google.firebase:firebase-common:16.0.0 --> com.google.firebase:firebase-common:+
com.google.android.gms:play-services-base:15.0.1 --> com.google.android.gms:play-services-base:+
com.google.firebase:firebase-core:16.0.1 --> com.google.firebase:firebase-core:+
com.google.firebase:firebase-analytics:16.0.1 --> com.google.firebase:firebase-analytics:+
android.arch.lifecycle:extensions:1.1.1 --> android.arch.lifecycle:extensions:+
```

I require 1.1.1 as a dependency for another plugin, and this is stopping me from being able to integrate Firebase Analytics.

Example of this happening: https://github.com/Crashthatch/quickstart-unity/tree/bugdemo/lifecycle-common-1.1.1-breaks-firebase-analytics/analytics/testapp

question

Most helpful comment

@Crashthatch FYI I just noticed the last patch I made to the Android Resolver breaks some of the use cases it needs to support e.g dealing with two user specified dependencies that are incompatible. So I recommend keeping an eye on our https://github.com/googlesamples/unity-jar-resolver repo as we'll likely change the dependency specification API for choosing a dependency that should not be auto-upgraded when a conflict is found.

All 5 comments

@Crashthatch you need to add a version of android.arch.lifecycle:extensions that is compatible with the AARs shipped with Firebase. As you can see, the Android Resolver (see https://github.com/googlesamples/unity-jar-resolver) is pulling the latest of everything as it can't find a compatible set of AARs that work with android.arch.lifecycle:extensions.

Now that said, it could be that you're running into a regression with Play Services Resolver 1.7.75 that broke variable replacement in Android Manifest files. You could try pulling 1.7.74 from the repo instead to see whether that fixes your issue.

you need to add a version of android.arch.lifecycle:extensions that is compatible with the AARs shipped with Firebase

I am using another plugin that requires android.arch.lifecycle:extensions:1.1.1 (https://mvnrepository.com/artifact/com.mapbox.mapboxsdk/mapbox-android-telemetry/3.1.4) and this issue is a feature-request that firebase be upgraded to be compatible with android.arch.lifecycle:extensions:1.1.1.

At the moment my "workaround" is to not use Firebase. (Is it somehow possible to include 2 different versions of the android.arch.lifecycle:extensions library to make both plugins happy? Unity doesn't seem to have particularly advanced package management...)

@Crashthatch Play Services Resolver 1.2.79 will now keep all explicitly specify dependencies, so if the other plugin wants to use android.arch.lifecycle:extensions:1.1.1 you can use it it's up to you to select the Android libraries that are compatible with Firebase. You're probably wondering how that is possible? Well as long as you don't bump the major version of any Firebase Android library dependency you're ok as everything is semantically versioned and API compatible across minor version changes.

Looking at http://mvnrepository.com/artifact/android.arch.lifecycle/extensions/1.1.1 the only potential conflict is with the Android support library which can be safely bumped to latest for Firebase.

Yes, I can confirm that Play Services Resolver 1.2.79 resolved the following set of packages, which seem to work correctly together:

<dependencies>
  <packages>
    <package>android.arch.lifecycle:extensions:1.1.1</package>
    <package>com.android.support:animated-vector-drawable:26.1.0</package>
    <package>com.android.support:appcompat-v7:26.1.0</package>
    <package>com.android.support:support-compat:26.1.0</package>
    <package>com.android.support:support-core-ui:26.1.0</package>
    <package>com.android.support:support-core-utils:26.1.0</package>
    <package>com.android.support:support-media-compat:26.1.0</package>
    <package>com.android.support:support-v4:26.1.0</package>
    <package>com.google.android.gms:play-services-base:15.0.1</package>
    <package>com.google.code.gson:gson:2.8.2</package>
    <package>com.google.firebase:firebase-analytics:16.0.1</package>
    <package>com.google.firebase:firebase-analytics-unity:5.1.1</package>
    <package>com.google.firebase:firebase-app-unity:5.1.1</package>
    <package>com.google.firebase:firebase-common:16.0.0</package>
    <package>com.google.firebase:firebase-core:16.0.1</package>
  </packages>
  <files>
    <file>Assets/Plugins/Android/android.arch.core.common-1.1.1.jar</file>
    <file>Assets/Plugins/Android/android.arch.core.runtime-1.1.1.aar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.common-1.1.1.jar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.extensions-1.1.1.aar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.livedata-1.1.1.aar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.livedata-core-1.1.1.aar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.runtime-1.1.1.aar</file>
    <file>Assets/Plugins/Android/android.arch.lifecycle.viewmodel-1.1.1.aar</file>
    <file>Assets/Plugins/Android/com.android.support.animated-vector-drawable-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.appcompat-v7-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-annotations-26.1.0.jar</file>
    <file>Assets/Plugins/Android/com.android.support.support-compat-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-core-ui-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-core-utils-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-fragment-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-media-compat-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-v4-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.android.support.support-vector-drawable-26.1.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-ads-identifier-15.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-base-15.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-basement-15.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-measurement-base-16.0.0.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-stats-15.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.android.gms.play-services-tasks-15.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.code.gson.gson-2.8.2.jar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-analytics-16.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-analytics-impl-16.1.1.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-analytics-unity-5.1.1.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-app-unity-5.1.1.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-common-16.0.0.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-core-16.0.1.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-iid-16.0.0.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-iid-interop-16.0.0.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-measurement-connector-16.0.0.aar</file>
    <file>Assets/Plugins/Android/com.google.firebase.firebase-measurement-connector-impl-16.0.1.aar</file>
  </files>
</dependencies>

Thanks for the help!

@Crashthatch FYI I just noticed the last patch I made to the Android Resolver breaks some of the use cases it needs to support e.g dealing with two user specified dependencies that are incompatible. So I recommend keeping an eye on our https://github.com/googlesamples/unity-jar-resolver repo as we'll likely change the dependency specification API for choosing a dependency that should not be auto-upgraded when a conflict is found.

Was this page helpful?
0 / 5 - 0 ratings