This article is about fixing Android build issue Execution failed for task 'appcheckDebugDuplicateClasses'. in ammarahm-ed react-native-admob-native-ads
  • 29-Jan-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing Android build issue Execution failed for task 'appcheckDebugDuplicateClasses'. in ammarahm-ed react-native-admob-native-ads

Android build issue: “Execution failed for task ‘:app:checkDebugDuplicateClasses’.” in ammarahm-ed react-native-admob-native-ads

Lightrun Team
Lightrun Team
29-Jan-2023

Explanation of the problem

A JavaScript/React/React Native developer is encountering issues with a package installation while building an Android app. The build is failing with the following error message:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.google.android.gms.internal.measurement.zzbm found in modules jetified-play-services-measurement-17.2.1-runtime (com.google.android.gms:play-services-measurement:17.2.1) and jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2)
     Duplicate class com.google.android.gms.internal.measurement.zzbn found in modules jetified-play-services-measurement-17.2.1-runtime (com.google.android.gms:play-services-measurement:17.2.1) and jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2)
     ...
     Duplicate class com.google.android.gms.measurement.internal.zzio found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-17.2.1-runtime (com.google.android.gms:play-services-measurement-impl:17.2.1)
     Duplicate class com.google.android.gms.measurement.internal.zzit found in modules jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) and jetified-play-services-measurement-impl-17.2.1-runtime (com.google.android.gms:play-services-measurement-impl:17.2.1)

The error indicates that there is a conflict with another package in the project, but the developer is unable to identify which package is causing the issue.

Troubleshooting with the Lightrun Developer Observability Platform

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.

  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

Problem solution for Android build issue: “Execution failed for task ‘:app:checkDebugDuplicateClasses’.” in ammarahm-ed react-native-admob-native-ads

This error usually occurs when there is a conflict in the versions of AdMob libraries in your project. To resolve the issue, try the following steps:

  1. Clean the project: Run ./gradlew clean in the terminal.
  2. Check for duplicates in build.gradle files: Make sure you only have one version of AdMob libraries in your project.
  3. Update AdMob libraries to the latest version: Run ./gradlew androidDependencies in the terminal to check for outdated dependencies and update them if necessary.

If these steps do not resolve the issue, you can also try excluding the conflicting classes or libraries by adding the following code in your app/build.gradle file:

android {
    packagingOptions {
        exclude 'path/to/conflicting/classes'
    }
}

Other popular problems with react-native-admob-native-ads

Problem: Duplicate classes error

The most common issue that developers face when using react-native-admob-native-ads is the “Execution failed for task ‘:app:checkDebugDuplicateClasses'” error. This error occurs when there are multiple versions of AdMob libraries in the project.

Solution:

To resolve this issue, check for duplicates in the build.gradle files and make sure that you only have one version of AdMob libraries in your project. Additionally, you can exclude the conflicting classes or libraries by adding the following code in your app/build.gradle file:

android {
    packagingOptions {
        exclude 'path/to/conflicting/classes'
    }
}

Problem: Configuration issue

Another common problem with react-native-admob-native-ads is the configuration issue, such as incorrect AdMob app ID or AdUnit ID.

Solution:

To resolve this issue, make sure you have correctly added your AdMob app ID and AdUnit ID in the project. You can add the AdMob app ID in the AndroidManifest.xml file and AdUnit ID in the component where you want to display the ad. Here’s an example:

AndroidManifest.xml:
<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>

Component:
<AdMobBanner
  bannerSize="fullBanner"
  adUnitID="ca-app-pub-xxxxxxxxxxxxxxxx/zzzzzzzzzz"
  servePersonalizedAds={true}
  onAdFailedToLoad={error => console.error(error)} />

Problem: Ad loading issue

Sometimes, the ad may not load even if the configuration is correct. This can be due to several reasons such as slow internet connection, ad block, or ad request limit.

Solution:

To resolve this issue, you can check your internet connection, disable ad block, and make sure you have not exceeded the ad request limit. Additionally, you can add error handling in the component to catch and display an error message if the ad fails to load. Here’s an example:

Component:
<AdMobBanner
  bannerSize="fullBanner"
  adUnitID="ca-app-pub-xxxxxxxxxxxxxxxx/zzzzzzzzzz"
  servePersonalizedAds={true}
  onAdFailedToLoad={error => console.error(error)} />

A brief introduction to react-native-admob-native-ads

react-native-admob-native-ads is a library for React Native that allows developers to integrate Google AdMob Native Ads in their mobile applications. It supports both Android and iOS platforms. The library is based on the AdMob native ads API and provides a simple and easy-to-use interface for developers to display native ads in their React Native applications. Native ads provide a more seamless user experience compared to traditional banner ads, as they are designed to blend in with the look and feel of the application.

react-native-admob-native-ads uses the React Native architecture and follows the principles of React Native development. It can be easily integrated into any React Native project with just a few lines of code. The library offers various customization options for the ad format and size, such as banner, medium rectangle, and full-screen interstitial ads. Additionally, developers can set ad targeting options and monitor the performance of their ads using the AdMob dashboard. Overall, react-native-admob-native-ads is a convenient and reliable solution for developers looking to monetize their React Native applications through Google AdMob native ads.

Most popular use cases for react-native-admob-native-ads

  1. Monetizing mobile applications: React-native-admob-native-ads can be used to monetize mobile applications by displaying Google AdMob native ads. These ads provide a more seamless user experience compared to traditional banner ads and help increase revenue for the application.
  2. Displaying native ads in React Native applications: React-native-admob-native-ads provides an easy-to-use interface for developers to display native ads in their React Native applications. This allows for a more seamless integration of ads into the application and provides a better user experience. Here‘s an example of how to display a full-screen interstitial ad in a React Native component using react-native-admob-native-ads:
import { AdMobInterstitial } from 'react-native-admob-native-ads';

AdMobInterstitial.setAdUnitID('ca-app-pub-xxxxxxxxxxxxxxxx/zzzzzzzzzz');
AdMobInterstitial.setTestDeviceID('EMULATOR');
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
  1. Customizing ad format and size: React-native-admob-native-ads allows developers to customize the format and size of the ads displayed in their applications. This includes options for banner, medium rectangle, and full-screen interstitial ads. Customizing the ad format and size helps ensure that the ads are displayed in a way that is appropriate for the application and provides a better user experience.
Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications.

Try Lightrun’s Playground

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.