{"action":"created","issue":{"url":"https://api.github.com/repos/gotev/android-upload-service/issues/228","repository_url":"https://api.github.com/repos/gotev/android-upload-service","labels_url":"https://api.github.com/repos/gotev/android-upload-service/issues/228/labels{/name}","comments_url":"https://api.github.com/repos/gotev/android-upload-service/issues/228/comments","events_url":"https://api.github.com/repos/gotev/android-upload-service/issues/228/events","html_url":"https://github.com/gotev/android-upload-service/issues/228","id":202192430,"number":228,"title":"Explicitly create instances of FileSchemeHandler and ContentSchemeHandler","user":{"login":"ianschmitz","id":6355370,"avatar_url":"https://avatars.githubusercontent.com/u/6355370?v=3","gravatar_id":"","url":"https://api.github.com/users/ianschmitz","html_url":"https://github.com/ianschmitz","followers_url":"https://api.github.com/users/ianschmitz/followers","following_url":"https://api.github.com/users/ianschmitz/following{/other_user}","gists_url":"https://api.github.com/users/ianschmitz/gists{/gist_id}","starred_url":"https://api.github.com/users/ianschmitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ianschmitz/subscriptions","organizations_url":"https://api.github.com/users/ianschmitz/orgs","repos_url":"https://api.github.com/users/ianschmitz/repos","events_url":"https://api.github.com/users/ianschmitz/events{/privacy}","received_events_url":"https://api.github.com/users/ianschmitz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-01-20T17:05:49Z","updated_at":"2017-01-20T19:15:00Z","closed_at":null,"body":"Currently the `SchemeHandlerFactory.get()` method returns an instance of either `FileSchemeHandler` or `ContentSchemeHandler` depending on the value of the `path` param. However the instance returned is created using `getDeclaredInstructor` which isn't an explicit reference to the constructor method.\r\n\r\nThe lack of an explicit reference causes the constructors to be stripped from both `FileSchemeHandler` and `ContentSchemeHandler` during release builds of a Xamarin Android project when using this library from a Xamarin Android Binding library. Presumably, the Xamarin Android project appears to strip the constructors out since during some form of static analysis it deems it not to be used.\r\n\r\nI confirmed the issue to be resolved when referencing the constructors directly. I changed the source for `ContentSchemeHandler.get()` to the following, which solved the issue:\r\n\r\n```java\r\n    public SchemeHandler get(String path) throws FileNotFoundException {\r\n        if (path.startsWith(\"/\")) {\r\n            return new FileSchemeHandler(path);\r\n        }\r\n\r\n        if (path.startsWith(\"content://\")) {\r\n            return new ContentSchemeHandler(path);\r\n        }\r\n\r\n        throw new UnsupportedOperationException(\"No handlers for \" + path);\r\n    }\r\n```"},"comment":{"url":"https://api.github.com/repos/gotev/android-upload-service/issues/comments/274155105","html_url":"https://github.com/gotev/android-upload-service/issues/228#issuecomment-274155105","issue_url":"https://api.github.com/repos/gotev/android-upload-service/issues/228","id":274155105,"user":{"login":"gotev","id":16792495,"avatar_url":"https://avatars.githubusercontent.com/u/16792495?v=3","gravatar_id":"","url":"https://api.github.com/users/gotev","html_url":"https://github.com/gotev","followers_url":"https://api.github.com/users/gotev/followers","following_url":"https://api.github.com/users/gotev/following{/other_user}","gists_url":"https://api.github.com/users/gotev/gists{/gist_id}","starred_url":"https://api.github.com/users/gotev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gotev/subscriptions","organizations_url":"https://api.github.com/users/gotev/orgs","repos_url":"https://api.github.com/users/gotev/repos","events_url":"https://api.github.com/users/gotev/events{/privacy}","received_events_url":"https://api.github.com/users/gotev/received_events","type":"User","site_admin":false},"created_at":"2017-01-20T19:15:00Z","updated_at":"2017-01-20T19:15:00Z","body":"> The lack of an explicit reference causes the constructors to be stripped from both FileSchemeHandler and ContentSchemeHandler during release builds of a Xamarin Android project when using this library from a Xamarin Android Binding library.\r\n\r\nI don't know Xamarin.Android but maybe it uses ProGuard or something similar. At that point in the code, Java Reflection is used. Since the constructors are not public, they are stripped down and you get the exception. Is there a way in Xamarin to add exceptions or `keepClass` attributes like in ProGuard on Android? I think it's the better option, because I would keep the implementation as it is now by using reflection, which makes extensions easier and reduces boilerplate code."}}
{"actor":{"display_login":"gotev"}}