Android youtube/gdata api not working after running proguard - android

Did anyone have trouble with youtube api especially after running proguard?
My code to fetch videos from youtube worked just fine before running proguard, after running proguard i am getting strange exception
ERROR/AndroidRuntime(10197): Caused by: java.lang.IllegalArgumentException:
No parser defined for Content-Type: application/atom+xml; charset=UTF-8; type=feed
I'm not setting content type anywhere and i'm using the default proguard.cfg file that's generated while creating a new project.
Did anyone face similar issues after running proguard?
Tried proguard without obfuscating, without optimization but it gives the same result.

Not sure if google-api-client is exactly the same as the gdata you mention, but it must be very similar. Since Proguard will often break your code, you have to tell it what it can and cannot do. It's not by any means a miracle tool that understands reflection.
I had to add this among others:
-keepattributes *Annotation* # Needed by google-api-client
-keepattributes Signature # Needed by google-api-client
# Needed by google-api-client to keep generic types and #Key annotations accessed via reflection
-keepclassmembers class * {
#com.google.api.client.util.Key <fields>;
}
# Needed by Guava (google-api-client)
-dontwarn sun.misc.Unsafe

Related

Why default proguard configurations in android sdk use keep *Annotation*

There is one line in the default proguard configuration of android sdk:
-keepattributes *Annotation*
According to Proguard Manual, this line equals to:
-keepattributes RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,RuntimeVisibleParameterAnnotations,RuntimeInvisibleParameterAnnotations,RuntimeVisibleTypeAnnotations,RuntimeInvisibleTypeAnnotations,AnnotationDefault
In my opinion, maybe the configuration below is enough:
-keepattributes RuntimeVisibleAnnotations,RuntimeVisibleParameterAnnotations,RuntimeVisibleTypeAnnotations,AnnotationDefault
Have I missing something? Why the recommend configuration keep all this things?
No, your observation is correct, the following configuration would be more correct imho:
-keepattributes RuntimeVisible*Annotation*,AnnotationDefault
Most people probably don't care about the subtle difference between runtime visible and invisible annotations, but there is no specific reason to keep runtime invisible annotations.
Edit: the above applies for Android applications only. If you are building an Android library, you should stick to -keepattributes *Annotation*.
btw. DexGuard (commercial variant of ProGuard) uses the updated configuration that I suggested above.

Note: android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU

I started getting the message with the latest Android Build Tools (ABT) v19.0.3 today. At first glance, I thought this might be an issue with ABT. However, a closer investigation reveals that this message:
android.support.v4.text.ICUCompatIcs: can't find dynamically referenced class libcore.icu.ICU
is only shown when Proguard is used. Answers on the net has yeilded no solution for me. Perhaps, this is only an issue with Proguard (the version I'm using is bundled with Android SDK v22.3).
I have added the following directives to proguard-project.txt file, but it makes no difference:
-keep interface android.support.v4.** { *; }
-keep class android.support.v4.** { *; }
Does anyone else come across this message and has a possible solution? Maybe Eric from Proguard might be able to shed some light into this issue. Maybe a code cleanup is required with Proguard? I'm interested to know the solution.
The note says that a support class is using reflection to access a runtime class that isn't present in the target runtime. In general, it could be a sign of compatibility problems. In this case, it's harmless; the developers of the support library are precisely using reflection to avoid any linking problems with different runtime environments. You can suppress the note with:
-dontnote android.support.**

Including external libraries in Android Proguard

My app is able to run without any issues during testing etc. But when I export out apk compiled with ProGuard, there are issues like random crashing and some features not working as expected.
I not sure is it due to the external jar libraries I have included in the project which is not properly configured in Proguard.
I have included the following in the proguard-android.txt file. I have two libraries so I added these:
-keep class org.apache.commons.net.** { *; }
-keep class org.jsoup.** { *; }
Is it the correct way? Is there any other way?
To add libraries just add -libraryjars ../libs/<libname>
After that you may need to keep classes and interfaces based on the errors you receive

Unknown classes ILicensingService notes when obfuscating Android project

I'm trying to build an Android release with Ant and ProGuard. I uncommented the following line in project.properties, despite the comment in said file noting that you shouldn't modify it ;):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
When obfuscating, I get the following notes:
[proguard] Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
[proguard] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
I do understand why this is happening. These lines can be found in the default ProGuard config file (${sdk.dir}/tools/proguard/proguard-android.txt):
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
I'm not using the Google Licensing Service, so the classes are indeed unknown. I found a solution to get rid of these notes by updating the proguard-project.txt:
-dontnote **ILicensingService
My question: Is this the correct way of handling this? It seems to me that these classes shouldn't be kept by default anyway, since that lib isn't mandatory for an android project. The only way I can think of to achieve this is by copying the default config file to my project, removing the -keep lines and ignoring the default config file in the SDK completely. Which doesn't seem as the proper way to go either. Or am I missing something?
The setting "-dontnote com.google.vending.licensing.ILicensingService" is fine. In fact, it could have been part of the default configuration file.
The -keep option may be necessary for projects that use the library.
The -dontnote option may be nice to suppress the note about the -keep option, for projects that don't use the library. The note is just a gentle reminder that the configuration file could contain a typo, because the specified class doesn't seem to exist. It doesn't affect the processing.

"Unknown Source" in release apk

Everything in my debug APK works just fine. However, when I export my APK and install it, everything works fine until I make a call to a referenced library.
E/AndroidRuntime(32571): at com.znood.znoodapp.ShowResultsActivity.a (Unknown Source)
I am using ProGuard.
My libraries are in the libs directory and are added to build path.
Any pointers are highly appreciated =)
The problem was with the Google Gson library. Proguard converts class names into obfuscated ones rendering json conversion buggy.
In order to solve this problem, make sure to have the following in your proguard-project.txt
# the classes that you use for Gson conversion
-keep class com.yourapp.objects.** { *; }
# without this line, I was having ClassCastException
-keepattributes Signature, *Annotation*
I hope this helps someone =)
If you haven't defined your libraries in proguard-project.txt then you can add like this
-libraryjars /libs/smack.jar
-libraryjars /libs/libphonenumber-5.0v1.5.jar
Android obfuscate app using proguard keeps obfuscating library jars - or is it?

Categories

Resources