3

It's been a week now and we're unable to build the apk file for our andorid project. The error that we're getting is related to the proguard(see the attached errors):

Warning:there were 416 unresolved references to classes or interfaces.

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForDebug'. java.io.IOException: Please correct the above warnings first.

The project used to build before one of our recent commits. So, when we checkout to that commit it works! We've tried everything available, related to this, on the stackoverflow/internet but nothing works! and the worst part is that it builds but just on one of our computers and we're unable to figure out why it doesn't work on other computers with the same version of the Android Studio.

We even tried to suppress the warnings by using :

-dontwarn

-keep class

So, in this case the build was successful but the app crashes.

Versions of the different components used :

Android Studio - 2.1.2

Proguard - 5.2.1

buildToolsVersion 23.0.2

Proguard errors

These are the proguard rules that we're using for our project :

-dontwarn com.github.siyamed.shapeimageview.path.parser.SvgToPath
-dontwarn com.google.android.gms.internal.zzhu
-dontwarn com.squareup.okhttp.**
-keep class com.opentok.** { *; }
-keep class org.webrtc.** { *; }

-keepattributes SourceFile,LineNumberTable
-keepattributes *Annotation*
-keep class org.acra.** { *; }
-keepclassmembers class com.paytm.pgsdk.PaytmWebView$PaytmJavaScriptInterface {
    public *;
}

##MoEngage proguard rules, src : http://docs.moengage.com/docs/android-configuring-proguard
-dontwarn com.google.android.gms.location.**
-dontwarn com.google.android.gms.gcm.**
-dontwarn com.google.android.gms.iid.**
-dontwarn okio.**

-keep class com.google.android.gms.gcm.** { *; }
-keep class com.google.android.gms.iid.** { *; }
-keep class com.google.android.gms.location.** { *; }
-keep class com.facebook.drawee.**{*;}
-dontwarn com.facebook.drawee.*

-keep class com.moe.pushlibrary.activities.** { *; }
-keep class com.moe.pushlibrary.internal.MoEService
-keep class com.moe.pushlibrary.GeofenceIntentService
-keep class com.moe.pushlibrary.InstallReceiver
-keep class com.moengage.push.MoEPushWorker
-keep class com.moe.pushlibrary.PushGcmBroadcastReceiver
-keep class com.moe.pushlibrary.providers.MoEProvider
-keep class com.moengage.receiver.MoEInstanceIDListener
-keep class com.moengage.worker.MoEGCMListenerService
-keep class com.moe.pushlibrary.models.** { *;}
-keep class com.moe.pushlibrary.internal.GeoTask
-keep class com.moengage.locationlibrarynew.LocationHandlerImpl

-dontwarn com.moengage.locationlibrarynew.LocationHandlerImpl
-dontwarn com.moe.pushlibrary.internal.GeoTask
-dontwarn com.moengage.receiver.*
-dontwarn com.moengage.worker.*
-dontwarn com.moengage.*
-keep class com.delight.**  { *; }

## for rx java
-dontwarn sun.misc.**

-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
   long producerIndex;
   long consumerIndex;
}

-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode producerNode;
}

-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
Community
  • 1
  • 1
Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39

1 Answers1

0

When you add some dependencies, there is a huge change that proguard will obsfucates the dependencies code. So instead using -dontwarn (which basically not warning you about some unresolved references) you should use -keep class.

Find the dependencies package name, then keep their class from being obsfucated by proguard.

-- UPDATED --

From your log there are 2 dependencies that need to be resolved: facebook and android-shape-imageview.

For facebook try adding this to your proguard:

-keep class com.facebook.** {
   *;
}

For shape-imageview:

-dontwarn android.support.v7.**
-keep class android.support.v7.** { ; }
-keep interface android.support.v7.* { ; }
-keepattributes *Annotation,Signature
-dontwarn com.github.siyamed.**
-keep class com.github.siyamed.shapeimageview.**{ *; }

Read more at:

  1. Android ProGuard settings for Facebook
  2. Anyone able to use this with proguard on?
Community
  • 1
  • 1
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • hey @isnotmenow , thanks for the answer, we did try adding -keep class rules for the errors we're getting but then it takes a lot of time to build the project and finally it throws some error. – Ashish Ranjan Jun 27 '16 at 16:54
  • and what i don't understand is why does it build in one of the PCs? Does it have something to do with the build tools version or the gradle version? – Ashish Ranjan Jun 27 '16 at 16:55
  • @AshishRanjan: what error?... Maybe the project in thay PC not exactly same with the project on the other PCs. Try cleaning and rebuilding project first. Sometimes Android Studio use the older compiled code when we try running the app. – ישו אוהב אותך Jun 27 '16 at 17:00
  • Btw, try to commenting some rules: -dontwarn com.github.siyamed.shapeimageview.path.parser.SvgToPat and **-keep class com.facebook.drawee.**{*;} -dontwarn com.facebook.drawee.* before using the rules in my answer. – ישו אוהב אותך Jun 27 '16 at 17:04
  • project is exactly same, as we just pulled the code from git and yeah we tried cleaning and rebuilding many times without any success! – Ashish Ranjan Jun 27 '16 at 17:06
  • ok i'll try your proguard rules, btw this is the complete list of warnings : http://pastebin.com/qFFwu1kH – Ashish Ranjan Jun 27 '16 at 17:15
  • Well, the sad fact is that we only can make sure everything working after proguarding by trial and error. try keeping all your new dependencies in proguard. Just a suggestion, for a more simple handling proguard you can group rules for specific library in a file. i.e app_compat.pro. And save it on proguard folder in the same root with your project. Then add **FileCollection proGuardFileCollection = files { file('./proguard').listFiles() } proguardFiles(proGuardFileCollection)** before ProguardFiles line in your build.gradle. This should help you localize the problem. – ישו אוהב אותך Jun 27 '16 at 17:31
  • hey we got rid of the warnings by using some -dontwarn, -keep rules but we're still getting notes like these for all our activity/application classes :- **Note: the configuration refers to the unknown class 'com.mypackage.activity'** – Ashish Ranjan Jun 28 '16 at 09:07
  • and due to this the app crashes on launch with the following error : java.lang.RuntimeException: Unable to instantiate application com.mypackage.myAppClass: java.lang.ClassNotFoundException: Didn't find class "com.package.myAppClass" on path: DexPathList[[zip file "/data/app/com.mypackage-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.mypackage-1, /vendor/lib, /system/lib]]. is there anything else i need to write in the proguard file? – Ashish Ranjan Jun 28 '16 at 09:08
  • Maybe this not related with that, but you should make sure that in your manifest contain the correct path like **** – ישו אוהב אותך Jun 28 '16 at 09:13
  • yeah the package name in the manifest file is correct and again we're not getting this error in that single PC.That's strange cuz the code is same. – Ashish Ranjan Jun 28 '16 at 09:16
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115973/discussion-between-isnotmenow-and-ashish-ranjan). – ישו אוהב אותך Jun 29 '16 at 13:48