Can’t add AdMob to my project: My project is ReactNative and AdMob needs JAVA

Ok so it looks as though you’re trying to put Java and JavaScript code in the same file, which won’t work.

In your included javascript project snippet, this whole section:

//problems start from here. This is the copied text from
package ...
import ...

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        MobileAds.initialize(this, new OnInitializationCompleteListener() {
            public void onInitializationComplete(InitializationStatus initializationStatus) {
//this is where they end

Would need to be in a separate Java file.

Now, I see you’re using react-native. I would need to know if you’re using standard react-native or an expo managed project.

If you are using an expo managed project, there is already a package made for admob, just follow the instructions in the documentation here:

If you are just using react native, it gets quite a bit more complicated. The docs that you provided are intended for Java / Kotlin native development opposed to native development through react, so it will be hard for you to get it working using the code from that document. This link should help you get it working for react-native:

*note that in the included docs provided by google, where you see package ... and import ..., you’re expected to fill in your actual package name, and any other imports you need for the class.

Hopefully this has provided some insight on your problem, let me know if there are still any issues.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top