Search Unity

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/ContextCompat; - U

Discussion in 'Android' started by siddharth3322, Sep 8, 2019.

  1. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    When I try to export my project Android build, I am getting this kind of error in debug log and my game get force closed on the spot.

    noclassdeffounderror.PNG

    Let me explain what I have done so I have started getting this error. Newly I have implemented AdMob Mediation within my game project.

    So I have integrated Chartboost Mediation plugin within my project and from first to last I have followed this document:
    https://developers.google.com/admob/unity/mediation/chartboost

    Additionally, I have added Chartboost.jar and android-support-v4.jar files within my Plugins/Android folder.

    After doing these steps my project started crashing on start and before it was working fine because I have a backup of the previous version of my Unity project.

    Here you have my project Build settings image:
    drifter_project_build settings.PNG

    Now I want to solve this problem so please guide some solution for this. I am available for all kinds of experiments.
     
  2. ARPAplus

    ARPAplus

    Joined:
    Jun 5, 2015
    Posts:
    32
    Confirm, have multiple crashes with AdMob Mediation and com.moat.analytics crashes. We also use Chartboost and some other mediation plugins. I've contacted with AdMob team, they told me they don't have anything related to Moat Analytics in their codes, so they won't care about it.
     
    siddharth3322 likes this.
  3. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    I hope someone will share their opinion on this subject.
     
  4. SneakyFoxDev

    SneakyFoxDev

    Joined:
    Aug 3, 2017
    Posts:
    10
    So, same issue here, but I have a lot of plugins integrated and it all works fine(IronSource, Amplitude, Google Play Games, some other native plugins) but when I added EasyMobile Pro plugin, it's start crashing with the same Issue. So, is there any solutions?

    photo_2019-10-16_20-45-13.jpg
     
  5. SneakyFoxDev

    SneakyFoxDev

    Joined:
    Aug 3, 2017
    Posts:
    10
    So, I'm fixed this problem, for more info check this https://github.com/firebase/quickstart-unity/issues/402

    First of all, I found and install PlayServicesResolver 1.2.95 and it don't download androidx libraries - it is what we need.
    Secondly, run force resolve to download old androd libraries.

    You should check that you plugins folder don't contain any androidx libs, and use only android libs to avoid any errors. Also waiting for normal support for androidx. Good luck)
     
  6. DropoutGamer

    DropoutGamer

    Joined:
    Jul 3, 2019
    Posts:
    5
  7. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    No, I can't able to solve this problem so I have removed the Chartboost ad network from my project and integrated other ad networks within my Admob Mediation setup.

    Because only Chartboost giving me this kind of problems.
     
    DropoutGamer likes this.
  8. febix

    febix

    Joined:
    Jun 2, 2013
    Posts:
    12
    Solved. If you have a crash in Chartboost Unity with AndroidX and have an error "android.support.v4.content.ContextCompat":
    The problem is that current chartboost library from sdk not "jetified".
    "The standalone Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead."

    1). Download jetifier
    https://developer.android.com/studio/command-line/jetifier

    2). After you integrate Chartboost to unity project, select "chartboost.jar" from Assets\Plugins\Android\ChartboostSDK\libs\chartboost.jar
    rename it to "chartboostX.jar" and use command:
    Code (CSharp):
    1. ./jetifier-standalone -i chartboostX.jar -o chartboost.jar
    Replace with new "chartboost.jar" in Unity project.

    3). Don't forget to add
    Code (CSharp):
    1. ([rootProject] + (rootProject.subprojects as List)).each {
    2.     ext {
    3.         it.setProperty("android.useAndroidX", true)
    4.         it.setProperty("android.enableJetifier", true)
    5.     }
    6. }
    to your gradle file.
    And also add only in dependencies section:

    Code (CSharp):
    1. implementation 'androidx.appcompat:appcompat:1.1.0'
    and remove:

    Code (CSharp):
    1. implementation 'com.android.support:support-v4:27.1.1'
    (I think: because you need to use only androidX libraries, for example by convert all the support libraries to androidX).

    4). Profit!