error Task :react-native-admob:compileDebugJavaWithJavac FAILED
  • 08-May-2023
Lightrun Team
Author Lightrun Team
Share
error Task :react-native-admob:compileDebugJavaWithJavac FAILED

error Task :react-native-admob:compileDebugJavaWithJavac FAILED when one day before Works well >.<

Lightrun Team
Lightrun Team
08-May-2023

Explanation of the problem

The React Native AdMob module is failing to compile in the Android Studio environment, generating the error message “Task :react-native-admob:compileDebugJavaWithJavac FAILED”. The module was functional until yesterday but now shows the error, even when installing it into a new project. The error message is consistent and indicates that the required libraries cannot be found. Specifically, the InterstitialAd, RewardedVideoAd, RewardItem, AppEventListener, PublisherAdRequest, and PublisherAdView classes are not found in their corresponding packages.

> Task :react-native-admob:compileDebugJavaWithJavac FAILED
26 actionable tasks: 5 executed, 21 up-to-date
D:\Node-WEb-React\000ADMOB_BASE\testeos\tadmob1\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobInterstitialAdModule.java:20: error: cannot find symbol
import com.google.android.gms.ads.InterstitialAd;
^
symbol: class InterstitialAd
location: package com.google.android.gms.ads

 

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 error Task :react-native-admob:compileDebugJavaWithJavac FAILED when one day before Works well >.<

Based on the two answers provided, it seems that the error could be caused by a variety of issues, but most likely it is related to issues with Gradle or XML files. One suggestion is to create a new RN project and test all Gradle commands to ensure that the files are fine. From there, gradually add necessary packages and code files to identify where the error is occurring.

Another answer suggests that the issue could be related to the XML declaration not being at the very top of the file. To address this, the user searched for instances of <?xml ?> in their main project folder and found files where the declaration wasn’t at the top. Moving the declaration to the top of the file fixed the issue.

In summary, it is recommended to check Gradle and XML files for potential issues when encountering this error, and to ensure that the XML declaration is at the very top of the file. Testing in a new RN project and gradually adding code and packages can also help identify where the error is occurring.

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.