简体   繁体   English

Crashlytics Unity插件 - 导出到Android Studio

[英]Crashlytics Unity Plugin - export to Android Studio

I integrated Crashlytic plugin into my Unity project. 我将Crashlytic插件集成到我的Unity项目中。 It work fine if I build an APK file directly from Unity. 如果我直接从Unity构建一个APK文件,它工作正常。

But if I use option export to "Google Android Project" in Unity 但是如果我在Unity中使用选项导出到“Google Android Project”

-> Then open Android Studio, select "Import project (Eclipse ADT, Graddle, etc)" - >然后打开Android Studio,选择“导入项目(Eclipse ADT,Graddle等)”

-> Run - >跑

-> App crash on Launch with exception: "java.lang.ClassNotFoundException: io.fabric.unity.android.FabricApplication" - >启动时应用程序崩溃,异常:“java.lang.ClassNotFoundException:io.fabric.unity.android.FabricApplication”

Here's my build.gradle 这是我的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')
}

Anyone got this problem before? 以前有人遇到这个问题吗?

==TLDR== == == TLDR

You need to configure Unity's Android Build Settings to customize the build.gradle file and emit a proguard-user.txt file when it exports the project: 您需要配置Unity的Android Build Settings来自定义build.gradle文件,并在导出项目时发出proguard-user.txt文件:

  1. Click the File Menu -> click Build Settings menu item -> select Android in the Build Settings window 单击文件菜单 - >单击构建设置菜单项 - >在构建设置窗口中选择Android 在此输入图像描述
  2. Change Build System to Gradle and check the Export Project box Build System更改为Gradle并选中Export Project
  3. Click Player Settings button 单击播放器设置按钮
  4. Click Publish Settings in the Player Settings inspector tab 单击 播放器设置”检查器选项卡中的 发布设置 在此输入图像描述
  5. Check both Custom Gradle Template and User Proguard File boxes under the Build section 检查Build部分下的Custom Gradle TemplateUser Proguard File
  6. Select Proguard for Release under the Minify section Minify部分下选择Proguard for Release
  7. Edit the Assets/Plugins/Android/mainTemplate.gradle and Assets/Plugins/Android/proguard-user.txt files to look like the ones below. 编辑Assets/Plugins/Android/mainTemplate.gradleAssets/Plugins/Android/proguard-user.txt文件,如下所示。

mainTemplate.gradle should have this in the buildTypes release section: mainTemplate.gradle应该在buildTypes release部分中有这个:

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

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

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

==Specifics for my situation== I was having a similar problem trying to export the project using the Gradle Build System in Unity. ==我的情况的具体情况==我在使用Unity中的Gradle Build System导出项目时遇到了类似的问题。 The terminology is a bit different, but it might be because I'm on a different Unity version (2017.1.1f1). 术语有点不同,但可能是因为我使用的是另一个Unity版本(2017.1.1f1)。

Also, rather than trying to import to Android Studio I'm trying to build from the command line using Gradle. 此外,我没有尝试导入Android Studio,而是尝试使用Gradle从命令行构建。

I was getting the following error while trying to do a gradlew assembleRelease , which is similar, but different: 尝试执行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 "..."]]

I noticed the release buildType in the root build.gradle was defined as follows: 我注意到根build.gradlerelease buildType定义如下:

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

In a blog article from Kongregate on Unity , where they talk about the problems with exporting your Android project, they mention (take note of the last bolded sentence): Kongregate on Unity的一篇博客文章中,他们谈到了导出Android项目的问题,他们提到(注意最后一个粗体句子):

We specified two ProGuard configuration files – the standard one that's included with the Android SDK (proguard-android.txt) and one which is exported with the Unity Project as of Unity 5.4, (proguard-unity.txt). 我们指定了两个ProGuard配置文件 - Android SDK中包含的标准配置文件(proguard-android.txt)和Unity 5.4中使用Unity项目导出的配置文件(proguard-unity.txt)。 You almost certainly need to maintain another ProGuard configuration file with rules specifying which classes and methods need to be kept for the plugins your game uses. 您几乎肯定需要维护另一个ProGuard配置文件,其中包含规则,指定您的游戏使用的插件需要保留哪些类和方法。

Thankfully, @MikeBonnell pointed me to the Fabric Android Crashlytics integration docs which tells you how to exclude Crashlytics from minification in your ProGuard file and that you must have minifyEnabled: true in your build.gradle file if you're using Gradle. 值得庆幸的是,@ MikeBonnell向我指出了Fabric Android Crashlytics集成文档,该文档告诉您如何在ProGuard文件中将Crashlytics从缩小排除,并且如果您使用Gradle,则必须在build.gradle文件中使用minifyEnabled: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM