本文介绍了Crashlytics Unity插件-导出到Android Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Crashlytic插件集成到了我的Unity项目中.如果我直接从Unity生成APK文件,效果会很好.

I integrated Crashlytic plugin into my Unity project. It work fine if I build an APK file directly from Unity.

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

But if I use option export to "Google Android Project" in Unity

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

-> Then open Android Studio, select "Import project (Eclipse ADT, Graddle, etc)"

->运行

->应用程序启动时崩溃,但出现以下异常:"java.lang.ClassNotFoundException:io.fabric.unity.android.FabricApplication"

-> App crash on Launch with exception: "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')
}

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

Anyone got this problem before?

推荐答案

== TLDR ==

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

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:

  1. 单击文件菜单->单击构建设置菜单项->在构建设置中选择 Android 窗户
  2. Build System 更改为 Gradle 并选中 Export Project
  3. 点击玩家设置按钮
  4. 播放器设置检查器选项卡中单击发布设置
  5. 选中 Build 部分
  6. 下的 Custom Gradle Template User Proguard File 框.
  7. 缩小部分下的发布中选择 Proguard
  8. 编辑Assets/Plugins/Android/mainTemplate.gradleAssets/Plugins/Android/proguard-user.txt文件,使其看起来像下面的文件.
  1. Click the File Menu -> click Build Settings menu item -> select Android in the Build Settings window
  2. Change Build System to Gradle and check the Export Project box
  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
  6. Select Proguard for Release under the Minify section
  7. Edit the Assets/Plugins/Android/mainTemplate.gradle and Assets/Plugins/Android/proguard-user.txt files to look like the ones below.

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

mainTemplate.gradle should have this in the buildTypes release section:

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 Build System导出项目时遇到类似的问题.术语有些不同,但这可能是因为我使用的是其他Unity版本(2017.1.1f1).

==Specifics for my situation==I was having a similar problem trying to export the project using the Gradle Build System in Unity. The terminology is a bit different, but it might be because I'm on a different Unity version (2017.1.1f1).

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

Also, rather than trying to import to Android Studio I'm trying to build from the command line using Gradle.

我尝试执行gradlew assembleRelease时遇到以下错误,该错误类似但不同:

I was getting the following error while trying to do a gradlew assembleRelease, which is similar, but different:

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定义如下:

I noticed the release buildType in the root build.gradle was defined as follows:

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

他们提到了Unity上的Kongregate ,他们在其中讨论了导出Android项目的问题(请注意最后一个粗体的句子):

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):

非常感谢@MikeBonnell向我介绍了Fabric Android Crashlytics集成文档,该文档告诉您如何在ProGuard文件中将Crashlytics从缩小中排除,以及如果您使用的是Gradle,则必须在build.gradle文件中包含minifyEnabled: true .

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.

这篇关于Crashlytics Unity插件-导出到Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:27