Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

AppCompatActivity Error when using custom plugin

Discussion in 'Android' started by LuciaGambardella, Jun 21, 2020.

  1. LuciaGambardella

    LuciaGambardella

    Joined:
    Jul 22, 2017
    Posts:
    8
    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 <dcb3aea45c9345de8667cb9cbdf166d6>:0)
    UnityEngine.AndroidJNISafe.FindClass (System.String name) (at <dcb3aea45c9345de8667cb9cbdf166d6>:0)
    UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[] args) (at <dcb3aea45c9345de8667cb9cbdf166d6>:0)
    UnityEngine.AndroidJavaObject..ctor (System.String className, System.Object[] args) (at <dcb3aea45c9345de8667cb9cbdf166d6>:0)
    TestJava.Start () (at <cccc0acf8ba6454fbdd0502d229c1895>:0)

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

    BelieveXiaoShuai

    Joined:
    Nov 6, 2017
    Posts:
    16
    Did u solve this problem? I have the same problem.
     
  3. theodhoribeka

    theodhoribeka

    Joined:
    Aug 9, 2018
    Posts:
    4
    I have the same issue!
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,637
    Could you show the code from which this happens?
     
  5. theodhoribeka

    theodhoribeka

    Joined:
    Aug 9, 2018
    Posts:
    4
    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.
     

    Attached Files: