mirror of https://github.com/grpc/grpc-java.git
core: Providers should consider Robolectric as Android
null class loader means to use the bootstrap class loader, which would normally make sense. However, Robolectric tests run on OpenJDK and provide the Android environment as part of the application, so "Android" won't be present in the bootstrap class loader.
This commit is contained in:
parent
f46280ae9f
commit
c16edb3c90
|
@ -125,7 +125,9 @@ public abstract class ManagedChannelProvider {
|
|||
*/
|
||||
protected static boolean isAndroid() {
|
||||
try {
|
||||
Class.forName("android.app.Application", /*initialize=*/ false, null);
|
||||
// Specify a class loader instead of null because we may be running under Robolectric
|
||||
Class.forName("android.app.Application", /*initialize=*/ false,
|
||||
ManagedChannelProvider.class.getClassLoader());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
// If Application isn't loaded, it might as well not be Android.
|
||||
|
|
|
@ -124,7 +124,9 @@ public abstract class NameResolverProvider extends NameResolver.Factory {
|
|||
|
||||
private static boolean isAndroid() {
|
||||
try {
|
||||
Class.forName("android.app.Application", /*initialize=*/ false, null);
|
||||
// Specify a class loader instead of null because we may be running under Robolectric
|
||||
Class.forName("android.app.Application", /*initialize=*/ false,
|
||||
NameResolverProvider.class.getClassLoader());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
// If Application isn't loaded, it might as well not be Android.
|
||||
|
|
Loading…
Reference in New Issue