sbugert / react-native-admob

A react-native component for Google AdMob banners
BSD 2-Clause "Simplified" License
1.13k stars 531 forks source link

React native admob not working after updating !! #448

Closed softsstar closed 4 years ago

softsstar commented 5 years ago

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

Linrasis commented 5 years ago

Same issue :/

dayhaysoos commented 5 years ago

Same issue

iacocesar commented 5 years ago

Same issue RN 0.60

iacocesar commented 5 years ago

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!

mallmann-objective commented 5 years ago

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

iacocesar commented 5 years ago

@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

mallmann-objective commented 5 years ago

@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 commented 5 years ago

@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

SaGaR1084 commented 5 years ago

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

a26364177 commented 5 years ago

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

ank26oct commented 5 years ago

Go to:

https://github.com/sbugert/react-native-admob/issues/452#issuecomment-506705969

amixel commented 5 years ago

same issue

bishrulhaq commented 5 years ago

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

MatheusAlvesA commented 5 years ago

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

vamsi920 commented 4 years ago

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!

ghost commented 4 years ago

Anybody found a working solution

koenpunt commented 4 years ago

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

koenpunt commented 4 years ago

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

mxvsh commented 4 years ago

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.

koenpunt commented 4 years ago

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.

vlerants commented 4 years ago

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

and it worked for me.

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

I hope this helps.

hugoh59 commented 4 years ago

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

AftabUfaq commented 4 years ago

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

Nishkarshgithub commented 4 years ago

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...

Install by using..

npm install react-native-admob@2.0.0-beta.6

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.

usersina commented 4 years ago

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 react-native-admob@2.0.0-beta.6

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

kanyo33 commented 4 years ago

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 react-native-admob@2.0.0-beta.6

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.

sergenti commented 4 years ago

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

omprakash8080 commented 3 years ago

Update the file :- Build.gradle(react-native-admob)

// implementation 'com.google.android.gms:play-services-ads:+' // comment this line

implementation 'com.google.android.gms:play-services-ads:19.7.0' // add this line.

sarceda commented 3 years ago

Update the file :- Build.gradle(react-native-admob)

// implementation 'com.google.android.gms:play-services-ads:+' // comment this line

implementation 'com.google.android.gms:play-services-ads:19.7.0' // add this line.

This, and other variations in the 'com.google.android.gms:play-services-ads:' implementation works, and I can build my app.

The problem is than then there is a great amount of "crashes" with this message:

java.lang.IllegalStateException
com.sbugert.rnadmob.ReactAdView.setAdSize

This is the Stack trace. Any idea on what to look for?

com.facebook.react.bridge.JSApplicationIllegalArgumentException: 
  at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp (ViewManagersPropertyCache.java:98)
  at com.facebook.react.uimanager.ViewManagerPropertyUpdater$FallbackViewManagerSetter.setProperty (ViewManagerPropertyUpdater.java:131)
  at com.facebook.react.uimanager.ViewManagerPropertyUpdater.updateProps (ViewManagerPropertyUpdater.java:51)
  at com.facebook.react.uimanager.ViewManager.updateProperties (ViewManager.java:46)
  at com.facebook.react.uimanager.NativeViewHierarchyManager.updateProperties (NativeViewHierarchyManager.java:139)
  at com.facebook.react.uimanager.UIViewOperationQueue$UpdatePropertiesOperation.execute (UIViewOperationQueue.java:93)
  at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:844)
  at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:952)
  at com.facebook.react.uimanager.UIViewOperationQueue.access$2200 (UIViewOperationQueue.java:44)
  at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded (UIViewOperationQueue.java:1012)
  at com.facebook.react.uimanager.GuardedFrameCallback.doFrame (GuardedFrameCallback.java:29)
  at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame (ReactChoreographer.java:172)
  at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame (ChoreographerCompat.java:84)
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1090)
  at android.view.Choreographer.doCallbacks (Choreographer.java:893)
  at android.view.Choreographer.doFrame (Choreographer.java:809)
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1078)
  at android.os.Handler.handleCallback (Handler.java:907)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:216)
  at android.app.ActivityThread.main (ActivityThread.java:7625)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)
Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Method.invoke (Native Method)
  at com.facebook.react.uimanager.ViewManagersPropertyCache$PropSetter.updateViewProp (ViewManagersPropertyCache.java:83)
Caused by: java.lang.IllegalStateException: 
  at com.google.android.gms.internal.ads.zzzn.setAdSizes
  at com.google.android.gms.ads.BaseAdView.setAdSize
  at com.google.android.gms.ads.AdView.setAdSize
  at com.sbugert.rnadmob.ReactAdView.setAdSize (RNAdMobBannerViewManager.java:158)
  at com.sbugert.rnadmob.RNAdMobBannerViewManager.setPropAdSize (RNAdMobBannerViewManager.java:216)
abhisheq6u commented 3 years ago

Update the file :- Build.gradle(react-native-admob)

// implementation 'com.google.android.gms:play-services-ads:+' // comment this line

implementation 'com.google.android.gms:play-services-ads:19.7.0' // add this line.

This worked for me straight away!! Thanks to @omprakash8080

ghost commented 2 years ago

Has this issue been resolved? I try do like https://github.com/sbugert/react-native-admob/issues/448#issuecomment-814028706 or like https://github.com/sbugert/react-native-admob/issues/448#issuecomment-537659889, but them don't work for me, usage issue doesn't change.

    "react": "17.0.1",
    "react-native": "0.64.1",
    "react-native-admob": "^2.0.0-beta.6",
varolemre commented 2 years ago

Worst npm package i have ever seen. It's sad that there is no alternative

koenpunt commented 2 years ago

Worst npm package i have ever seen. It's sad that there is no alternative

It's open source, feel free to improve it yourself.

Salman98 commented 1 year ago

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

after using the above changes and adding these line in react-native-admob@2.0.0-beta.6 build.gradle file , I'm able to resolve this issue

 implementation ('com.google.android.gms:play-services-ads:19.6.0') { force = true; }