Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execution failed for task ':react-native-camera:compileDebugJavaWithJavac'

I am creating app using React-Native and testing it on Android device. After adding react-native-camera module, the following error occurs:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':react-native-camera:compileDebugJavaWithJavac'. at "Build->Run Tasks" (Android Studio).

Concerning the Java compiler, there are about 20-30 errors, all of which show the following: error: package android.support.annotation does not exist, error: package android.support.v4.util does not exist, error: package android.support.media does not exist, etc. OR error: cannot find symbol class SparseArrayCompat, error: package Pools does not exist, error: cannot find symbol variable ExifInterface, which when checked in the error file has to do with import android.support.v4.util.ArrayMap;-import kind of statements.

My android/build.gradle file:

buildscript {
    ext {
        minSdkVersion = 26
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = 28
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
    }
}

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        mavenLocal()
        jcenter()
        /*maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            //url "$rootDir/../node_modules/react-native/android"
            url "https://maven.google.com"
        }*/
        google()
    }
}

tasks.withType(Wrapper) {
    gradleVersion = "4.10.1"
    distributionUrl = distributionUrl.replace("bin", "all")
}

My app/build.gradle file:

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js"
]

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

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.helloworld"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation (project(':react-native-camera')) {
        exclude group: 'com.google.android.gms'
        exclude group: "com.android.support"
        implementation 'com.android.support:exifinterface:28.0.0'
        implementation ('com.google.android.gms:play-services-vision:12.0.1') {
            force = true
        }
    }
    implementation project(':react-native-orientation')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-linear-gradient')
    implementation project(':react-native-spinkit')
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation ('com.facebook.react:react-native:0.58.3')
    implementation "com.android.support:support-v4:28.0.0"
    //implementation "androidx.legacy:legacy-support-v4:1.0.0"
}

My attempt at solution:

  • I added android-support-v4.jar file to the ./libs folder.
  • I added "google()" or maven links to the dependencies.
  • I tried changing minSdkVersion, compileVersion, etc, didn't help, but I guess this might be the main problem.
  • Rebuilding the project didn't work too.
  • Migrating project to Android X.

My SDK version: 28

Gradle version: 4.10.1

classpath 'com.android.tools.build:gradle:3.3.1' (Downgrading gradle version to 3.1.0 didn't work).

like image 932

People also ask

How do I enable camera react native?

You just have to import the core React Native components such as View and Alert as well as RNCamera from react-native-camera . Then, create a class component App that is going to render the JSX that uses a hardware camera on the device's screen. This going to be done by wrapping the RNCamera component inside a View .

Can you use camera with react native?

React Native Camera is an incredible package to help developers use the device camera for iOS and Android apps built with React Native. Besides our example QR code scanner, you can also do text recognition, face detection, and capture video and images.


1 Answers

change the minsdk version and compilesdk version in react-native-camera build.gradle file with your app build gradle properties.

android/build.gradle

buildscript {
    ext {
      buildToolsVersion = "28.0.3"
      minSdkVersion = 16
      compileSdkVersion = 28
      targetSdkVersion = 28
      supportLibVersion = "28.0.0"
      googlePlayServicesVersion = "16.1.0" // or set latest version
      androidMapsUtilsVersion = "0.5+"
    }
}

react-native-camera/android/build.gradle

android {
   compileSdkVersion 28
   buildToolsVersion "28.0.3"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName computeVersionName()
}
lintOptions {
    abortOnError false
}
}
like image 103
Geetha Tulasi Balam Avatar answered Oct 17 '22 13:10

Geetha Tulasi Balam