Ercument Kisa
Ercument Kisa

Reputation: 168

Android DexGuard: Exclude Crashlytics from Obfuscation

My application can run perfectly with Crashlytics when I turn DexGuard off. However, when I add the following configurations to obfuscate my code the application stucks at launch with a black screen.

Here is the related part of the 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'
       }
   }
}

Base build.gradle file:

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.+'
   }
}

Related part of dexguard-project.txt file:

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

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

Logcat Console output:

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

What i am actually doing with Crashlytics.getInstance :

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

I see no warnings or errors in the build log. Anyone have an idea what causes the problem?

Thanks in advance!

Upvotes: 1

Views: 1603

Answers (1)

scottyab
scottyab

Reputation: 24039

Have you tried applying the io.fabric after dexguard?

I have an app working with dexguard and crashlytics and Crashlytics.getInstance().core.setString("ENVIRONMENT", BuildConfig.BUILD_TYPE); doesn't cause an error. I'm using the same -keep and -dontwarn config as you.

From my build.gradle file

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

Upvotes: 1

Related Questions