skip to Main Content

I am facing issue with the build in React Native. Unable to proceed further and no solution being found anywhere. Here is my build.gradle file

import org.apache.tools.ant.taskdefs.condition.Os


buildscript {
ext {
    buildToolsVersion = "31.0.0"
    minSdkVersion = 21
    compileSdkVersion = 31
    targetSdkVersion = 31 
    kotlinVersion = "1.5.31"


    if (findProperty('android.kotlinVersion')) {
        kotlinVersion = findProperty('android.kotlinVersion')
    }
    frescoVersion = findProperty('expo.frescoVersion') ?: '2.5.0'

    if (System.properties['os.arch'] == 'aarch64') {
        
        ndkVersion = '24.0.8215888'
    } else {
        
        ndkVersion = '21.4.7075529'
    }
}
repositories {
    google()
    mavenCentral()
}
dependencies {
    classpath('com.android.tools.build:gradle:7.3.0')
    classpath('com.facebook.react:react-native-gradle-plugin')
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    classpath('de.undercouch:gradle-download-task:4.1.2')
    classpath 'com.google.gms:google-services:4.3.13'
    
}}
allprojects {
repositories {
    mavenLocal()
    maven {
        
        url(new File(['node', '--print', "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), '../android'))
    }
    maven {
       
        url(new File(['node', '--print', "require.resolve('jsc-android/package.json')"].execute(null, rootDir).text.trim(), '../dist'))
    }

    google()
    mavenCentral {
       
        content {
            excludeGroup 'com.facebook.react'
        }
    }
    maven { url 'https://www.jitpack.io' }
    maven { url 'https://jcenter.bintray.com' }
}}

and my app/build.gradle is :

apply plugin: "com.android.application"

apply plugin: 'com.google.gms.google-services'

import com.android.build.OutputFile
import org.apache.tools.ant.taskdefs.condition.Os

def projectRoot = rootDir.getAbsoluteFile().getParentFile().getAbsolutePath()

project.ext.react = [
entryFile: ["node", "-e", "require('expo/scripts/resolveAppEntry')", projectRoot, "android"].execute(null, rootDir).text.trim(),
enableHermes: (findProperty('expo.jsEngine') ?: "jsc") == "hermes",
cliPath: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/cli.js",
hermesCommand: new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/%OS-BIN%/hermesc",
composeSourceMapsPath: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/scripts/compose-source-maps.js",]

apply from: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../react.gradle")

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: false).toBoolean()

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]}

android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
    applicationId 'xxx.xxxx.xxxx'
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0.0"
    buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()

    if (isNewArchitectureEnabled()) {
        externalNativeBuild {
            ndkBuild {
                arguments "APP_PLATFORM=android-21",
                    "APP_STL=c++_shared",
                    "NDK_TOOLCHAIN_VERSION=clang",
                    "GENERATED_SRC_DIR=$buildDir/generated/source",
                    "PROJECT_BUILD_DIR=$buildDir",
                    "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
                    "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
                cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
                cppFlags "-std=c++17"
               
                targets "baseapp_appmodules"
                if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                    arguments "NDK_APP_SHORT_COMMANDS=true"
                }
            }
        }
        if (!enableSeparateBuildPerCPUArchitecture) {
            ndk {
                abiFilters (*reactNativeArchitectures())
            }
        }
    }
}

if (isNewArchitectureEnabled()) {
    externalNativeBuild {
        ndkBuild {
            path "$projectDir/src/main/jni/Android.mk"
        }
    }
    def reactAndroidProjectDir = project(':ReactAndroid').projectDir
    def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
        dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
        from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
        into("$buildDir/react-ndk/exported")
    }
    def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
        dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
        from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
        into("$buildDir/react-ndk/exported")
    }
    afterEvaluate {
        
        preDebugBuild.dependsOn(packageReactNdkDebugLibs)
        preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)

        configureNdkBuildRelease.dependsOn(preReleaseBuild)
        configureNdkBuildDebug.dependsOn(preDebugBuild)
        reactNativeArchitectures().each { architecture ->
            tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
                dependsOn("preDebugBuild")
            }
            tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
                dependsOn("preReleaseBuild")
            }
        }
    }
}

splits {
    abi {
        reset()
        enable enableSeparateBuildPerCPUArchitecture
        universalApk false  
        include (*reactNativeArchitectures())
    }
}
signingConfigs {
    debug {
        storeFile file('debug.keystore')
        storePassword 'android'
        keyAlias 'androiddebugkey'
        keyPassword 'android'
    }
    release {
        if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
            storeFile file(MYAPP_UPLOAD_STORE_FILE)
            storePassword MYAPP_UPLOAD_STORE_PASSWORD
            keyAlias MYAPP_UPLOAD_KEY_ALIAS
            keyPassword MYAPP_UPLOAD_KEY_PASSWORD
        }
    }
}
buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        
        signingConfig signingConfigs.release
        minifyEnabled enableProguardInReleaseBuilds
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        
        def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
        def abi = output.getFilter(OutputFile.ABI)
        if (abi != null) {  
            output.versionCodeOverride =
                    versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
        }

    }
}}

["pickFirsts", "excludes", "merges", "doNotStrip"].each { prop ->
// Split option: 'foo,bar' -> ['foo', 'bar']
def options = (findProperty("android.packagingOptions.$prop") ?: "").split(",");
// Trim all elements in place.
for (i in 0..<options.size()) options[i] = options[i].trim();
// `[] - ""` is essentially `[""].filter(Boolean)` removing all empty strings.
options -= ""

if (options.length > 0) {
    println "android.packagingOptions.$prop += $options ($options.length)"
    options.each {
        android.packagingOptions[prop] += it
    }
}}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

implementation platform('com.google.firebase:firebase-bom:30.3.1')
implementation "com.facebook.react:react-native:+"  // From node_modules
implementation 'com.twitter.sdk.android:twitter-core:3.2.0'
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation 'com.google.firebase:firebase-analytics'

def isGifEnabled = (findProperty('expo.gif.enabled') ?: "") == "true";
def isWebpEnabled = (findProperty('expo.webp.enabled') ?: "") == "true";
def isWebpAnimatedEnabled = (findProperty('expo.webp.animated') ?: "") == "true";
def frescoVersion = rootProject.ext.frescoVersion

if (isGifEnabled || isWebpEnabled) {
    implementation "com.facebook.fresco:fresco:${frescoVersion}"
    implementation "com.facebook.fresco:imagepipeline-okhttp3:${frescoVersion}"
}

if (isGifEnabled) {
    implementation "com.facebook.fresco:animated-gif:${frescoVersion}"
}

if (isWebpEnabled) {
    implementation "com.facebook.fresco:webpsupport:${frescoVersion}"
    if (isWebpAnimatedEnabled) {
        implementation "com.facebook.fresco:animated-webp:${frescoVersion}"
    }
}

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.flipper'
    exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
    exclude group:'com.facebook.flipper'
}

if (enableHermes) {
    debugImplementation files(new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim(), "../android/hermes-debug.aar"))
    releaseImplementation files(new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute(null, rootDir).text.trim(), "../android/hermes-release.aar"))
} else {
    implementation jscFlavor
}}

if (isNewArchitectureEnabled()) {
configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute(module("com.facebook.react:react-native"))
                .using(project(":ReactAndroid")).because("On New Architecture we're building React Native from source")
    }
}}

task copyDownloadableDepsToLibs(type: Copy) {
from configurations.implementation
into 'libs'}

apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
applyNativeModulesAppBuildGradle(project)

def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"}

With these files, Im getting error with the AbsolutePath() error and compileSDKVersion not specified error. Can any explain the issue and the resolution for the same. The error goes as follows:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.

-----------
* Where:
Build file '/Users/XXXX/Documents/baseappcode/android/app/build.gradle' line: 88

* What went wrong:
A problem occurred evaluating project ':app'.
> Cannot invoke method getAbsolutePath() 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.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> 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 14s
5 actionable tasks: 5 up-to-date

2

Answers


  1. Looks like you upgraded your react version and missed to remove some code? Your project.ext.react in app/build.gradle should look like this:

    project.ext.react = [
        enableHermes: false,  // clean and rebuild if changing
    ]
    

    All code including getAbsolutePath must be removed. Use upgrade helper to compare your code.

    Login or Signup to reply.
  2. I got rid off this by upgrading Expo and later on following the guide to upgrade React Native https://react-native-community.github.io/upgrade-helper/?from=0.64.4&to=0.70.5

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search