sephiroth74/HorizontalVariableListView

ClassCastException occurs when App Package is different than the R.java package

Closed this issue · 5 comments

The Android Gradle Plugin allows you to rename the App package, which is convenient for installing your debug and release apps on the same device.

I've traced it down to this line: https://github.com/sephiroth74/HorizontalVariableListView/blob/master/library/src/it/sephiroth/android/library/widget/AbsHListView.java#L5794

See https://groups.google.com/forum/?fromgroups=#!topic/adt-dev/cqdjG2TuM-I

from Xavier Ducrohet:

They make the assumption that the package name of the app is the same as the R class. This really is not correct. While the previous build system somewhat implied this, aapt always had the feature to generate the R class in a different package.

Thinking about it there really is no current way to query the app for the package of the R class. It'd have to be provided to the library.

and what's the solution you suggest in order to make it work with both ant and gradle?

Why is the reflection needed? Why can't the styles be obtained through obtainStyledAttributes?

It was needed when compiling with ant and the android jar libraries could not contain external resources

so are you implying that it's no longer needed?

not really. I have some projects where this library must be included as a single "jar" instead of android library so it's still required, but I guess it's better to create a different branch for that. I'll fix in the next release.