3

I am using React Native:

npx react-native run-android

I have many other solutions. Like force or update the targetsdk version and compile the SDK version, but nothing worked.

I tried changing compileSdkVersion 30 to compileSdkVersion 31 and targetSdkVersion 30 to targetSdkVersion 31.

The issue

The minCompileSdk (31) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-30).

Dependency: androidx.appcompat:appcompat:1.4.1.

My buiild.gradle file

// Top-level build file where you can add configuration
// options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        ndkVersion = "21.4.7075529"
        firebaseMessagingVersion = "21.1.0"
        googlePlayServicesVisionVersion = "19.0.0"
        playServicesVersion = "17.0.0" // or find latest version
        androidMapsUtilsVersion = "2.2.5"
        kotlin_version = "1.5.0"
        androidXCore = "1.5.0"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        classpath('com.google.gms:google-services:4.3.2')

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        maven { url 'https://www.jitpack.io' }
    }
}
configurations.all {
    resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nahid Hasan
  • 687
  • 1
  • 10
  • 34
  • 3
    Does this answer your question? https://stackoverflow.com/questions/74334162/android-build-failure-common-issue-failed-to-install-the-app-error-command-f – Thanhal P A Nov 07 '22 at 07:43
  • 1
    Does this answer your question? [My React Native was working fine upto 4 November but now throwing an exception while Running yarn android](https://stackoverflow.com/questions/74370367/my-react-native-was-working-fine-upto-4-november-but-now-throwing-an-exception-w) – Thanhal P A Nov 09 '22 at 12:11
  • 2
    Please don't ask multiple questions in one post. If you've got a different error (not directly related to your existing question) ask another question. – Abdul Aziz Barkat Nov 27 '22 at 05:54
  • 1
    This post is getting discussed at meta: https://meta.stackoverflow.com/questions/421691/an-audit-failed-but-the-question-has-two-different-problems-in-it-one-resolved. – Lundin Nov 28 '22 at 10:58
  • The replication of the misspelling "buld.gradle" (of [build.gradle](https://docs.gradle.org/current/userguide/tutorial_using_tasks.html)) (probably from [the GitHub issue](https://github.com/facebook/react-native/issues/35210)) in answers (several) hints at mindless copy-paste. That ought to trigger plagiarism checks. – Peter Mortensen Nov 29 '22 at 13:02
  • Re *"My buiild.gradle file"*: Is the file name actually *`buiild.gradle`*? Not *[`build.gradle`](https://docs.gradle.org/current/userguide/tutorial_using_tasks.html)*? – Peter Mortensen Nov 29 '22 at 13:25
  • This is the subject of an associated audit referenced in [a meta question](https://meta.stackoverflow.com/questions/421691/). – Peter Mortensen Dec 15 '22 at 02:54

1 Answers1

13

That is because of an Android build issue since 2022-11-04. I have resolved that by adding a few lines of code based on the report.

You can add this in the allprojects area of your android/build.gradle file.

def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())

allprojects {
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }

In my case, I have added it under repositories. See below.

allprojects {
    repositories {
        google()
        mavenCentral()
    }
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
}

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
reggi49
  • 460
  • 3
  • 11