AppCompatActivity Error when using custom plugin

Hi everyone,
I’m trying to create a custom plugin to get location information in background in Unity for Android.
However, after doing everything both on andorid studio and unity, I get this error in the Build:

AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/app/AppCompatActivity;

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/app/AppCompatActivity;
com.unity3d.player.UnityPlayer.nativeRender(Native Method)
com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:214)
com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “androidx.appcompat.app.AppCompatActivity” on path: DexPathList[[zip file “/data/app/com.DefaultCompany.TestJavaPlugin-rHVBIXnek9UUuf-e8zhVkA==/base.apk”],nativeLibraryDirectories=[/data/app/com.DefaultCompany.TestJavaPlugin-rHVBIXnek9UUuf-e8zhVkA==/lib/arm, /data/app/com.DefaultCompany.TestJavaPlugin-rHVBIXnek9UUuf-e8zhVkA==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
java.lang.ClassLoader.loadClass(ClassLoader.java:379)
java.lang.ClassLoader.loadClass(ClassLoader.java:312)
… 6 more
UnityEngine.AndroidJNISafe.CheckException () (at :0)
UnityEngine.AndroidJNISafe.FindClass (System.String name) (at :0)
UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[ ] args) (at :0)
UnityEngine.AndroidJavaObject…ctor (System.String className, System.Object[ ] args) (at :0)
TestJava.Start () (at :0)

Can anyone tell me a possibile solution or cause of the problem? Thanks!

Did u solve this problem? I have the same problem.

I have the same issue!

Could you show the code from which this happens?

The issue happens whenever I try to use an external library like AppCompat on a plugin I am creating and trying to use inside Unity for Android devices.
If i try to "import androidx.appcompat.app.AppCompatActivity" and extend from AppcompatActivity
like in the image attached, the Android App builded will not work and will crash at the moment i try to open this activity.
I have tried to add the AppCompat dependency library inside Plugins/Android folder, however this did not work.

I am using Unity 2019.4.12f1.
This issue has emerged when switched the Android → Player → Other Settings → Target Api Level to 31 (which is the min version number now play store supports for new app updates)
On Target Api Level 30 and Below, this issue is not present.

So in General I am limited for my android plugin to use only embeded native android functionalities like:
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.widget.Toast;
import android.Manifest;

Without the possibility to add any other external dependencies.

I have the same problem