react-native-admob icon indicating copy to clipboard operation
react-native-admob copied to clipboard

Invariant Violation: Native component for "RNAdMob" does not exist

Open khalidahmedshalabi opened this issue 8 years ago • 3 comments

  • react-native-admob: 2.0.0-beta.5
  • react-native: 0.55.3
  • On Android

Error I'm getting on app start

Invariant Violation: Native component for "RNAdMob" does not exist

Linking

I read somewhere that it has to do with the linking, so here's how I've done it

  • settings.gradle
...
include ':react-native-admob'
project(':react-native-admob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')
...

include ':app'
  • build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
		classpath 'com.google.gms:google-services:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
		maven {
            url "https://maven.google.com"
        }
    }
}
  • build.gradle (app)
...
dependencies {
	compile project(':react-native-admob')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
	compile "com.google.android.gms:play-services-ads:15.0.0"
    compile "com.facebook.react:react-native:+"  // From node_modules
	compile project(':react-native-linear-gradient')
	compile project(':react-native-vector-icons')
}
...
  • MainActivity.java
...
@Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MobileAds.initialize(this, "xxxxxxxxxxxxxxxxxx");
    }
...
  • MainApplication.java
import com.sbugert.rnadmob.RNAdMobPackage;

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
		  new RNAdMobPackage(),
		 ...
      );
    }

You guys need to work on the installation part because it lacks a lot of things and leaves most of us confused.

khalidahmedshalabi avatar May 15 '18 21:05 khalidahmedshalabi

Did you try automatic installation?

Verma-Pooja avatar Aug 02 '18 12:08 Verma-Pooja

No, I did it manually @Verma-Pooja

khalidahmedshalabi avatar Aug 06 '18 00:08 khalidahmedshalabi

I have the solution for automatic installation. I didn't try on manual installation but in automatic installation, you may also face this same issue. if you want to see solution of the automatic installation in this problem you can refer this link: https://react-native-solutions.blogspot.com/2018/07/how-to-create-react-native-app-with.html

Verma-Pooja avatar Aug 06 '18 10:08 Verma-Pooja