Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resolveAndroidApiVersion when running under Robolectric #4912

Merged
merged 1 commit into from
Dec 9, 2016

Conversation

cesar1000
Copy link

This is addressing issue #4697.

PlatformDependent.resolveAndroidApiVersion() tries to determine the Android SDK version by reading the android.os.Build$VERSION#SDK_INT field. When running under Robolectric, the class will be found (since Robolectric bundles an original android.jar). However, the method is using the system class loader for loading it (instead of the Robolectric instrumenting class loader), which will not instrument the class to run in the JVM. As a result, static initialization of the class fails with
an UnsatisfiedLinkError when calling SystemProperties.get(), which calls native method native_get.

I fixed by using the default class loader instead. This would only make a difference in the extremely rare case that the Android application installs a class loader that's not capable of finding Android classes. I tested that this behaves as expected on a device, fixes the issue with Robolectric, and detects it's not Android otherwise (as proven by the unit test).

PlatformDependent.resolveAndroidApiVersion() tries to determine the
Android SDK version by reading the android.os.Build$VERSION#SDK_INT
field. When running under Robolectric, the class will be found (since
Robolectric bundles an original android.jar). However, the method is
using the system class loader for loading it (instead of the Robolectric
instrumenting class loader), which will not instrument the class to run
in the JVM. As a result, static initialization of the class fails with
an UnsatisfiedLinkError when calling SystemProperties.get(), which calls
native method native_get.

I fixed by using the default class loader instead. This would only make
a difference in the extremely rare case that the Android application
installs a class loader that's not capable of finding Android classes.
I tested that this behaves as expected on a device, fixes the issue
with Robolectric, and detects it's not Android otherwise (as proven
by the unit test).
@codecov-io
Copy link

codecov-io commented Dec 9, 2016

Current coverage is 84.17% (diff: 100%)

Merging #4912 into 1.x will decrease coverage by 0.01%

@@                1.x      #4912   diff @@
==========================================
  Files           288        288          
  Lines         17808      17804     -4   
  Methods           0          0          
  Messages          0          0          
  Branches       2698       2697     -1   
==========================================
- Hits          14992      14986     -6   
- Misses         1958       1962     +4   
+ Partials        858        856     -2   

Powered by Codecov. Last update 57a9c09...100010a

@akarnokd akarnokd merged commit 7c7c9b9 into ReactiveX:1.x Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants