FirebaseApp not found in Unity Android release

Viewed 293

I am working on a Unity (version 2020.3.3f1) application that is being released for desktop and Android, everything was working fine until I had to release on Google Play in which I had to change some settings and update Firebase SDK (to 8.8.0) and java (to java8/jdk1.8.0_321) and Play services resolver (now external dependency manager), after that the desktop and Editor work absolutely fine but the Android release doesn't.

My code:

static void initializeDatabase()
{
    Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
        var dependencyStatus = task.Result;
        if (dependencyStatus == Firebase.DependencyStatus.Available)
        {
            app = Firebase.FirebaseApp.DefaultInstance;
            Debug.Log("Firebase app at db success");
            reference = FirebaseDatabase.GetInstance(app).RootReference;
            FBStorage.setApp(app);
        }
        else
        {
            UnityEngine.Debug.LogError("Firebase App error at db " + System.String.Format("Could not resolve all Firebase dependencies: {0}", dependencyStatus));
        }
    });
}

public static void setApp(FirebaseApp app)
{
    instance = new FBStorage();
    storage = FirebaseStorage.GetInstance(app, "...");
    root_storage_ref = storage.GetReferenceFromUrl("...");
    
    if(storage != null && root_storage_ref != null)
    {
        Debug.Log("Firebase storage success");
    }
    else
    {
        Debug.LogError("Firebase Storage Error");
    }    
}

And these are the errors I get when it tries to initialize the app in the first code block:

Error: Java class com/google/firebase/FirebaseApp not found.  Please verify the AAR which contains the com/google/firebase/FirebaseApp class is included in your app.

Error: clazz

Error: Unable to check Google Play services availablity as the com.google.android.gms.common.GoogleApiAvailability class is not present in this application.

Error: Firebase App error at db Could not resolve all Firebase dependencies: UnavailableOther<>c:<initializeDatabase>b__11_0(Task`1)
System.Threading.ThreadPoolWorkQueue:Dispatch()

I have tried multiple solutions such as this https://stackoverflow.com/a/68197350/10781620 and this https://github.com/firebase/quickstart-unity/issues/1179#issuecomment-976412970 (changing crashlytics to suit my problem ofcourse), also tried force resolve in Android Resolver multiple times.

My AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools">
    <application android:extractNativeLibs="true" android:name="androidx.multidex.MultiDexApplication" android:allowBackup="false">
        <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" android:extractNativeLibs="true" />
        </activity>
    </application>
</manifest>

My baseProjectTemplate.gradle:

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
    
allprojects {
    buildscript {
        repositories {**ARTIFACTORYREPOSITORY**
            google()
            jcenter()
        }
        
        dependencies {
            classpath 'com.android.tools.build:gradle:3.4.0'
            **BUILD_SCRIPT_DEPS**
        }
    }
    
    repositories {**ARTIFACTORYREPOSITORY**
        google()
        jcenter()
        flatDir {
            dirs "${project(':unityLibrary').projectDir}/libs"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My gradleTemplate.properties:

unityStreamingAssets=.unity3d**STREAMING_ASSETS**
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
android.enableR8=**MINIFY_WITH_R_EIGHT**
android.useAndroidX=true
android.enableJetifier=true
# Android Resolver Properties Start
android.useAndroidX=true
android.enableJetifier=true
# Android Resolver Properties End
**ADDITIONAL_PROPERTIES**
android.bundle.enableUncompressedNativeLibs=false

My mainTemplate.gradle:

apply plugin: 'com.android.library'
**APPLY_PLUGINS**
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.core:core:1.0.1'
    implementation "androidx.multidex:multidex:2.0.1"
    **DEPS**}

android {
    compileSdkVersion **APIVERSION**
    buildToolsVersion '**BUILDTOOLS**'
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    
    defaultConfig {
        minSdkVersion **MINSDKVERSION**
        multiDexEnabled true
        targetSdkVersion **TARGETSDKVERSION**
        ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
        versionCode **VERSIONCODE**
        versionName '**VERSIONNAME**'
        consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
    }
    
    lintOptions {
        abortOnError false
    }
    
    aaptOptions {
        noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }**PACKAGING_OPTIONS**
}**REPOSITORIES**
**IL_CPP_BUILD_SETUP**
**SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**

My proguard-user.txt:

-keep class com.google.firebase.** { *; }

And these are my project settings: Build settings AndroidResolver settings

0 Answers
Related