1

I am doing Unity Ads integration in native android. But I am facing below issue.

java.lang.NoClassDefFoundError: com.unity3d.ads.android.R$layout
            at com.unity3d.ads.android.video.UnityAdsVideoPlayView.e(UnityAdsVideoPlayView.java:225)
            at com.unity3d.ads.android.video.UnityAdsVideoPlayView.<init>(UnityAdsVideoPlayView.java:62)
            at com.unity3d.ads.android.view.UnityAdsMainView.setViewState(UnityAdsMainView.java:76)
            at com.unity3d.ads.android.view.b.run(UnityAdsFullscreenActivity.java:593)
            at android.os.Handler.handleCallback(Handler.java:725)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5099)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:803)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:570)
            at dalvik.system.NativeStart.main(Native Method)

Can anybody help me how to resolve that. I have this resource file in layout then too I face this error.

Narendra Pal
  • 6,474
  • 13
  • 49
  • 85

2 Answers2

6

I had the exact same problem as you, and the solution was to download the aar file oalpayli told you about, put it inside the libs folder, and in gradle add this code:

dependencies {
    compile(name:'unity-ads',ext:'aar')
}

repositories {
    flatDir {
        dirs 'libs'
    }
}
EiN
  • 121
  • 1
  • 6
2

This issue has been addressed in the latest SDK update. Please follow these instructions to update:

  1. Download the unity-ads.aar file
  2. Remove all previously added Unity Ads integration related files/references from your project
  3. On Android Studio, Click File -> New -> New Module
  4. Select Import .JAR/.AAR Package, click Next
  5. Locate unity-ads.aar, module name should change to unity-ads, click Finish.
  6. Now, Right Click the default module of your project, select Open Module Settings
  7. Ensure that your default module is selected, click the Dependencies tab
  8. Click the plus sign in the bottom of the screen, choose Module Dependency
  9. Choose unity-ads from the popup that opens

This should fix the R$Layout issue.

oalpayli
  • 227
  • 1
  • 2
  • 9
  • You are right but in my case I need to use the jar file and following the instruction to pass aar to jar file, I'm getting the same error java.lang.NoClassDefFoundError: com.unity3d.ads.android.R$layout – AlphaDeveloper Aug 29 '16 at 15:18
  • Here: "Locate unity-ads.aar, module name should change to unity-ads, click Finish." , when I click Finish, the window trembles and nothing happens, im guessing the trembling means an error, but I dont know why. Any ideas? – Daahrien Dec 27 '16 at 10:14