2

We have a project with some library (and native) dependencies, like this:

Native SDK ← Library (Wrapper) ← Main Project

To start with, this structure cannot be changed, as we are reusing the parts. The problem I am facing is passing the 65k reference limit. This, of course, has a workaround - enable ProGuard. With it enabled, the project compiles.

Since we are transitioning to the Android's default testing framework, we need to add some more dependencies to the testing config, so in dependencies we now have:

compile 'com.google.android.gms:play-services-base:7.5.0'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-safetynet:7.5.0'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.1'

compile files('libs/small-library1.jar')
compile files('libs/small-library2.jar')
compile files('libs/small-library3.jar')
compile files('libs/medium-library1.jar')
compile files('libs/medium-library2.jar')
compile files('libs/medium-library3.jar')
compile files('libs/huge-library1.jar')
compile files('libs/huge-library2.jar')

androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'

We are using SDK (API) 22, so everything is pretty much at the latest version. The problem is, our native SDK has a bunch of code in the protobuf layer, and the library wrapper is big. With all other JARs, we are too high over the 65k limit (but as I said, ProGuard fixes this barely). Multi-dex is out of the question as it works well only on Android 5.0+.

We're trying to reduce the codebase, but even then, Android Tests are failing with method reference overflow issues (i.e. not compiling).

Is there any way to enable ProGuard for tests as well?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
milosmns
  • 3,595
  • 4
  • 36
  • 48

1 Answers1

2

One option is to change your test build using testBuildType to the release build or another build variant that has ProGuard enabled. See Gradle User Guide. You can also try the solution here, but I have not tried that myself.

Community
  • 1
  • 1
Chris Feist
  • 1,678
  • 15
  • 17
  • I've tested the solution from http://stackoverflow.com/questions/21463089/proguard-gradle-debug-build-but-not-the-tests/23405948#23405948 already, but no luck. I'll check the other one now. – milosmns Jul 29 '15 at 16:49
  • So the first one fails too. I've added `testBuildType = "release"` to the `android` tag, but still proguard doesn't run.. – milosmns Jul 31 '15 at 17:08
  • 1
    I've tried the `staging` variant, getting the dex overflow error again (which means the project is too big). I'll accept this answer since it did solve the problem of proguard not running on test builds. – milosmns Aug 03 '15 at 09:27