Build fails with react-native-google-mobile-ads

Hello,

You recommend to use react-native-google-mobile-ads instead of expo-ads-admob. I havn’t found any documentation about its use with Expo, so I’ve read related threads and tried to follow the instructions. Unfortunately, the EAS build fails.

Here is my process:

  • yarn add react-native-google-mobile-ads
  • add adMob keys to app.json :
"react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-blabla",
    "ios_app_id": "ca-app-pub-blabla"
  }
  • run eas build --platform android --profile development --local

The build fails. The log is:

[RUN_GRADLEW] FAILURE: Build failed with an exception.
[RUN_GRADLEW] * What went wrong:
[RUN_GRADLEW] Execution failed for task ':app:checkDebugAarMetadata'.
[RUN_GRADLEW] > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
[RUN_GRADLEW]    > The minCompileSdk (31) specified in a
[RUN_GRADLEW]      dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
[RUN_GRADLEW]      is greater than this module's compileSdkVersion (android-30).
[RUN_GRADLEW]      Dependency: androidx.work:work-runtime:2.7.0.
[RUN_GRADLEW]      AAR metadata file: /Users/antoine/.gradle/caches/transforms-3/ffee51ff6db99f884b0e8a6a5d65a88b/transformed/work-runtime-2.7.0/META-INF/com/android/build/gradle/aar-metadata.properties.
[RUN_GRADLEW] * Try:
[RUN_GRADLEW] 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.
[RUN_GRADLEW] * Get more help at https://help.gradle.org
[RUN_GRADLEW] Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
[RUN_GRADLEW] Use '--warning-mode all' to show the individual deprecation warnings.
[RUN_GRADLEW] See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
[RUN_GRADLEW] 72 actionable tasks: 72 executed
[RUN_GRADLEW] BUILD FAILED in 11s
[RUN_GRADLEW] Error: Gradle build failed with unknown error. Please see logs for the "Run gradlew" phase.

Build failed
Gradle build failed with unknown error. Please see logs for the "Run gradlew" phase.
    Error: npx exited with non-zero code: 1

So, it seems I must use an Android SDK equal or greater than 31. I made sure I’ve installed it on my machine. When running android list target I have:

Available Android targets:
----------
id: 1 or "android-29"
     Name: Android API 29
     Type: Platform
     API level: 29
     Revision: 4
----------
id: 2 or "android-30"
     Name: Android API 30
     Type: Platform
     API level: 30
     Revision: 3
----------
id: 3 or "android-31"
     Name: Android API 31
     Type: Platform
     API level: 31
     Revision: 1

But the build keeps failing over and over again.

Same thing in the cloud by running eas build:

> Task :react-native-google-mobile-ads:preBuild UP-TO-DATE
108
> Task :react-native-google-mobile-ads:preReleaseBuild UP-TO-DATE
109
> Task :react-native-google-mobile-ads:compileReleaseAidl NO-SOURCE

Task :react-native-google-mobile-ads:packageReleaseRenderscript NO-SOURCE
Task :react-native-google-mobile-ads:writeReleaseAarMetadata

> Task :app:checkReleaseAarMetadata FAILED
166
[stderr] FAILURE: Build failed with an exception.
167
[stderr] * What went wrong:
168
[stderr] Execution failed for task ':app:checkReleaseAarMetadata'.
169
[stderr] > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
170
[stderr]    > The minCompileSdk (31) specified in a
171
[stderr]      dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
172
[stderr]      is greater than this module's compileSdkVersion (android-30).
173
[stderr]      Dependency: androidx.work:work-runtime:2.7.0.
174
[stderr]      AAR metadata file: /home/expo/.gradle/caches/transforms-3/ffee51ff6db99f884b0e8a6a5d65a88b/transformed/work-runtime-2.7.0/META-INF/com/android/build/gradle/aar-metadata.properties.
175
[stderr] * Try:
176
[stderr] 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.

How to fix this?

Also, once the build is done, is there a special process to follow? I’ve read I must install expo-dev-client and run expo start --dev-client to display the app in an android simulator and add the ads. Once I’m happy with the result, I must simply run eas build again to get the build ready to be sent to stores, right?

Should this library didn’t work, can I still use expo-ads-admob and expect it to work properly with eas build?

Thank you!

Information

  • managed workflow (but will be bare once react-native-google-mobile-ads is installed)
  • eas-cli version: 5.4.7
  • sdk version: 44.0.0

Hi @donedeal0

The last part of that is not necessarily true :slight_smile: These days it’s not necessary to use the bare workflow just because you want to use something like react-native-google-mobile-ads.

You might have more luck with Expo SDK 45, which uses compileSdkVersion 31 by default.

Also, see if the following thread helps:

1 Like

Yes, thanks, I had Expo 44 and an older Java version… Everything works fine now, thanks!

1 Like