React-native-admob: React native admob not working after updating !!

Created on 20 Jun 2019  路  27Comments  路  Source: sbugert/react-native-admob

getting annotation null error on newer reactnative version

Configure project :react-native-admob
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
WARNING: The specified Android SDK Build Tools version (23.0.1) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.4.0.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '23.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

Task :react-native-admob:compileDebugJavaWithJavac FAILED
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobBannerViewManager.java:4: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
^
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobInterstitialAdModule.java:5: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
^
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobRewardedVideoAdModule.java:5: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
^
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNPublisherBannerViewManager.java:4: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;
^
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobBannerViewManager.java:119: error: cannot find symbol
private void sendEvent(String name, @Nullable WritableMap event) {
^
symbol: class Nullable
location: class ReactAdView
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobBannerViewManager.java:196: error: cannot find symbol
@Nullable
^
symbol: class Nullable
location: class RNAdMobBannerViewManager
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobBannerViewManager.java:254: error: cannot find symbol
@Nullable
^
symbol: class Nullable
location: class RNAdMobBannerViewManager
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobInterstitialAdModule.java:103: error: cannot find symbol
private void sendEvent(String eventName, @Nullable WritableMap params) {
^
symbol: class Nullable
location: class RNAdMobInterstitialAdModule
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNAdMobRewardedVideoAdModule.java:123: error: cannot find symbol
private void sendEvent(String eventName, @Nullable WritableMap params) {
^
symbol: class Nullable
location: class RNAdMobRewardedVideoAdModule
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNPublisherBannerViewManager.java:122: error: cannot find symbol
private void sendEvent(String name, @Nullable WritableMap event) {
^
symbol: class Nullable
location: class ReactPublisherAdView
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNPublisherBannerViewManager.java:229: error: cannot find symbol
@Nullable
^
symbol: class Nullable
location: class RNPublisherBannerViewManager
D:\React Native\admo\node_modules\react-native-admob\android\src\main\java\com\sbugert\rnadmob\RNPublisherBannerViewManager.java:302: error: cannot find symbol
@Nullable
^
symbol: class Nullable
location: class RNPublisherBannerViewManager
12 errors

Most helpful comment

Go to react-native-admob under node-modules and change "import android.support.annotation.Nullable;" to import androidx.annotation.Nullable;

All 27 comments

Same issue :/

Same issue

Same issue RN 0.60

Solved adding

configurations.all { resolutionStrategy { force "com.google.android.gms:play-services-basement:16.0.1" force "com.google.android.gms:play-services-base:16.0.1" force "com.google.android.gms:play-services-stats:16.0.1" force "com.google.android.gms:play-services-gcm:16.0.0" force "com.google.android.gms:play-services-ads:16.0.1" } }

implementation (project(':react-native-admob'), { exclude group: "com.google.android.gms" })

But have other error
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/ads/InterstitialAd;

UPDATE


add implementation ('com.google.android.gms:play-services-ads:16.+') { force = true; } WORKS!

@IacoCesar Where should I put this configuration? Is it in the build.gradle file?

@IacoCesar Where should I put this configuration? Is it in the build.gradle file?

Yes put the implementation in dependencies and configurations.all in upper of dependencies

@IacoCesar Where should I put this configuration? Is it in the build.gradle file?

Yes put the implementation in dependencies and configurations.all in upper of dependencies

Sorry, I'm still confused about the gradle file. Am I missing something?

Screen Shot 2019-06-25 at 11 55 39

@IacoCesar Where should I put this configuration? Is it in the build.gradle file?

Yes put the implementation in dependencies and configurations.all in upper of dependencies

Sorry, I'm still confused about the gradle file. Am I missing something?

Screen Shot 2019-06-25 at 11 55 39

build.gradle of the android/app

Same issue in "react-native": "0.59.9"
"react": "16.8.3"

Same issue in "react-native": "0.59.9"
"react": "16.8.3"

same issue

Go to react-native-admob under node-modules and change "import android.support.annotation.Nullable;" to import androidx.annotation.Nullable;

I fixed this issue on my own lib.
Check this: https://github.com/sbugert/react-native-admob/issues/458

Solved adding

configurations.all { resolutionStrategy { force "com.google.android.gms:play-services-basement:16.0.1" force "com.google.android.gms:play-services-base:16.0.1" force "com.google.android.gms:play-services-stats:16.0.1" force "com.google.android.gms:play-services-gcm:16.0.0" force "com.google.android.gms:play-services-ads:16.0.1" } }

implementation (project(':react-native-admob'), { exclude group: "com.google.android.gms" })

But have other error
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/ads/InterstitialAd;

UPDATE

add implementation ('com.google.android.gms:play-services-ads:16.+') { force = true; } WORKS!

Anybody found a working solution

I've opened a PR to bring this library up to date with the latest version of React Native, and thus bringing support for CocoaPods and support for Android X: #472

The latest beta (v2.0.0-beta.6) should work just fine with the latest version of React Native (and thus AndroidX)

The latest beta (v2.0.0-beta.6) should work just fine with the latest version of React Native (and thus AndroidX)

it's not working on 2.0.0-beta.6, I just initiated fresh react-native project, and first module I installed was react-native-admob.

I need a little bit more than just "it's not working". As you can see in the example project it is working, so I think it's a matter of configuration.

I switched from import android.support.annotation.Nullable; to import androidx.annotation.Nullable; on these files:

  • RNAdMobBannerViewManager.java

  • RNAdMobInterstitialAdModule.java

  • RNAdMobRewardedVideoAdModule.java

  • RNPublisherBannerViewManager.java

and it worked for me.

Note that you may also have top comment lines 92-95 on file :

  • RNAdMobRewardedVideoAdModule.java

    // @Override
    // public void onRewardedVideoCompleted() {
    //     sendEvent(EVENT_VIDEO_COMPLETED, null);
    // }
    

I hope this helps.

I already have it like that but still throw error message.

have the same issue on m project. apply all the above but get nothing . same erroe

Stuck on this for about 7 hours and finally found the solution which is pretty simple. Just upgrade react-native-admob to v2.0.0-beta.6 using

My react-native project config...

  • "react": "16.9.0",
  • "react-native": "0.61.5",
  • "react-native-admob": "^2.0.0-beta.6",

Install by using..

npm install [email protected]

First, create a Google Admob account and create you app in it and copy App_ID from GoogleAdmob > Apps > View All Apps > Copy AppID.

and then edit your AndroidManifest file. Project > android > app > src > AndroidManifest .

under tag insert

<meta-data 
        android:name="com.google.android.gms.ads.APPLICATION_ID" 
        android:value="**YOUR_APP_ID**"/>
>

note: please add your app id in android.value

Now clean your build folder and rebuild the project everything will work fine.

Stuck on this for about 7 hours and finally found the solution which is pretty simple. Just upgrade react-native-admob to v2.0.0-beta.6 using

My react-native project config...

  • "react": "16.9.0",
  • "react-native": "0.61.5",
  • "react-native-admob": "^2.0.0-beta.6",

Install by using..

npm install [email protected]

First, create a Google Admob account and create you app in it and copy App_ID from GoogleAdmob > Apps > View All Apps > Copy AppID.

and then edit your AndroidManifest file. Project > android > app > src > AndroidManifest .

under tag insert

<meta-data 
        android:name="com.google.android.gms.ads.APPLICATION_ID" 
        android:value="**YOUR_APP_ID**"/>
>

note: please add your app id in android.value

Now clean your build folder and rebuild the project everything will work fine.

I've had another error after solving the previous one with this code. I had to add the following code in android/app/build.gradle for it to finally work:
`android {
defaultConfig {
...
multiDexEnabled true
}
...
}

dependencies {
implementation 'com.android.support:multidex:1.0.3'
}`

Source: https://developer.android.com/studio/build/multidex

Stuck on this for about 7 hours and finally found the solution which is pretty simple. Just upgrade react-native-admob to v2.0.0-beta.6 using
My react-native project config...

  • "react": "16.9.0",
  • "react-native": "0.61.5",
  • "react-native-admob": "^2.0.0-beta.6",

Install by using..

npm install [email protected]

First, create a Google Admob account and create you app in it and copy App_ID from GoogleAdmob > Apps > View All Apps > Copy AppID.
and then edit your AndroidManifest file. Project > android > app > src > AndroidManifest .
under tag insert

<meta-data 
        android:name="com.google.android.gms.ads.APPLICATION_ID" 
        android:value="**YOUR_APP_ID**"/>
>

note: please add your app id in android.value
Now clean your build folder and rebuild the project everything will work fine.

I've had another error after solving the previous one with this code. I had to add the following code in android/app/build.gradle for it to finally work:
`android {
defaultConfig {
...
multiDexEnabled true
}
...
}

dependencies {
implementation 'com.android.support:multidex:1.0.3'
}`

Source: https://developer.android.com/studio/build/multidex

Can attest to the multidex error being a common issue with this plugin. This workaround did the job. Thanks.

same issue, I implemented Admob using _@react-native-firebase/app_ and _@react-native-firebase/admob_ btw I would really like to use this library, Ad-components are such a better implementation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MohsinTariq10 picture MohsinTariq10  路  6Comments

furkancelik picture furkancelik  路  5Comments

ozmaat picture ozmaat  路  3Comments

xencodes picture xencodes  路  4Comments

shinriyo picture shinriyo  路  3Comments