Android Cling/Upnp proguard
Asked Answered
H

3

12

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*
Hephzipa answered 22/11, 2015 at 11:17 Comment(5)
you have a "HTTP response was: 500 Internal Server Error" do you check error on your server ?Allenaallenby
Yes its pretty strange that same server works fine with chromecast but not with Upnp after running proguard Iam just stuckHephzipa
OK but what's the error on server ? I'm sure error 500 is logged on server. Please check this on serverAllenaallenby
If you read the log it clearly states that problem is due to service and therefore appropriate payload cant be class cast which at the end return in server as server doesn't have correct payloadHephzipa
#4447645 try that if its a reflection / proguard issueGameness
H
8

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

Hephzipa answered 4/12, 2015 at 6:1 Comment(0)
G
2

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!

Gameness answered 3/12, 2015 at 8:14 Comment(1)
Tried every possible combination but still same error message, thinking on moving off from clingHephzipa
A
0

Maybe you could try to add -keepclassmembers in addition to -keep class for package org.fourthline.cling as this:

-keep class org.fourthline.cling.** { *;}
-keepclassmembers class org.fourthline.cling.** { *;}
Allenaallenby answered 3/12, 2015 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.