Unity Android应用启动时崩溃

15

好的,自从我上次成功构建以来,我所做的一切就是尝试将Google Play服务添加到我的游戏中,源代码来自这里

我导入了Unity安装包,并在相关设置窗口中设置了适用于Android的Google Play游戏。

我尝试在此时构建,但是未能成功,收到一个有关dex文件之间存在冲突的奇怪错误。我将其缩小到由assets/plugins/android/play-services-base-9.0.2和assets/plugins/android/play-services-basement-9.0.2两个aar文件引起的。

我取消了两者在Android上的构建,以消除与转换为dex错误相关的问题。我认为这应该没问题。

然后,我将应用程序推送到Google Play(alpha环境),并添加了一个小型控制器脚本,用于在启动时登录Google Play:

void Awake()
{
    // recommended for debugging:
    PlayGamesPlatform.DebugLogEnabled = true;
    // Activate the Google Play Games platform
    PlayGamesPlatform.Activate();
}

void Start()
{
    Login();
}

void Login()
{
    Social.localUser.Authenticate((bool success) => {
        LoggedIn = success;
    });
}

然而,Unity似乎在打开第一个场景之前就崩溃了。它在启动时立即崩溃。可以在此处查看logcat的内容: here
问题似乎出现在第842行附近:
10-07 06:03:06.282: E/AndroidRuntime(9551): FATAL EXCEPTION: main
10-07 06:03:06.298: W/ActivityManager(771):   Force finishing activity 1 com.PINGUAPPS.TEMPLATE/com.unity3d.player.UnityPlayerNativeActivity
10-07 06:03:06.339: W/ActivityManager(771):   Force finishing activity 2 com.google.android.apps.mtaas.backdrop/.BackdropActivity
10-07 06:03:06.402: D/Atlas(771): Validating map...

我不知道如何解决这个问题?

::附加信息::

因此,我已经回滚到了一个状态,在该状态下我已将unity包导入到Unity中,但我尚未配置它,也没有将我的xml包含的资源提供给它。 在此时,在编辑器中会出现nullreferenceexception:

NullReferenceException: Object reference not set to an instance of an object
GooglePlayServices.PlayServicesResolver.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) (at Assets/PlayServicesResolver/Editor/PlayServicesResolver.cs:104)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:27)
UnityEditor.AssetDatabase:Refresh()
GooglePlayGames.Editor.GPGSUpgrader:.cctor() (at Assets/GooglePlayGames/Editor/GPGSUpgrader.cs:107)
UnityEditor.EditorAssemblies:SetLoadedEditorAssemblies(Assembly[])

它所引用的行是:
if (!Resolver.ShouldAutoResolve(importedAssets, deletedAssets,
                movedAssets, movedFromAssetPaths))

然而,在这个空引用异常之后,我在日志中看到解析器已经被注册了,例如:

Registering resolver version 1.2.0
UnityEngine.Debug:Log(Object)
GooglePlayServices.ResolverVer1_2:.cctor() (at Assets/PlayServicesResolver/Editor/ResolverVer1_2.cs:34)
UnityEditor.EditorAssemblies:SetLoadedEditorAssemblies(Assembly[])

现在,我可以顺利地构建这个APK并在我的手机上运行,没有问题。(显然,谷歌游戏服务不会起作用,因为它没有配置好)。

因此,我转到“窗口”>>“谷歌游戏”>>“设置”>>“Android”,在这里,我粘贴我的资源XML。 我为资源C#文件指定了位置和名称,然后点击“设置”。

我看到以下Jar依赖冲突选项:

Remove or replace play-services-ads version 9.0.2 with version 9.6.1?
Remove or replace support-v4 version 23.1.1 with version 24.0.0?
Remove or replace play-services-gcm version 9.0.2 with version 9.6.1?
Remove or replace play-services-location version 9.0.2 with version 9.6.1?
Remove or replace play-services-base version 9.0.2 with version 9.6.1?
Remove or replace play-services-basement version 9.0.2 with version 9.6.1?
Remove or replace support-annotations version 23.1.1 with version 23.4.0?
Remove or replace play-services-iid version 9.0.2 with version 9.6.1?
Remove or replace play-services-tasks version 9.0.2 with version 9.6.1?

我尝试过按下“全部保留”和“确定”按钮,但这两个操作都会导致我的aars发生冲突。

我刚刚又尝试了一次,这次按下所有按钮的“确定”,并且在上一次成功构建后只进行了这些操作。在将jar转换为dex格式时,构建失败并出现以下错误:

CommandInvokationFailure: Unable to convert classes into dex format.
C:\Program Files (x86)\Java\jdk1.7.0_55\bin\java.exe -Xmx1024M -Dcom.android.sdkmanager.toolsdir="C:/Users/PINGU/AppData/Local/Android/sdk\tools" -Dfile.encoding=UTF8 -jar "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar" -

stderr[
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.a) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.banners.BannerSize$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.banners.b) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.banners.d) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.banners.a) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.banners.c) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.interstitials.a.b) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.interstitials.a.c) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.ofw.a) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.e) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.f) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.g) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.h) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.d) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.i) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.j) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.m) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.n) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.a.o) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.b) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.c) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.e) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.h) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.f) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.g) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.k) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.i) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.j) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.fyber.ads.videos.l) that doesn't come with<message truncated>

如前所述,我可以通过找到我的play-services-base和play-services-basement文件并取消选中它们以便为android构建来防止发生这种情况。当我这样做时,APK会构建,但是应用程序一旦打开就会崩溃。


你能列出 AAR 冲突错误吗?那将会很有帮助。 - JeanLuc
我添加了尽可能多的附加信息 - 希望这能帮到你 :) - pingu2k4
如果您使用Eclipse,只需使用logcat查看启动应用程序时的错误。 - Kenshin
3个回答

0

我之前也有同样的问题出现在我的Unity项目中。那是一个重复的support-v4类。后来发现最好是将Google Play插件导入到一个空项目中(进行测试构建)。

然后完全删除Extensions、Editor和Plugins文件夹中的Google Play插件和所有文件,并从空项目重新导入。很抱歉,我无法再进一步澄清了,因为无法访问我的项目文件。


0

去年我在我的 Android 游戏项目中遇到了同样的问题。我更新了 Android Support Repository、Android Support Library、Google Play Services、Google Repository、Google Billing Library 和 Android API 6.0,然后这个问题就解决了。我仍然不知道问题的源头在哪里,但是我在我的项目中用这种方式解决了问题。希望对你也有帮助。


0

如果您在检查器中没有添加Google Admob广告ID,大多数情况下应用程序将在开始时崩溃。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接