Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 28463

React native Android App wont't build and displays the following error

$
0
0

PFA image for reference.

Screenshot Real Device

  • One Plus 6
  • Oxygen OS

My app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js",
    bundleInRelease: true,
    enableHermes: true,
]

apply from: "../../node_modules/react-native/react.gradle"

def enableSeparateBuildPerCPUArchitecture = true

def enableProguardInReleaseBuilds = true

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

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

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions { 
        checkReleaseBuilds false
    }

    defaultConfig {
        applicationId "com.****.**"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 206
        versionName "2.1"
        multiDexEnabled true
        missingDimensionStrategy 'react-native-camera', 'general'

    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {            
            // minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
            // shrinkResources true
            zipAlignEnabled true
            useProguard enableProguardInReleaseBuilds
        }

        // applicationVariants are e.g. debug, release
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                // For each separate APK per architecture, set a unique version code as described here:
                // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
                def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
                def abi = output.getFilter(OutputFile.ABI)
                if (abi != null) {  // null for the universal-debug, universal-release variants
                    output.versionCodeOverride =
                            versionCodes.get(abi) * 1048600 + defaultConfig.versionCode
                }
            }
        }
    }

    packagingOptions {
        pickFirst '**/armeabi-v7a/libc++_shared.so'
        pickFirst '**/x86/libc++_shared.so'
        pickFirst '**/arm64-v8a/libc++_shared.so'
        pickFirst '**/x86_64/libc++_shared.so'
        pickFirst '**/x86/libjsc.so'
        pickFirst '**/armeabi-v7a/libjsc.so'        
    }

}

dependencies {
    implementation project(':react-native-splash-screen')
    implementation project(':@react-native-community_async-storage')
    implementation project(':react-native-gesture-handler')
    implementation project(':@react-native-community_netinfo')
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.annotation:annotation:1.0.2'
    implementation fileTree(include: ['*.jar'], dir: 'libs')   
    implementation 'com.facebook.react:react-native:+'
    implementation 'com.android.support:multidex:1.0.1'

    // JSC from node_modules
   if (enableHermes) {
      def hermesPath = "../../node_modules/hermesvm/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")    
    } else {
        implementation jscFlavor
    }

    // From node_modules
    implementation 'com.google.android.gms:play-services-auth-api-phone:16.0.0'
    implementation 'com.google.android.gms:play-services-identity:16.0.0'
    implementation 'com.google.android.gms:play-services-auth:16.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    // Firebase dependencies
    implementation project(':react-native-firebase')
    implementation "com.google.android.gms:play-services-base:17.0.0"

    implementation "com.google.firebase:firebase-core:17.0.0"
    implementation "com.google.firebase:firebase-messaging:19.0.0"

    implementation project(':@mauron85_react-native-background-geolocation')
    implementation(project(':react-native-maps')){
       exclude group: 'com.google.android.gms', module: 'play-services-base'
       exclude group: 'com.google.android.gms', module: 'play-services-maps'
   }

}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

apply plugin: 'com.google.gms.google-services'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

My Top Level build.gradle file


buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 28
        supportLibVersion = "28.0.0"
        googlePlayServicesVersion = "11+"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.4.1")
        classpath 'com.google.gms:google-services:4.2.0'

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

allprojects {
    repositories {
        mavenLocal()
        google()
        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")
        }

    }
}

/*
To resolve the gradle dependency issue
*/
subprojects {
    afterEvaluate {
        project ->
            if (project.hasProperty("android")) {
            android {
            compileSdkVersion = 28
            buildToolsVersion = "28.0.3"
            }
        }
    }
}
subprojects {
  project.configurations.all {
     resolutionStrategy.eachDependency { details ->
        if (details.requested.group == 'com.android.support'&& !details.requested.name.contains('multidex') ) {
           details.useVersion "28.0.3"
        }
     }
  }
}

My package.json dependencies

"dependencies": {
    "@mauron85/react-native-background-geolocation": "^0.6.3",
    "@react-native-community/async-storage": "^1.5.1",
    "@react-native-community/geolocation": "^2.0.2",
    "@react-native-community/netinfo": "^3.2.1",
    "@types/react-native-vector-icons": "^6.4.2",
    "@typescript-eslint/eslint-plugin": "^2.2.0",
    "@typescript-eslint/parser": "^2.2.0",
    "buffer": "^5.2.1",
    "d3-shape": "^1.3.5",
    "deepmerge": "^3.2.0",
    "lottie-react-native": "^3.1.0",
    "moment": "^2.24.0",
    "object-path": "^0.11.4",
    "prop-types": "^15.7.2",
    "query-string": "^6.5.0",
    "react": "16.8.6",
    "react-native": "0.60.5",
    "react-native-android-location-services-dialog-box": "^2.8.2",
    "react-native-camera": "^3.0.0",
    "react-native-cli": "^2.0.1",
    "react-native-copilot": "^2.4.5",
    "react-native-datepicker": "^1.7.2",
    "react-native-device-info": "1.6.1",
    "react-native-document-picker": "^2.2.0",
    "react-native-elements": "^1.1.0",
    "react-native-exit-app": "^1.0.0",
    "react-native-fetch-blob": "^0.10.8",
    "react-native-firebase": "~5.5.6",
    "react-native-fs": "^2.13.3",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-google-signin": "^2.0.0",
    "react-native-image-picker": "^0.28.0",
    "react-native-image-resizer": "^1.0.1",
    "react-native-image-zoom-viewer": "^2.2.25",
    "react-native-linear-gradient": "^2.5.4",
    "react-native-loader": "^1.2.1",
    "react-native-loading-spinner-overlay": "^1.0.1",
    "react-native-maps": "^0.26.1",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-permissions": "^1.1.1",
    "react-native-picker-select": "^6.1.0",
    "react-native-privacy-snapshot": "^1.0.0",
    "react-native-qrcode-scanner": "^1.2.1",
    "react-native-shared-preferences": "^1.0.0",
    "react-native-simple-toast": "0.0.8",
    "react-native-snackbar": "^2.0.2",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^9.4.0",
    "react-native-user-defaults": "^0.1.5",
    "react-native-vector-icons": "^6.6.0",
    "react-native-webview": "^5.12.1",
    "react-redux": "^5.0.6",
    "react-roka-components": "^1.0.1",
    "redux": "^3.0.0",
    "redux-devtools-extension": "^2.13.8",
    "redux-form": "^7.4.2",
    "url": "^0.11.0",
    "url-parse": "^1.4.7",
    "uuid": "^3.3.2",
    "whatwg-fetch": "^2.0.4"
  },

Steps taken to resolve :

1) Tried using the same version of dependencies (17.0.0) for "com.google.firebase:firebase-core" and "com.google.firebase:firebase-messaging" as suggested in the below link.

No class Def Error

But the gradle build failed with the following error

CONFIGURE FAILED in 1m 0s In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[16.0.0]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

Dependency failing: com.google.firebase:firebase-messaging:17.0.0 -> com.google.firebase:firebase-iid@[16.0.0], but firebase-iid version was 19.0.0.

The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the artifact with the issue.

-- Project 'app' depends onto com.google.firebase:firebase-messaging@{strictly 17.0.0}

-- Project 'app' depends onto com.google.firebase:firebase-iid@{strictly 19.0.0}


Viewing all articles
Browse latest Browse all 28463

Trending Articles