PC パソコン

How to Fix “Unable to get provider” in connectedDebugAndroidTest

If ./gradlew :app:connectedDebugAndroidTest fails with “Unable to get provider” and a ClassNotFoundException for a provider in a dynamic feature module, the build may be affected by a known AGP issue. Google lists Issue #257765153 as fixed in AGP 9.4.0-alpha02; upgrading to stable AGP 9.4.0 or newer is recommended.

Typical error

java.lang.RuntimeException:
Unable to get provider com.example.feature.MyProvider:
java.lang.ClassNotFoundException:
Didn't find class "com.example.feature.MyProvider"

At instrumentation startup, Android instantiates providers from the merged manifest. If the declaration is installed without the dynamic-feature code that owns the class, startup stops before tests run.

When this fix applies

  • The app uses a dynamic feature module.
  • The provider class belongs to that feature.
  • :app:connectedDebugAndroidTest fails.
  • The root cause is the provider’s ClassNotFoundException.
  • The project uses an affected AGP version older than the 9.4.0-alpha02 fix.

An incorrect android:name or namespace causes the same exception. Confirm that the fully qualified name matches the real provider first.

Recommended fix

1. Inspect the merged manifest

Use Android Studio’s Merged Manifest view to verify the owning module, final class name, and source manifest.

<provider
    android:name="com.example.feature.MyProvider"
    android:authorities="${applicationId}.feature.provider"
    android:exported="false" />

2. Upgrade to stable AGP 9.4.0 or newer

The AGP 9.4 release notes list the fix under 9.4.0-alpha02, and it is included in stable 9.4.0. Use a suitable stable release rather than the historical alpha.

plugins {
    id("com.android.application") version "9.4.0" apply false
    id("com.android.dynamic-feature") version "9.4.0" apply false
}

Google’s compatibility table requires Gradle 9.6.0, SDK Build Tools 36.0.0, and JDK 17 for AGP 9.4.0. Keep application and dynamic-feature plugins on the same AGP version.

3. Retest from a clean state

./gradlew --stop
./gradlew clean
./gradlew :app:connectedDebugAndroidTest --stacktrace

Use gradlew.bat on Windows. Remove stale app and test APKs from the device if necessary.

Alternatives

  • Temporarily move a startup-critical provider into the base app if the architecture permits.
  • Use a test installation that includes the provider’s feature.
  • Pin CI to a verified unaffected AGP version.
  • Run provider-independent tests separately.

Moving a feature to the base changes download size and delivery behavior. Treat it only as a temporary workaround.

If it still fails

  • Confirm the provider exists in a Debug-visible source set.
  • Verify the dynamic-feature/base-app relationship.
  • Confirm that the base APK and required split are installed together.
  • Inspect androidTest manifest overrides.

How to verify

  1. connectedDebugAndroidTest reaches test execution.
  2. The provider ClassNotFoundException disappears.
  3. Gradle produces test result files.
  4. The test succeeds on a clean emulator.

Important notes

Deleting the provider declaration can make tests start while breaking production behavior. If the provider is required at startup, verify that its placement in an on-demand feature is valid for the delivery model.

Summary

The dynamic-feature provider failure was fixed in AGP 9.4.0-alpha02 and is included in stable 9.4.0. Verify the manifest and class name, align AGP, Gradle, Build Tools, and JDK versions, then retest on a clean device.

References