Narendra Pal
Narendra Pal

Reputation: 6604

Integration Unity Ads in Android Native

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.

Upvotes: 1

Views: 3344

Answers (2)

EiN
EiN

Reputation: 131

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'
    }
}

Upvotes: 6

oalpayli
oalpayli

Reputation: 265

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.

Upvotes: 2

Related Questions