LoginSignup
1
1

More than 3 years have passed since last update.

react-native-admobをインストールしたときのandroidでのエラー

Posted at

広告を出したくてreact-native-admobを利用したがnpm installしただけで androidで起動できなくなった。

流れ

インストールは以下を参考に実施。
https://qiita.com/juginon/items/7f4ee4273b2c480277f3

npm instal  --save react-native-admob@next

そしてこの段階で npm run android以下実行してエラーが出る。

エラー1 react-native-admob:compileDebugJavaWithJavac FAILED

以下のようなエラーがドバババとでる。

****/node_modules/react-native-admob/android/src/main/java/com/sbugert/rnadmob/RNAdMobInterstitialAdModule.java:20: エラー: シンボルを見つけられません
import com.google.android.gms.ads.InterstitialAd;
                               ^
シンボル:   クラス InterstitialAd
場所: パッケージ com.google.android.gms.ads

参考リンク: https://github.com/sbugert/react-native-admob/issues/448

上記リンクの一番下の対応で、このエラーはでなくなった。

node_module/react_native_admobのbuild.gradleを修正する。

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

しかし、まだエラーが出る

エラー2 “unexpected element found in ” error?

参考
https://stackoverflow.com/questions/62969917/how-to-fix-unexpected-element-queries-found-in-manifest-error

使っているgradleのバージョンが3.5.3だったので、3.5.4に更新して対応。

# android/builed.gradle
    dependencies {
        ...
        classpath("com.android.tools.build:gradle:3.5.4")  
    }


もういっちょエラーが出る

エラー3 The number of method references in a .dex file cannot exceed 64K

参考:https://stackoverflow.com/questions/36785014/the-number-of-method-references-in-a-dex-file-cannot-exceed-64k-api-17

android/app/build.gradle のdefaultConfigに
「multiDexEnabled true」

#android/app/build.gradle

    defaultConfig {
        ...
        multiDexEnabled true //bug
    }

おわり

以上でエラーは一旦落ち着いた。あとは手順どおりで広告表示まで到達。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1