Android DexGuard:从混淆中排除Crashlytics

时间:2015-09-04 15:26:54

标签: android obfuscation crashlytics dexguard

当我关闭DexGuard时,我的应用程序可以与Crashlytics完美搭配。但是,当我添加以下配置来混淆我的代码时,应用程序在启动时会卡住黑屏。

以下是 build.gradle

的相关部分
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'dexguard'

repositories {
  maven { url 'https://maven.fabric.io/public' }
}

dependencies {
   compile fileTree(dir: 'libs', include: '*.jar')
   compile project(':MyProject')
   compile('commons-validator:commons-validator:1.4.0') {
      exclude group: 'commons-logging', module: 'commons-logging'
   }

   compile project(':android-maps-extensions')
   compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
      transitive = true;
   }
}

android {
   publishNonDefault true
   compileSdkVersion 23
   buildToolsVersion "23"
   compileOptions {
      encoding "windows-1254"
   }

   defaultConfig {
    applicationId "com.x.y"
    minSdkVersion 16
    targetSdkVersion 22
    multiDexEnabled true
   }
   lintOptions {
      abortOnError false
      checkReleaseBuilds false
   }

   dexOptions{
      incremental true
      javaMaxHeapSize "4g"
      jumboMode  true
   }

   android.enforceUniquePackageName = false

   buildTypes {
      debug {
         minifyEnabled false
       }
       release {
          minifyEnabled true
          proguardFiles getDefaultDexGuardFile('dexguard-release.pro'),'dexguard-project.txt'
       }
   }
}

基础 build.gradle 文件:

buildscript {
   repositories {
      flatDir dirs: System.getenv('DEXGUARD_LIB')
      jcenter()
      maven { url 'https://maven.fabric.io/public' }
   }

   dependencies {
      classpath ':dexguard'
      classpath 'com.android.tools.build:gradle:1.2.3'
      classpath 'io.fabric.tools:gradle:1.+'
   }
}

dexguard-project.txt 文件的相关部分:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-multidex

-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

Logcat控制台输出:

Could not find method com.crashlytics.android.Crashlytics.getInstance, referenced from method com.x.y.application.MyApplication.ʻ
Could not find method com.crashlytics.android.Crashlytics.getInstance, referenced from method com.x.y.application.MyApplication.ˏ
Could not find method com.crashlytics.android.Crashlytics.getInstance, referenced from method com.x.y.application.MyApplication.ᐝ

Starting window AppWindowToken{4518e2c0 token=Token{43255cd8 ActivityRecord{42d2a290 u0 com.x.y.tst/com.x.y.activity.start.FirstActivity t369}}} timed out

我实际上在使用Crashlytics.getInstance:

Crashlytics.getInstance().core.setString("ENVIRONMENT", "TEST");

我在构建日志中看不到任何警告或错误。 任何人都知道导致问题的原因是什么?

提前致谢!

1 个答案:

答案 0 :(得分:1)

您是否尝试在io.fabric之后应用dexguard

我有一个使用dexguard和crashlytics的应用,Crashlytics.getInstance().core.setString("ENVIRONMENT", BuildConfig.BUILD_TYPE);不会导致错误。我正在使用与您相同的-keep-dontwarn配置。

来自我的build.gradle文件

apply plugin: 'com.android.application' apply plugin: 'dexguard' apply plugin: 'io.fabric'