【问题标题】:Crashlytics Unity Plugin - export to Android StudioCrashlytics Unity 插件 - 导出到 Android Studio
【发布时间】:2017-10-02 02:42:04
【问题描述】:

我将 Crashlytic 插件集成到我的 Unity 项目中。如果我直接从 Unity 构建 APK 文件,它工作正常。

但如果我在 Unity 中使用选项导出到“Google Android 项目”

->然后打开Android Studio,选择“Import project (Eclipse ADT, Graddle, etc)”

-> 运行

-> 应用程序在启动时崩溃,异常:“java.lang.ClassNotFoundException: io.fabric.unity.android.FabricApplication”

这是我的 build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "25.0.2"

defaultConfig {
    applicationId "com.xct.poke.khongchien"
    minSdkVersion 15
    targetSdkVersion 25
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
}

dependencies {
compile project(':answers')
compile project(':an_social')
compile project(':beta')
compile project(':common')
compile project(':crashlytics')
compile project(':crashlyticswrapper')
compile project(':fabric')
compile project(':fabricinit')
compile project(':facebookandroidsdk470')
compile project(':facebookandroidwrapperrelease')
compile project(':googleAIDL')
compile project(':googlePlay')
compile project(':unityadsrelease')
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services-analytics:9.0.0'
compile 'com.google.android.gms:play-services-auth:9.0.0'
compile files('libs/bolts-android-1.2.0.jar')
compile files('libs/EtceteraPlugin.jar')
compile files('libs/mobilenativepopups.jar')
compile files('libs/Prime31UnityActivity.jar')
compile files('libs/unity-classes.jar')
compile files('libs/WebViewPlugin.jar')
}

以前有人遇到过这个问题吗?

【问题讨论】:

  • 来自 Fabric 的 Mike。是你应用的 build.gradle 还是项目的 build.gradle?
  • 嗨 Mike,这是我应用的 build.gradle,io.fabric.unity.android.FabricApplication 类应该在项目“fabricinit”中。
  • @MikeBonnell 你有这方面的任何信息吗?
  • @plainjimbo 不幸的是,我无法重现这一点。您能否分享更多关于您的实例的详细信息?

标签: android unity3d google-fabric


【解决方案1】:

==TLDR==

您需要配置 Unity 的 Android Build Settings 以自定义 build.gradle 文件并在导出项目时发出 proguard-user.txt 文件:

  1. 点击File菜单->点击Build Settings菜单项->在Build Settings中选择Android窗户
  2. 将 Build System 更改为 Gradle 并选中 Export Project 框
  3. 点击播放器设置按钮
  4. 在播放器设置检查器选项卡中单击发布设置
  5. 选中 Build 部分下的 Custom Gradle Template 和 User Proguard File 框
  6. 在 Minify 部分下为 Release 选择 Proguard
  7. 编辑Assets/Plugins/Android/mainTemplate.gradle 和Assets/Plugins/Android/proguard-user.txt 文件,使其如下所示。

ma​​inTemplate.gradle 应该在 buildTypes release 部分有这个:

release {
  minifyEnabled true
  useProguard true
  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt', 'proguard-user.txt'
}

proguard-user.txt 看起来像这样:

-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

==我的具体情况== 我在尝试使用 Unity 中的 Gradle 构建系统导出项目时遇到了类似的问题。术语有点不同,但可能是因为我使用的是不同的 Unity 版本(2017.1.1f1)。

另外,我尝试使用 Gradle 从命令行构建,而不是尝试导入 Android Studio。

我在尝试执行 gradlew assembleRelease 时遇到了以下错误,这是相似但不同的:

java.lang.RuntimeException: Unable to create application io.fabric.unity.android.FabricApplication: io.fabric.unity.android.b: Could not instantiate kits
....
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.crashlytics.android.Crashlytics" on path: DexPathList[[zip file "..."]]

我注意到根build.gradle 中的release buildType 定义如下:

    release {
      minifyEnabled true
      useProguard true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
    }

在Kongregate on Unity 的一篇博客文章中,他们谈到了导出您的 Android 项目时遇到的问题,他们提到(注意最后一个粗体字):

我们指定了两个 ProGuard 配置文件——一个包含在 Android SDK (proguard-android.txt) 中的标准配置文件和一个从 Unity 5.4 开始随 Unity 项目导出的一个 (proguard-unity.txt)。 您几乎肯定需要维护另一个 ProGuard 配置文件,其中包含指定需要为您的游戏使用的插件保留哪些类和方法的规则。

谢天谢地,@MikeBonnell 向我指出了 Fabric Android Crashlytics 集成文档,如果您使用的是 Gradle,该文档会告诉您 ProGuard 文件中的 how to exclude Crashlytics from minification 和 build.gradle 文件中的 you must have minifyEnabled: true。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 2017-04-02
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 2019-03-25
    相关资源
    最近更新 更多