Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Cling/Upnp proguard

I have created app using Cling and is working fine but when I create release build I get following message and nothing plays on renderer:

   11-22 16:24:53.341  20172-20172/? I/RendererCommand﹕ TrackMetadata : TrackMetadata [id=1, title=IMG-20151120-WA0007, artist=, genre=, artURI=res=http://192.168.1.4:8089/1.jpg, itemClass=object.item.imageItem]
11-22 16:24:53.345  20172-20172/? V/RendererCommand﹕ Resume
11-22 16:24:53.351  20172-20301/? W/RendererCommand﹕ Fail to stop ! Error: Current state of service prevents invoking that action. Error writing request message. Can't transform message payload: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType. (HTTP response was: 500 Internal Server Error)
11-22 16:24:53.351  20172-20301/? I/RendererCommand﹕ Set uri to http://192.168.1.4:8089/1.jpg
11-22 16:24:53.353  20172-20386/? D/RendererCommand﹕ Update state !
11-22 16:24:53.354  20172-20264/? W/RendererCommand﹕ Fail to set URI ! Error: Current state of service prevents invoking that action. Error writing request message. Can't transform message payload: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType. (HTTP response was: 500 Internal Server Error)
11-22 16:24:53.354  20172-20262/? W/RendererCommand﹕ Fail to get position info ! Error: Current state of service prevents invoking that action. Error writing request message. Can't transform message payload: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType. (HTTP response was: 500 Internal Server Error)
11-22 16:24:54.354  20172-20386/? D/RendererCommand﹕ Update state !

Below is my proguard enteries:

-dontoptimize
-dontshrink
-dontskipnonpubliclibraryclasses
-dontpreverify
-allowaccessmodification
-verbose

-dontwarn org.fourthline.cling.**
-dontwarn org.seamless.**
-dontwarn org.eclipse.jetty.**
-dontwarn android.support.v4.app.**
-dontwarn android.support.design.widget.**

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep class javax.** { *; }
-keep class org.** { *; }
-keep class org.fourthline.cling.** { *;}
-keep class org.seamless.** { *;}
-keep class org.eclipse.jetty.** { *;}
-keep class org.slf4j.** { *;}
-keep class javax.servlet.** { *;}

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}


-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }

-keepattributes *Annotation*
like image 942
ingsaurabh Avatar asked Nov 22 '15 11:11

ingsaurabh


2 Answers

Ok after having reading proguard manual, and having numerous hit and trials I finally did it by modifying last line of above prguard file to

-keepattributes Annotation, InnerClasses, Signature

and every thing works fine

from proguard

Specifies the generic signature of the class, field, or method. Compilers may need this information to properly compile classes that use generic types from compiled libraries. Code may access this signature by reflection.

and issue is of reflection

like image 126
ingsaurabh Avatar answered Sep 17 '22 13:09

ingsaurabh


proguard is corrupting ie touching classes/interfaces in the Cling lib and you need to prevent that...

you could start here assuming you have a problem with Proguard touching some networking related in the Jetty/Http stack i guess from the content of your error. Wild guess is that its as if the http entity or body cant be handled as implementing the proper interfaces... You want to config proguard to avoid all interfaces in that library and you dont have any "keep interface" directives in your proguard...

For example, are you telling proguard not to touch any of the interfaces in 'org.eclipse.jetty' . You are not doing that and you might want to .

see here

scan proguard manuals for -keepinterface to use with jetty packages implementing the server/http connections in your lib.

  1. know more about the 'cling' packages/interfaces around the internal Client-server and internal networking stack implementations in your library ( looks like it implements jetty for C-S connections on some protocol like http )

  2. build a packages list on the lib's jar/archive to compare to your proguard config. pay special attention to interfaces being used by jetty's server implementation "jar -tf my.jar | sort | uniq" or some such

  3. look at whats been obfuscated by proguard in 'mapping.txt' and in 'seeds.txt' explain here. intersect those packages names from those respective lists with packages & lists assembled above that you did NOT want proguard to mess with. 'seeds' should contain your jetty classes/interfaces. 'mapping' should NOT!

like image 45
Robert Rowntree Avatar answered Sep 19 '22 13:09

Robert Rowntree