teratail header banner
teratail header banner
質問するログイン新規登録

質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.30%
React Native

React Nativeは、ネイティブモバイルアプリ(iOS/Android)を作成できるJavaScriptフレームワークです。Reactと同じ設計のため、宣言的なコンポーネントでリッチなUIを開発することが可能です。

AdMob

AdMobは、事前に指定した条件に従ってアプリに広告を表示するGoogleのサービス。開発者の向けのサービスで、広告を掲載することにより、収益を得ることが可能です。その他、見た目や雰囲気などアプリに合う広告に変更したり、広告表示の場所を指定することもできます。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Q&A

0回答

872閲覧

React Nativeで広告ライブラリadmobのビルドに失敗する

rkgmpngn

総合スコア7

React Native

React Nativeは、ネイティブモバイルアプリ(iOS/Android)を作成できるJavaScriptフレームワークです。Reactと同じ設計のため、宣言的なコンポーネントでリッチなUIを開発することが可能です。

AdMob

AdMobは、事前に指定した条件に従ってアプリに広告を表示するGoogleのサービス。開発者の向けのサービスで、広告を掲載することにより、収益を得ることが可能です。その他、見た目や雰囲気などアプリに合う広告に変更したり、広告表示の場所を指定することもできます。

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

0グッド

0クリップ

投稿2022/02/19 01:33

0

0

前提・実現したいこと

React Nativeでスマートフォンアプリ開発を行なっております。
広告ライブラリのreact-native-admob-native-adsで広告を表示させる機能を実装中です。
react-native-admob-native-adsの設定をAndroidの設定手順に沿って実施しました。
設定後、npx react-native run-androidでAndroidアプリを起動すると、以下のビルドエラーが出ており、解決ができません。

発生している問題・エラーメッセージ

FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * Where: Build file '/Users/xxx.yyy/project/react-native-tutorial/node_modules/react-native-admob-native-ads/android/build.gradle' line: 31 * What went wrong: A problem occurred evaluating project ':react-native-admob-native-ads'. > Plugin with id 'maven' not found. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: A problem occurred configuring project ':react-native-admob-native-ads'. > com.android.builder.errors.EvalIssueException: compileSdkVersion is not specified. Please add it to build.gradle * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. ============================================================================== * Get more help at https://help.gradle.org BUILD FAILED in 7s at makeError (/Users/xxx.yyy/project/react-native-tutorial/node_modules/execa/index.js:174:9) at /Users/xxx.yyy/project/react-native-tutorial/node_modules/execa/index.js:278:16 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async runOnAllDevices (/Users/txxx.yyy/project/react-native-tutorial/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5) at async Command.handleAction (/Users/xxx.yyy/project/react-native-tutorial/node_modules/@react-native-community/cli/build/index.js:192:9)

該当のソースコード

androidフォルダ配下のandroid/build.gradleは以下です。

gradle

1// Top-level build file where you can add configuration options common to all sub-projects/modules. 2 3buildscript { 4 ext { 5 buildToolsVersion = "30.0.2" 6 minSdkVersion = 21 7 compileSdkVersion = 30 8 targetSdkVersion = 30 9 ndkVersion = "21.4.7075529" 10 } 11 repositories { 12 google() 13 mavenCentral() 14 } 15 dependencies { 16 classpath("com.android.tools.build:gradle:4.2.2") 17 // NOTE: Do not place your application dependencies here; they belong 18 // in the individual module build.gradle files 19 } 20} 21 22allprojects { 23 repositories { 24 maven { 25 // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 26 url("$rootDir/../node_modules/react-native/android") 27 } 28 maven { 29 // Android JSC is installed from npm 30 url("$rootDir/../node_modules/jsc-android/dist") 31 } 32 mavenCentral { 33 // We don't want to fetch react-native from Maven Central as there are 34 // older versions over there. 35 content { 36 excludeGroup "com.facebook.react" 37 } 38 } 39 google() 40 mavenCentral() // ☆追加 41 maven { url 'https://www.jitpack.io' } 42 jcenter() { 43 content { 44 includeModule("com.yqritc", "android-scalablevideoview") 45 } 46 } 47 } 48}

appフォルダ配下のbuild.gradleは以下です。

gradle

1apply plugin: "com.android.application" 2 3import com.android.build.OutputFile 4 5project.ext.react = [ 6 enableHermes: false, // clean and rebuild if changing 7] 8 9apply from: "../../node_modules/react-native/react.gradle" 10 11def enableSeparateBuildPerCPUArchitecture = false 12 13def enableProguardInReleaseBuilds = false 14 15def jscFlavor = 'org.webkit:android-jsc:+' 16 17def enableHermes = project.ext.react.get("enableHermes", false); 18 19def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures") 20 21android { 22 ndkVersion rootProject.ext.ndkVersion 23 24 compileSdkVersion rootProject.ext.compileSdkVersion 25 26 defaultConfig { 27 applicationId "com.awesomeproject" 28 minSdkVersion rootProject.ext.minSdkVersion 29 targetSdkVersion rootProject.ext.targetSdkVersion 30 versionCode 1 31 versionName "1.0" 32 } 33 splits { 34 abi { 35 reset() 36 enable enableSeparateBuildPerCPUArchitecture 37 universalApk false // If true, also generate a universal APK 38 include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 39 } 40 } 41 signingConfigs { 42 debug { 43 storeFile file('debug.keystore') 44 storePassword 'android' 45 keyAlias 'androiddebugkey' 46 keyPassword 'android' 47 } 48 } 49 buildTypes { 50 debug { 51 signingConfig signingConfigs.debug 52 if (nativeArchitectures) { 53 ndk { 54 abiFilters nativeArchitectures.split(',') 55 } 56 } 57 } 58 release { 59 // Caution! In production, you need to generate your own keystore file. 60 // see https://reactnative.dev/docs/signed-apk-android. 61 signingConfig signingConfigs.debug 62 minifyEnabled enableProguardInReleaseBuilds 63 proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 64 } 65 } 66 67 // applicationVariants are e.g. debug, release 68 applicationVariants.all { variant -> 69 variant.outputs.each { output -> 70 // For each separate APK per architecture, set a unique version code as described here: 71 // https://developer.android.com/studio/build/configure-apk-splits.html 72 // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. 73 def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 74 def abi = output.getFilter(OutputFile.ABI) 75 if (abi != null) { // null for the universal-debug, universal-release variants 76 output.versionCodeOverride = 77 defaultConfig.versionCode * 1000 + versionCodes.get(abi) 78 } 79 80 } 81 } 82} 83 84dependencies { 85 implementation fileTree(dir: "libs", include: ["*.jar"]) 86 //noinspection GradleDynamicVersion 87 implementation "com.facebook.react:react-native:+" // From node_modules 88 89 implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" 90 91 implementation 'com.google.android.gms:play-services-ads:20.5.0' 92 93 debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") { 94 exclude group:'com.facebook.fbjni' 95 } 96 97 debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") { 98 exclude group:'com.facebook.flipper' 99 exclude group:'com.squareup.okhttp3', module:'okhttp' 100 } 101 102 debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") { 103 exclude group:'com.facebook.flipper' 104 } 105 106 if (enableHermes) { 107 def hermesPath = "../../node_modules/hermes-engine/android/"; 108 debugImplementation files(hermesPath + "hermes-debug.aar") 109 releaseImplementation files(hermesPath + "hermes-release.aar") 110 } else { 111 implementation jscFlavor 112 } 113} 114 115// Run this once to be able to run the application with BUCK 116// puts all compile dependencies into folder libs for BUCK to use 117task copyDownloadableDepsToLibs(type: Copy) { 118 from configurations.implementation 119 into 'libs' 120} 121 122apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

AndroidManifest.xmlは以下です。

xml

1<manifest xmlns:android="http://schemas.android.com/apk/res/android" 2 package="com.awesomeproject"> 3 4 <uses-permission android:name="android.permission.INTERNET" /> 5 6 <application 7 android:name=".MainApplication" 8 android:label="@string/app_name" 9 android:icon="@mipmap/ic_launcher" 10 android:roundIcon="@mipmap/ic_launcher_round" 11 android:allowBackup="false" 12 android:theme="@style/AppTheme"> 13 <meta-data 14 android:name="com.google.android.gms.ads.APPLICATION_ID" // ☆追加 15 android:value="ca-app-pub-xxxxxxxxx-yyyyyyyyy"/> // ☆追加 16 17 <activity 18 android:name=".MainActivity" 19 android:label="@string/app_name" 20 android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" 21 android:launchMode="singleTask" 22 android:screenOrientation="portrait" 23 android:windowSoftInputMode="adjustResize"> 24 <intent-filter> 25 <action android:name="android.intent.action.MAIN" /> 26 <category android:name="android.intent.category.LAUNCHER" /> 27 </intent-filter> 28 </activity> 29 </application> 30</manifest>

試したこと

  • compileSdkVersion is not specified. Please add it to build.gradleのエラーが出ていたので、gradleファイルにcompileSdkVersionが定義されているかを確認しました。上記のソースにある通り定義されていました。
  • ネットで検索しましたが、有益な解決方法がありませんでした。

補足情報(FW/ツールのバージョンなど)

  • "react-native-admob-native-ads": "^0.5.0"
  • "react-native": "0.67.2"

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.30%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問