当我关闭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");


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

提前致谢!

最佳答案

您是否尝试过在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'

关于android - Android DexGuard:将Crashlytics从混淆中排除,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32401616/

10-11 14:25