Crashlytics Unity插件 - 导出到Android Studio

Son*_* Le 2 android unity-game-engine google-fabric

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

但是如果我在Unity中使用选项导出到"Google Android Project"

- >然后打开Android Studio,选择"导入项目(Eclipse ADT,Graddle等)"

- >跑

- >启动时应用程序崩溃,异常:"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')
}
Run Code Online (Sandbox Code Playgroud)

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

pla*_*mbo 7

== == TLDR

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

  1. 单击文件菜单 - >单击构建设置菜单项 - > 在构建设置窗口中 选择Android在此输入图像描述
  2. Build System更改为Gradle并选中Export Project
  3. 单击播放器设置按钮
  4. 单击" 播放器设置"检查器选项卡 中的" 发布设置"在此输入图像描述
  5. 检查Build部分下的Custom Gradle TemplateUser Proguard File
  6. Minify部分下选择Proguard for Release
  7. 编辑Assets/Plugins/Android/mainTemplate.gradleAssets/Plugins/Android/proguard-user.txt文件看起来像下面的那些.

mainTemplate.gradle应该在以下buildTypes release部分中包含:

release {
  minifyEnabled true
  useProguard true
  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt', 'proguard-user.txt'
}
Run Code Online (Sandbox Code Playgroud)

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

-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
Run Code Online (Sandbox Code Playgroud)

==我的情况的具体情况== 我在使用Unity中的Gradle Build System导出项目时遇到了类似的问题.术语有点不同,但可能是因为我使用的是另一个Unity版本(2017.1.1f1).

此外,我没有尝试导入Android Studio,而是尝试使用Gradle从命令行构建.

我在尝试做一个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 "..."]]
Run Code Online (Sandbox Code Playgroud)

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

    release {
      minifyEnabled true
      useProguard true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
    }
Run Code Online (Sandbox Code Playgroud)

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

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

值得庆幸的是,@ MikeBonnell向我指出了Fabric Android Crashlytics集成文档,该文档告诉您如何在ProGuard文件中将Crashlytics从缩小排除,并且如果您正在使用Gradle,则必须minifyEnabled: true在build.gradle文件中.