react-native: Build error "Could not get unknown property 'preDebugBuild' for extension 'android'"

New Version

0.68.0

Old Version

0.67.3

Build Target(s)

android

Output of react-native info

System:
    OS: macOS 12.2.1
    CPU: (8) arm64 Apple M1
    Memory: 775.20 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.10.0 - /opt/homebrew/bin/node
    Yarn: 1.22.15 - ~/.yarn/bin/yarn
    npm: 7.24.0 - /opt/homebrew/bin/npm
    Watchman: 2021.09.27.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.2 - /opt/homebrew/bin/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, 29, 30, 31
      Build Tools: 30.0.2, 30.0.3, 31.0.0
      System Images: android-31 | Google APIs ARM 64 v8a
      Android NDK: 21.4.7075529
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8309675
    Xcode: 13.3/13E113 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.12 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: Not Found
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Issue and Reproduction Steps

After the update, when I run yarn android with newArchitecture enabled, I got the following error :

FAILURE: Build failed with an exception.

  • Where: Build file ‘/Users/rvasseur/Desktop/LoungeUp/staffcompanion-rn/android/app/build.gradle’ line: 224

  • What went wrong: A problem occurred configuring project ‘:app’.

Could not get unknown property ‘preDebugBuild’ for extension ‘android’ of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 24 (3 by maintainers)

Most upvoted comments

Can someone here validate that my fix solves your issues too?

afterEvaluate {
    // If you wish to add a custom TurboModule or component locally,
    // you should uncomment this line.
    // preBuild.dependsOn("generateCodegenArtifactsFromSchema")
    android.applicationVariants.all { def variant ->
        def variantName = variant.name.capitalize()
        def preVariantBuildTask = tasks.findByName("pre${variantName}Build")

        // Due to a bug inside AGP, we have to explicitly set a dependency
        // between configureNdkBuild* tasks and the preBuild tasks.
        // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
        if (variantName.endsWith("Debug")) {
            preVariantBuildTask.dependsOn(packageReactNdkDebugLibs)
            configureNdkBuildDebug.dependsOn(preVariantBuildTask)
            reactNativeArchitectures().each { architecture ->
                tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
                    dependsOn(preVariantBuildTask.name)
                }
            }
        }
        if (variantName.endsWith("Release")) {
            preVariantBuildTask.dependsOn(packageReactNdkReleaseLibs)
            configureNdkBuildRelease.dependsOn(preVariantBuildTask)
            reactNativeArchitectures().each { architecture ->
                tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
                    dependsOn(preVariantBuildTask.name)
                }
            }
        }
    }
}

@oblador I’m getting below issue: Could not get unknown property ‘configureNdkBuildDebug’ for object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.

NDK version: 24.0.8215888 System: Apple M1 pro reactNativeArchitectures=x86_64 -> in gradle.properties.

I’m getting the same error too after upgrading from 0.67 -> 0.68 when newArchEnabled=true. But i was able to build it when newArchEnabled=false.

Looks like it’s caused by product flavours. We have “staging” and “production”, changing preDebugBuild to preStagingDebugBuild seems to work, ie inserting your flavour.

i am having the same issue & I tried @oblador fix but i got another error from it.

* What went wrong:
Could not determine the dependencies of task ':ReactAndroid:packageReactNdkDebugLibsForBuck'.
> Task with path 'mergeDebugNativeLibs' not found in project ':ReactAndroid'.

So I am grateful for any suggestions here.

Just a heads up that this has been fully fixed in RN 0.71. If you update version everything should work without extra scripts or patches needed.

@oblador I’m getting below issue: Could not get unknown property ‘configureNdkBuildDebug’ for object of type com.android.build.gradle.internal.api.ApplicationVariantImpl. NDK version: 24.0.8215888 System: Apple M1 pro reactNativeArchitectures=x86_64 -> in gradle.properties.

@oblador I am also facing same issue after applying your solution

I’m also getting the same error, any progress on this?

@oblador I’m getting below issue: Could not get unknown property ‘configureNdkBuildDebug’ for object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.

NDK version: 24.0.8215888 System: Apple M1 pro reactNativeArchitectures=x86_64 -> in gradle.properties.

@oblador I am also facing same issue after applying your solution