microg/GmsCore · error · LoadingException
null application Context
Error message
null application Context
What it means
DynamiteModule.load(context, policy, moduleId) first resolves context.getApplicationContext(); if that returns null it throws a LoadingException('null application Context'). Dynamite needs a real application context to query and load the dynamic module.
Source
Thrown at play-services-basement/src/main/java/com/google/android/gms/dynamite/DynamiteModule.java:133
} catch (Exception e) {
Log.e(TAG, "Failed to load module descriptor class.", e);
return 0;
}
}
public static int getRemoteVersion(@NonNull Context context, @NonNull String moduleId) {
return getRemoteVersion(context, moduleId, false);
}
public static int getRemoteVersion(@NonNull Context context, @NonNull String moduleId, boolean forceStaging) {
Log.e(TAG, "Remote modules not yet supported");
return 0;
}
@NonNull
public static DynamiteModule load(@NonNull Context context, @NonNull VersionPolicy policy, @NonNull String moduleId) throws LoadingException {
Context applicationContext = context.getApplicationContext();
if (applicationContext == null) throw new LoadingException("null application Context", null);
try {
VersionPolicy.SelectionResult result = policy.selectModule(context, moduleId, VersionPolicy.IVersions.Default);
Log.i(TAG, "Considering local module " + moduleId + ":" + result.localVersion + " and remote module " + moduleId + ":" + result.remoteVersion);
switch (result.selection) {
case NONE:
throw new LoadingException("No acceptable module " + moduleId + " found. Local version is " + result.localVersion + " and remote version is " + result.remoteVersion + ".");
case LOCAL:
Log.i(TAG, "Selected local version of " + moduleId);
return new DynamiteModule(context);
case REMOTE:
throw new UnsupportedOperationException();
default:
throw new LoadingException("VersionPolicy returned invalid code:" + result.selection);
}
} catch (LoadingException loadingException) {
throw loadingException;
} catch (Throwable e) {
throw new LoadingException("Failed to load remote module.", e);View on GitHub (pinned to 157c9d86ac)
Solutions
- Pass a real, fully-attached Context: an Activity, a Service, or context.getApplicationContext() from a live component
- In tests, use ApplicationProvider.getApplicationContext() (Robolectric) or a real instrumentation target context instead of a mocked Context
- Never call DynamiteModule.load before the Application is created (e.g., not in a static initializer of a non-ContentProvider class)
- Wrap load in try-catch LoadingException and degrade gracefully
Example fix
// before DynamiteModule.load(mockContext, policy, "module"); // throws // after Context appCtx = ApplicationProvider.getApplicationContext(); DynamiteModule.load(appCtx, policy, "module");
Defensive patterns
Strategy: type-guard
Validate before calling
if (context == null || context.getApplicationContext() == null) {
// do not call DynamiteModule.load with this context
} Type guard
boolean canLoadDynamite(Context ctx) {
return ctx != null && ctx.getApplicationContext() != null;
} Try / catch
try {
DynamiteModule m = DynamiteModule.load(ctx, policy, moduleId);
} catch (DynamiteModule.LoadingException e) {
Log.w(TAG, "Dynamite load failed", e);
} Prevention
- Always pass an Activity, Service, or a real application context
- In tests use ApplicationProvider.getApplicationContext(), not mocked Contexts
- Don't call DynamiteModule.load from static initializers before the Application exists
When it happens
Trigger: Passing a bare/mock Context (e.g., Mockito-mocked Context, Robolectric context without application, or a ContextWrapper wrapping null) whose getApplicationContext() returns null.
Common situations: Unit or instrumentation tests injecting fake Contexts into gms APIs; early-lifecycle code calling load before the Application is attached; custom Context subclasses that override getApplicationContext() to return null.
Related errors
- No acceptable module " + moduleId + " found. Local version i
- VersionPolicy returned invalid code:
- onCreateView not allowed on MapViewDelegate
- onDestroyView not allowed on MapViewDelegate
- onInflate not allowed on MapViewDelegate
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/f02a88585d74d79e.
Report an issue: GitHub.