java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/LocalBroadcastManager only on Build APK
I faced similar problem.
This is because of the instant run feature is enabled. Just disable it, clean the project then build the project. Now generate release Apk. It will work.
May be Android Studio is not including all files in Apk, when we use the instant run to fasten the process.
On PC:
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
On Mac:
Android Studio --> Preferences --> Build, Execution, Deployment --> Instant Run.
The solution that worked for me was to add the dependency
implementation "com.android.support:support-v4:<compileSdkVersion>.x.x"
in my gradle dependencies.
You can check the version according to your compileSdkVersion here.
From sdk version 29, you need to convert your project to androidx and use the new dependency
I faced this issue after migrating to AndroidX.
I have added the following dependency.
implementation 'androidx.legacy:legacy-support-v4:1.0.0'