expo: Clean expo init & prebuild can not build in Android Studio

Summary

Trying to init a new project and then prebuild it to access native code seems impossible. I want to run gradle tasks or open the project in Android Studio but seem to stumble on 2 failures:

> Configure project :app
Unable to detect AGP versions for included builds. All projects in the build should use the same AGP version. Class name for the included build object: org.gradle.composite.internal.DefaultIncludedBuild$IncludedBuildImpl_Decorated.

> Configure project :expo

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/Users/thibault.maekelbergh/Downloads/temp/node_modules/expo/android/build.gradle' line: 9

* What went wrong:
A problem occurred evaluating project ':expo'.
> Cannot invoke method multiply() on null object

* 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.
-----------
* Where:
Build file '/Users/thibault.maekelbergh/Downloads/temp/node_modules/expo/android/build.gradle' line: 79

* What went wrong:
A problem occurred configuring project ':expo'.
> Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.

What platform(s) does this occur on?

Android

SDK Version

45

Environment

  expo-env-info 1.0.4 environment info:
    System:
      OS: macOS 12.3.1
      Shell: 5.9 - /usr/local/bin/zsh
    Binaries:
      Node: 16.13.2 - ~/.asdf/installs/nodejs/16.13.2/bin/node
      Yarn: 1.22.19 - ~/.yarn/bin/yarn
      npm: 8.1.2 - ~/.asdf/plugins/nodejs/shims/npm
      Watchman: 2022.06.27.00 - /usr/local/bin/watchman
    Managers:
      CocoaPods: 1.11.2 - /Users/thibault.maekelbergh/.asdf/shims/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5
      Android SDK:
        API Levels: 23, 26, 27, 28, 29, 30, 31
        Build Tools: 28.0.3, 29.0.0, 29.0.2, 29.0.3, 30.0.2
        System Images: android-24 | Intel x86 Atom_64, android-28 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom_64
        Android NDK: 20.1.5948944
    IDEs:
      Android Studio: 2021.2 AI-212.5712.43.2112.8512546
      Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild
    npmPackages:
      expo: ~45.0.0 => 45.0.6
      react: 17.0.2 => 17.0.2
      react-dom: 17.0.2 => 17.0.2
      react-native: 0.68.2 => 0.68.2
      react-native-web: 0.17.7 => 0.17.7
    npmGlobalPackages:
      eas-cli: 0.47.0
      expo-cli: 5.4.12
    Expo Workflow: bare

I use Java via asdf, tried with zulu-11.56.19, zulu-11.54.25, temurin-17.0.2+8 and updated the Android Studio Gradle JDK path accordingly each time.

Reproducible demo

Create new project:

$ expo init -t expo-template-blank-typescript . --npm
$ expo prebuild

Any of these trigger the errors:

  • Run expo run:android
  • Open in Android Studio (open -a Android\ Studio ./android) and running a Gradle sync
  • Or try: cd android && ./gradlew clean

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 8
  • Comments: 44 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@brentvatne it is working after I restart my laptop without changing anything. 🎉

weird, but it works now 😅

Temporary fix is to add the reactNativeVersion property to your project build.gradle file. For example beneath the compileSdkVersion.

buildscript {
    ext {
        androidXVersion = "1.2.0"
        buildToolsVersion = "31.0.0"
        compileSdkVersion = 31
        reactNativeVersion = "0.69.4" // https://github.com/expo/expo/issues/18129
    }
}

Confirmed that this workaround works for now. This shouldn’t really be necessary however, Expo should be able to figure out the react-native version by the package.json or similar

This also worked for me (but with 0.68.2). Thanks, was struggling for some hours already.

This workaround worked for me, but I didn’t like the idea of hardcoding the value, so I came up with this!

buildscript {
    ext.getPackageJsonVersion = { packageName ->
         new File(['node', '--print', "JSON.parse(require('fs').readFileSync(require.resolve('${packageName}/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
    }
    ext {
        reactNativeVersion = "${ext.getPackageJsonVersion('react-native')}"
        expoPackageVersion = "${ext.getPackageJsonVersion('expo')}"
    }
}

Temporary fix is to add the reactNativeVersion property to your project build.gradle file. For example beneath the compileSdkVersion.

buildscript {
    ext {
        androidXVersion = "1.2.0"
        buildToolsVersion = "31.0.0"
        compileSdkVersion = 31
        reactNativeVersion = "0.69.4" // https://github.com/expo/expo/issues/18129
    }
}

I am having similar issue with expo 48

> Configure project :expo-modules-core
WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.

> Configure project :expo
WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.

FAILURE: Build failed with an exception.

* Where:
Script 'E:\Projects\NovelManager\NovelManager.app\node_modules\expo-modules-autolinking\scripts\android\autolinking_implementation.gradle' line: 273

* What went wrong:
A problem occurred evaluating project ':expo'.
> A problem occurred configuring project ':expo-modules-core'.
   > Failed to notify project evaluation listener.
      > The filename, directory name, or volume label syntax is incorrect
      > Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.


tried all the above solution and nothing works

Temporary fix is to add the reactNativeVersion property to your project build.gradle file. For example beneath the compileSdkVersion.

buildscript {
    ext {
        androidXVersion = "1.2.0"
        buildToolsVersion = "31.0.0"
        compileSdkVersion = 31
        reactNativeVersion = "0.69.4" // https://github.com/expo/expo/issues/18129
    }
}

Confirmed that this workaround works for now. This shouldn’t really be necessary however, Expo should be able to figure out the react-native version by the package.json or similar

This also worked for me (but with 0.68.2). Thanks, was struggling for some hours already.

Temporary fix is to add the reactNativeVersion property to your project build.gradle file. For example beneath the compileSdkVersion.

buildscript {
    ext {
        androidXVersion = "1.2.0"
        buildToolsVersion = "31.0.0"
        compileSdkVersion = 31
        reactNativeVersion = "0.69.4" // https://github.com/expo/expo/issues/18129
    }
}

Confirmed that this workaround works for now. This shouldn’t really be necessary however, Expo should be able to figure out the react-native version by the package.json or similar

This also worked for me (but with 0.68.2). Thanks, was struggling for some hours already.

This workaround worked for me, but I didn’t like the idea of hardcoding the value, so I came up with this!

buildscript {
    ext.getPackageJsonVersion = { packageName ->
         new File(['node', '--print', "JSON.parse(require('fs').readFileSync(require.resolve('${packageName}/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
    }
    ext {
        reactNativeVersion = "${ext.getPackageJsonVersion('react-native')}"
        expoPackageVersion = "${ext.getPackageJsonVersion('expo')}"
    }
}

This worked for me perfectly! Thank you.

Using expo@47.0.12 and react-native@0.70.5

Temporary fix is to add the reactNativeVersion property to your project build.gradle file. For example beneath the compileSdkVersion.

buildscript {
    ext {
        androidXVersion = "1.2.0"
        buildToolsVersion = "31.0.0"
        compileSdkVersion = 31
        reactNativeVersion = "0.69.4" // https://github.com/expo/expo/issues/18129
    }
}

Confirmed that this workaround works for now. This shouldn’t really be necessary however, Expo should be able to figure out the react-native version by the package.json or similar

@thibmaek it’s strange. let’s investigate what happens to the node command execution first. could you apply the patch to node_modules/expo/android/build.gradle? if there’s command execution errors, gradle should throw a GradleException and let you know the error message.