question

Peter avatar image
Peter asked

Proguard and obfuscated R

I got the following error due to using proguard: Can’t load an ad because resources cannot be read. Make sure the ‘R’ class has not been obfuscated. It was fixed by not renaming the R class. I find this to be very strange. Is the library using introspection or so? Other SDK's deal ok with proguard, it would be nice if I didn't need to reveal my R files. Sure there must be a nicer way to access the R file?
mobile ads
10 |5000

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 Peter, Thanks for showing interest in Mobile Ads. Unfortunately, Mobile Ads will not work if R file does not have the same name as your package or if it's obfuscated. It's explained in the end of below documentation https://developer.amazon.com/sdk/mobileads/event-tracking-and-errors.html Please configure your proguard so that R file is excluded from obfuscation target.
10 |5000

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
Hi, Yes I understand it doesn't work now. What I do not understand is, why the SDK is coded this way, since clearly this can be avoided. (Other SDK's don't need this)
10 |5000

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
Thanks for your feedback. We have forwarded this issue to the concerned team.
10 |5000

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
I am confused. Does this mean we can't use proguard or we can't obfuscate any of our code if we are using Amazon ads?
10 |5000

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, Per the included Readme file, the current version of the Amazon Mobile Ads API does not officially support any obfuscated apps. If removing the R class from the obfuscation process doesn't remove the "Can’t load an ad because resources cannot be read" message, then your only option would be to remove obfuscation completely. We will take your feedback into account for future releases. Thanks Matt
10 |5000

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
Well, I've given up. I need to use Proguard and I can't get it work with Amazon's ads, so I need to go back to AdMob, which unfortunately, has their own issues, but I've, at least, gotten AdMob to work without jumping through a million hoops. When/if Amazon decides to make their SDK work with Proguard, I'll start using them.
10 |5000

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

chesley54 avatar image
chesley54 answered
Hello Peter, The Mobile Ads API will not work if either the R class or the com.amazon.device.ads classes are obfuscated. To work around this issue you should exclude both our classes and the R class. Suggested proguard syntax: -keep class com.amazon.device.ads.** {*;} -keep class **.R$* {*;} Please let us know if this resolves the issue. Sincerely, -Chesley
10 |5000

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 Guys, Just letting you know that the currently available Amazon Mobile Ads API, version 5.0.2, now allows the R class to be obfuscated. Matt
10 |5000

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