EditBlock:我在android studio中的一个新的空项目上测试了Firebase。 firebase成功初始化。我已经连接,并且能够很好地创建用户。如果我构建一个jar文件导入Unity并在那里构建项目,则firebase初始化不成功。我似乎无法找到原因,但感觉我的应用程序和firebase之间的连接不再存在,如果有人知道我错过了什么,那将会非常令人满意。
我目前有一个有效的Android活动,但仅限于从Android Studio构建。自从我添加Firebase支持后,它从Unity构建时停止工作。我尝试了许多不同的帖子中的许多不同的东西,问题与此类似,但从未设法解决我的问题。我根据设置有不同的错误,我不确定哪一个最接近解决方案。我正在使用PlayServiceResolver,它可以帮助处理可能重复的依赖项。我知道那里有很多东西,但我真的不知道还有什么可以尝试。
这是我目前的设置:
的build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.1.0'
}
app.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "me.devhelp.unityplugin"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.0.0'
compile 'com.google.code.gson:gson:2.8.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
compile 'com.google.android.gms:play-services-location:11.2.0'
provided files('libs/classes.jar')
}
task clearJar(type: Delete) {
delete '/AndroidPlugin.jar'
}
task androidReleaseJar(type: Jar) {
from "$buildDir/intermediates/classes/release/"
exclude '**/BuildConfig.class'
exclude '**/R.class'
exclude '**/R$*.class'
dependsOn 'assembleRelease'
}
task makeJar(type: Copy) {
from('build/libs/')
into("$buildDir")
include('app.jar')
rename ('app.jar', 'AndroidPlugin.jar')
}
makeJar.dependsOn(clearJar, build)
clearJar.dependsOn('androidReleaseJar', build)
apply plugin: 'com.google.gms.google-services'
Unity中的AndroidManifest.xml(AndroidStudio中的AndroidManifest.xml是不同的,因为我使用普通的Activity来测试而不是UnityPlayerActivity):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="me.devhelp.unityplugin">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name="me.devhelp.unityplugin.UnityPluginActivity" android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="me.devhelp.unityplugin.LocationService"
android:process=":UnityPluginLocationService" />
<provider
android:name="me.devhelp.unityplugin.LocationContentProvider"
android:authorities="me.devhelp.plugin.provider.store"
android:exported="false" />
</application>
</manifest>
如果我从AndroidStudio安装apk,当我在活动的onCreate()中调用FirebaseApp.initializeApp(this)时,init是成功的,并且在调用FirebaseAuth.getInstance时我没有得到java.lang.ClassNotFoundException( );但是这是我从Unity开始构建后得到的Logcat错误:
09-01 15:29:55.869 9875-9875/? I/FirebaseInitProvider: FirebaseApp initialization unsuccessful
09-01 15:29:55.879 9875-9875/? I/LocationPlugin: DBHelper init
...
09-01 15:29:56.119 9875-9875/? I/LocationPlugin: UnityPluginActivity:onCreate
09-01 15:29:56.119 9875-9875/? D/AndroidRuntime: Shutting down VM
Process: me.devhelp.unityplugin, PID: 29432
java.lang.Error: FATAL EXCEPTION[main]
Unity version : 5.6.1f1
Device model : LGE LG-V497
Device fingerprint: lge/t8lte_rgs_ca/t8lte:5.0.2/LRX22G/152291201d423:user/release-keys
Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{me.devhelp.unityplugin/me.devhelp.unityplugin.UnityPluginActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process me.devhelp.unityplugin.Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
...
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process me.devhelp.unityplugin.Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
...
我曾经在app.gradle中拥有依赖项“com.google.firebase:firebase-core:11.2.0”,AndroidStudio版本可以使用或不使用它。但是如果我在jar解析器脚本中添加或不添加依赖项,我会得到不同的错误(我猜测与重复有关)。如果我不添加它,我在调用FirebaseApp.initializeApp(this)时会得到一个java.lang.ClassNotFoundException,如果我添加它,错误就是构建处理AAR插件时它说系统找不到指定的文件(Unity控制台):
IOException: Failed to Move File / Directory from 'Temp/StagingArea\android-libraries\firebase-core-11.2.0\classes.jar' to 'Temp/StagingArea\android-libraries\firebase-core-11.2.0\libs\classes.jar'.
UnityEditor.Android.PostProcessor.Tasks.ProcessAAR.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTargetGroup targetGroup, BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.BuildReporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:186)
UnityEditor.HostView:OnGUI()
另一件可能相关的事情是,当解析器注册依赖项时,我确实会收到此错误:
IOException: Directory C:\Users\TRIPLE ~1\AppData\Local\Temp\jb5dcmui.673 is not empty
System.IO.Directory.Delete (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:178)
Google.JarResolver.PlayServicesSupport.DeleteExistingFileOrDirectory (System.String path, Boolean includeMetaFiles)
GooglePlayServices.ResolverVer1_1.ShouldExplode (System.String aarPath)
GooglePlayServices.ResolverVer1_1+<GradleResolution>c__AnonStorey11.<>m__1D(GooglePlayServices.Result result)
GooglePlayServices.ResolverVer1_1+<GradleResolution>c__AnonStorey11+<GradleResolution>c__AnonStorey12.<>m__26()
GooglePlayServices.PlayServicesResolver.PumpUpdateQueue ()
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorApplicationBindings.gen.cs:249)