Search code examples
react-nativebuildexpoadmobeas

React Native Expo Android build failed: react-native-google-mobile-ads


I want to get a development build in my Expo application. Unfortunately, after upgrading Expo to version 49, I encountered these errors and couldn’t find a solution.

> Configure project :react-native-google-mobile-ads
:react-native-google-mobile-ads package.json found at /home/expo/workingdir/build/node_modules/react-native-google-mobile-ads/package.json
[stderr] 
FAILURE: Build completed with 2 failures.
[stderr] 
1:
[stderr] 
Task failed with an exception.
[stderr] 
-----------
[stderr] 
* Where:
[stderr] 
Build file '/home/expo/workingdir/build/node_modules/react-native-google-mobile-ads/android/build.gradle' line: 120
[stderr] 
* What went wrong:
[stderr] 
A problem occurred evaluating project ':react-native-google-mobile-ads'.
[stderr] 
> Cannot set the value of read-only property 'force' for DefaultExternalModuleDependency{group='com.google.android.gms', name='play-services-ads', version='21.4.0', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency.
[stderr] 
* Try:
[stderr] 
> Run with --stacktrace option to get the stack trace.
[stderr] 
> Run with
[stderr] 
--info
[stderr] 
or --debug option to get more log output.
[stderr] 
> Run with --scan to get full insights.
[stderr] 
==============================================================================
[stderr] 
2: Task failed with an exception.
[stderr] 
-----------
[stderr] 
* What went wrong:
[stderr] 
A problem occurred configuring project ':react-native-google-mobile-ads'.
[stderr] 
> compileSdkVersion is not specified. Please add it to build.gradle
[stderr] 
* Try:
[stderr] 
> Run with --stacktrace option to get the stack trace.
[stderr] 
> Run with --info or --debug option to get more log output.
[stderr] 
> Run with --scan to get full insights.
[stderr] 
==============================================================================
[stderr] 
* Get more help at https://help.gradle.org
[stderr] 
BUILD FAILED in 3m 23s
15 actionable tasks: 15 executed

package.json:

{
  "name": "zikirmatik",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@expo/config-plugins": "~7.2.2",
    "@expo/metro-config": "~0.10.0",
    "@expo/prebuild-config": "~6.2.4",
    "@react-native-async-storage/async-storage": "1.18.2",
    "@react-native-masked-view/masked-view": "0.2.9",
    "@react-native-picker/picker": "2.4.10",
    "@react-navigation/bottom-tabs": "^6.5.5",
    "@react-navigation/native": "^6.1.4",
    "@react-navigation/stack": "^6.3.14",
    "@reduxjs/toolkit": "^1.9.2",
    "expo": "^49.0.0",
    "expo-app-loading": "^2.1.1",
    "expo-av": "~13.4.1",
    "expo-build-properties": "~0.8.3",
    "expo-dev-client": "~2.4.10",
    "expo-device": "~5.4.0",
    "expo-font": "~11.4.0",
    "expo-linking": "~5.0.2",
    "expo-notifications": "~0.20.1",
    "expo-splash-screen": "~0.20.5",
    "expo-status-bar": "~1.6.0",
    "expo-store-review": "~6.4.0",
    "expo-updates": "~0.18.13",
    "firebase": "^9.17.2",
    "immer": "^9.0.19",
    "moment": "^2.29.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.72.4",
    "react-native-element-dropdown": "^1.8.2",
    "react-native-event-listeners": "^1.0.7",
    "react-native-gesture-handler": "~2.12.0",
    "react-native-google-mobile-ads": "^12.1.2",
    "react-native-paper": "^4.11.2",
    "react-native-responsive-screen": "^1.4.2",
    "react-native-safe-area-context": "4.6.3",
    "react-native-svg": "13.9.0",
    "react-native-web": "~0.19.6",
    "react-redux": "^8.0.5",
    "redux": "^4.2.1",
    "styled-components": "^5.3.3",
    "styled-system": "^5.1.5"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "resolutions": {
    "@expo/config-plugins": "^5.0.0"
  },
  "private": true
}

I tried to get a development build, but I encountered this error. This occurred after the Expo version update. I researched many methods, but I couldn't reach any solution. I couldn't determine whether it's related to the frequent updates or if it's a compatibility issue between the SDK and ads.


Solution

  • Moderator Wodin from Expo forum provided the following answers and it worked for me:

    Have a look at this: Troubleshoot build errors and crashes 3

    It’s worth looking through the whole thing, but a couple of things I want to highlight:

    Try running using a dev build with npx expo start --no-dev --minify. This behaves much closer to a production build than just npx expo start, so it might give you an idea of what’s wrong. Try running adb logcat -d to get the logs from the phone/emulator Search for “FATAL” If all else fails, try to see if you can use a bisection search to figure out what’s causing the problem. i.e. comment out half your code to see if it still crashes. If it does, chances are the problem is in the remaining half. If not, chances are the problem is in the part you commented out. Then comment out half of the “bad” code, etc. See also expo.fyi/manual-debugging

    Also:

      "dependencies": {
        "@expo/config-plugins": "~7.2.2",
    [...]
        "@expo/prebuild-config": "~6.2.4",
    [...]
      },
      "resolutions": {
        "@expo/config-plugins": "^5.0.0"
      },
    

    Why do you need these dependencies and resolutions? It might indicate that you’re using some incompatible dependencies.

    "expo-app-loading": "^2.1.1",
    

    As per the Expo SDK 45 release blog post 1:

    expo-app-loading is deprecated — use expo-splash-screen directly instead: SplashScreen.preventAutoHideAsync() and SplashScreen.hideAsync(). The implementation is only a thin wrapper around expo-splash-screen 1 that you can copy into your project if you’d like to keep using it. It was still there in Expo SDK 46, but was removed in Expo SDK 47.