admin管理员组

文章数量:1277280

For some context to the project's structure, it's a Unity game that's within a Flutter project. This was achieved using the flutter-unity-widget. So far I have been setting up Firebase Analytics as a Unity project.

Now onto the issue. I have been getting the error report:

Failed to read Firebase options from the app's resources. Either make sure google-services.json is included in your build or specify options explicitly.

The FirebaseApp.androidlib is located within the unityLibrary and it has the google-services.xml file inside. google-services.xml in FirebaseApp.androidlib

I have also tried just manually inputting the file into the app's root. Like so: google-services.json in android root

For my current attempt, I have set the AppOptions for the FirebaseApp explicitly hoping it would fix the issue as stated but it's still returning the error.

There could be the possibility of me not setting up proguard or the build gradle properly.

Proguard:

-keep class bitter.jnibridge.* { *; }
-keep class com.unity3d.player.* { *; }
-keep interface com.unity3d.player.IUnityPlayerLifecycleEvents { *; }
-keep class .fmod.* { *; }
-keep class com.google.androidgamesdk.ChoreographerCallback { *; }
-keep class com.google.androidgamesdk.SwappyDisplayManager { *; }
-keep class com.unity3d.plugin.UnityAndroidPermissions** { *; }
-keep class com.unity3d.plugin.*{ *; }
-keep class android.telephony.*{ *; }
-keep class com.appsflyer.** { *; }
-keepclassmembers class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}
#noinspection ShrinkerUnresolvedReference
#unity
-keep class com.ironsource.unity.androidbridge.** { *;}
-keep class com.google.android.gms.ads.** {public *;}
-keep class com.google.android.gms.appset.** { *; }
-keep class com.google.android.gms.tasks.** { *; }
#adapters
-keep class com.ironsource.adapters.** { *; }
#sdk
-dontwarn com.ironsource.**
-dontwarn com.ironsource.adapters.**
-keepclassmembers class com.ironsource.** { public *; }
-keep public class com.ironsource.**
-keep class com.ironsource.adapters.** { *;
}
#omid
-dontwarn com.iab.omid.**
-keep class com.iab.omid.** {*;}
#javascript
-keepattributes JavascriptInterface
-keepclassmembers class * { @android.webkit.JavascriptInterface <methods>; }
#firebase
-keep class com.google.firebase.** { *; }
-ignorewarnings

Build.gradle

apply plugin: 'com.android.library'

dependencies {
    implementation(name: 'com.sglib.easymobile.easy-mobile-1.5.1', ext:'aar')
    implementation(name: 'unityandroidpermissions', ext:'aar')
    implementation(name: 'unity-classes', ext:'jar')
    implementation(name: 'arcore_client', ext:'aar')
    implementation(name: 'UnityARCore', ext:'aar')
    implementation(name: 'common', ext:'aar')
    implementation(name: 'ARPresto', ext:'aar')
    implementation(name: 'androidx.legacy.legacy-support-v4-1.0.0', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-ads-identifier-18.1.0', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-stats-17.1.0', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-basement-18.5.0', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-tasks-18.2.0', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-base-18.5.0', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-analytics-impl-18.2.0', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-analytics-18.1.1', ext:'aar')
    implementation(name: 'com.google.android.gms.play-services-tagmanager-v4-impl-18.1.1', ext:'aar')
    implementation(name: 'com.appsflyer.unity-wrapper-6.12.10', ext:'aar')
    implementation(name: 'com.ironsource.adapters.unityadsadapter-4.3.31', ext:'aar')
    implementation(name: 'com.ironsource.sdk.mediationsdk-7.5.0', ext:'aar')
    implementation files('IronSource.androidlib/libs/IronSource-bridge.jar')
    implementation(name: 'com.google.firebase.firebase-analytics-22.2.0', ext:'aar')
    implementation(name: 'com.google.firebase.firebase-analytics-unity-12.6.0', ext:'aar')
    implementation(name: 'com.google.firebase.firebase-app-unity-12.6.0', ext:'aar')
    implementation(name: 'com.google.firebase.firebase-common-21.0.0', ext:'aar')
}

android {
    compileSdkVersion 33
    buildToolsVersion '30.0.2'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 29
        targetSdkVersion 33
        ndk {
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
        versionCode 29
        versionName '1.0.0'
        consumerProguardFiles 'proguard-unity.txt'
    }

    lintOptions {
        abortOnError false
    }

    aaptOptions {
        noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.unityexp']
        ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
    }

    packagingOptions {
        doNotStrip '*/armeabi-v7a/*.so'
        doNotStrip '*/arm64-v8a/*.so'
    }
}

def getSdkDir() {
    Properties local = new Properties()
    local.load(new FileInputStream("${rootDir}/local.properties"))
    return local.getProperty('sdk.dir')
}

def BuildIl2Cpp(String workingDir, String configuration, String architecture, String abi, String[] staticLibraries) {
    def commandLineArgs = []
    commandLineArgs.add("--compile-cpp")
    commandLineArgs.add("--platform=Android")
    commandLineArgs.add("--architecture=" + architecture)
    commandLineArgs.add("--outputpath=" + workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.so")
    commandLineArgs.add("--libil2cpp-static")
    commandLineArgs.add("--baselib-directory=" + workingDir + "/src/main/jniStaticLibs/" + abi)
    commandLineArgs.add("--configuration=" + configuration)
    commandLineArgs.add("--dotnetprofile=unityaot-linux")
    commandLineArgs.add("--profiler-report")
    commandLineArgs.add("--profiler-output-file=" + workingDir + "/build/il2cpp_"+ abi + "_" + configuration + "/il2cpp_conv.traceevents")
    commandLineArgs.add("--print-command-line")
    commandLineArgs.add("--generatedcppdir=" + workingDir + "/src/main/Il2CppOutputProject/Source/il2cppOutput")
    commandLineArgs.add("--cachedirectory=" + workingDir + "/build/il2cpp_"+ abi + "_" + configuration + "/il2cpp_cache")
    commandLineArgs.add("--tool-chain-path=" + android.ndkDirectory)
    staticLibraries.eachWithIndex {fileName, i->
        commandLineArgs.add("--additional-libraries=" + workingDir + "/src/main/jniStaticLibs/" + abi + "/" + fileName)
    }
    def executableExtension = ""
    if (.gradle.internal.os.OperatingSystem.current().isWindows())
        executableExtension = ".exe"
    exec {
        executable workingDir + "/src/main/Il2CppOutputProject/IL2CPP/build/deploy/il2cpp" + executableExtension
        args commandLineArgs
        environment "ANDROID_SDK_ROOT", getSdkDir()
    }
    delete workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.sym.so"
    ant.move(file: workingDir + "/src/main/jniLibs/" + abi + "/libil2cpp.dbg.so", tofile: workingDir + "/symbols/" + abi + "/libil2cpp.so")
}

android {
    task BuildIl2CppTask {
        doLast {
              BuildIl2Cpp(projectDir.toString().replaceAll('\\\\', '/'), 'Release', 'armv7', 'armeabi-v7a', [  ] as String[]);
              BuildIl2Cpp(projectDir.toString().replaceAll('\\\\', '/'), 'Release', 'arm64', 'arm64-v8a', [  ] as String[]);
        }
    }
    afterEvaluate {
        if (project(':unityLibrary').tasks.findByName('mergeDebugJniLibFolders'))
            project(':unityLibrary').mergeDebugJniLibFolders.dependsOn BuildIl2CppTask
        if (project(':unityLibrary').tasks.findByName('mergeReleaseJniLibFolders'))
            project(':unityLibrary').mergeReleaseJniLibFolders.dependsOn BuildIl2CppTask
    }
    sourceSets {
        main {
            jni.srcDirs = ["src/main/Il2CppOutputProject"]
        }
    }
}

本文标签: androidFirebase UnityFailed to read Firebase options from the app39s resourcesStack Overflow