question

Kris B avatar image
Kris B asked

Can we use Proguard

I posted this question in this thread here: https://forums.developer.amazon.com/forums/thread.jspa?messageID=3228&tstart=0 but can we not obfuscate our code using Proguard if we are using Amazon's ads? I ask because on this page: https://developer.amazon.com/sdk/mobileads/event-tracking-and-errors.html It says: "Your ‘R’ class could not be read because it does not have the same name as your package. If your app is obfuscated, please remove obfuscation or ensure that the resource class is not renamed."
mobile ads
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Matt15@Amazon avatar image
Matt15@Amazon answered
Hey Kris, The current version of the Amazon Mobile Ads API does not officially support ProGuard obfuscation, but it may still work as long as you ensure the R class retains its name during the obfuscation process. If this doesn't work then the only option is to remove obfuscation. Does this answer your question? Matt
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kris B avatar image
Kris B answered
Sort of. I just have to figure out how to retain the R classes. Not sure how to do that.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kris B avatar image
Kris B answered
If anyone has figured out how to retain the resources files while using Proguard, please let me know. This is what I've tried so far: -keeppackagenames com.app.*.R; -keepclassmembers com.app.*.R; -keep class com.app.*.R; -keepclassmembers class **.R$* { public static ; }
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered

Hi Kris,

Thank you for the post. Can you try following proguard options?

-keep public final class **.R$*
-keepclassmembers class **.R$* {
    public static ;
}
-keepclassmembers class **.R {
    public static final class *;
}

javac generates separate .class files for inner classes that exist in main class (R in this case). So you need to apply the skip obfuscation rule for proguard for all the classes generated after compilation. Let us know if this resolves your issue.

10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Peter avatar image
Peter answered
I use the following and it works ok for me: -keep class com.amazon.device.ads.** { *; } -keep class **.R { } -keep class **.R$* { } -keepattributes *Annotation*
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hello Peter, Thank you for sharing the proguard rule with us. The currently available Amazon Mobile Ads API, version 5.0.2, now allows the R class to be obfuscated. So developers are not supposed to write any proguard rule to keep the R file intact.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

monocube avatar image
monocube answered
Hello, just tried to use Proguard using the latest Android Tools and Amazon Mobile Ads SDK (amazon-ads-5.1.14). I get this: [b]Warning: com.amazon.device.ads.MraidAssets: can't find referenced class org.apache.commons.codec.binary.Base64[/b] Also, if you target Android SDK 18, you also get this: [b]Warning: com.amazon.device.ads.HtmlRenderer: can't find referenced method 'void setPluginsEnabled(boolean)' in class android.webkit.WebSettings Warning: com.amazon.device.ads.MraidView: can't find referenced method 'void setPluginsEnabled(boolean)' in class android.webkit.WebSettings[/b] Can you please help? Message was edited by: monocube
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Monocube, Are all these causing failure of Ad loading? Are you getting any error code or reason in logcat?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

monocube avatar image
monocube answered
No, these are caused when exporting the APK from Eclipse - they are logs from Proguard output. Your library seems to be missing some dependency and it's not fully compatible with Android 4.3 (SDK 18). Basically, we can't export and obfuscate the app because of this. Message was edited by: monocube
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Monocube, Thanks for bringing the issue into our notice. I have forwarded your issue to the concerned team. Please wait till my next post.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.