teslamotors / react-native-camera-kit

A high performance, easy to use, rock solid camera library for React Native apps.
MIT License
2.46k stars 584 forks source link

Upgrade to Gradle Build Tools 3.3 causes "package R does not exist" #215

Closed booleanBoy closed 5 years ago

booleanBoy commented 5 years ago

Issue Description

Since upgrading Gradle build tools to 3.3.+, my previously working project is no longer building on Android with this error:

RNCameraKit\camera\barcode\BarcodeFrame.java:12: error: cannot find symbol import com.wix.RNCameraKit.R; ^ RNCameraKit\camera\barcode\BarcodeFrame.java:43: error: package R does not exist

From what I've read, problems with R not generating is a general Android issue, not a problem with RN Camera Kit, but I hoped someone else might have also experienced this problem and might be able to share a solution.

Steps to Reproduce / Code Snippets / Screenshots

None. A fresh project, with an install of RNCameraKit, upgraded to the same gradle version works.

Project build.gradle

buildscript {
    repositories {
        google()
        jcenter()        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.+'
        classpath 'com.google.gms:google-services:3.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 28
                buildToolsVersion "28.0.2"
            }
        }
    }
}

ext {
    compileSdkVersion           = 28       //Which compiler to use. Latest is 'always' best
    minimumSdkVersion           = 22       //Lowest allowable API version. 22 = 5.1/Lollipop. This is over 80% of users currently (Aug 18).
    targetSdkVersion            = 27       //High target is good, but as we move to a new compile Sdk we may not be ready to increase the target just yet, depending on the changes between versions
    buildToolsVersion           = "28.0.2" //Must match compile major version number 
    googlePlayServicesVersion   = "11.8.0" //Independent, I think
    supportLibVersion           = "28.0.0" //Must match compile major version number
}

App build.gradle

apply plugin: 'io.fabric'

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
    buildToolsVersion '28.0.2'

    defaultConfig {
        applicationId "ee.homefr.android"
        minSdkVersion 23
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 66
        versionName "0.7.6"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        vectorDrawables.useSupportLibrary = true
    }
    packagingOptions{
        doNotStrip '*/mips/*.so'
        doNotStrip '*/mips64/*.so'
    }

    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
        debug {
            versionNameSuffix "-dev"
        }
    }
    // 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]
            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
            }
        }
    }
    dexOptions {

        javaMaxHeapSize "8g"
    }
}
repositories {
    maven { url 'https://maven.fabric.io/public' }
}
dependencies {
    implementation project(":react-native-camera-kit")
    implementation project(':react-native-smart-splashscreen')
    implementation project(':react-native-share')
    implementation project(':react-native-text-input-mask')
    implementation project(':react-native-svg')
    implementation project(':rn-fetch-blob')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.5@aar') {
        transitive = true;
    }
    implementation 'com.android.support:appcompat-v7:27.+'
    implementation 'com.facebook.react:react-native:+'
    // From node_modules
    implementation project(':react-native-sensitive-info')
    implementation project(':react-native-image-crop-picker')
    implementation project(':react-native-fs')
    implementation project(':react-native-version-number')
    implementation(project(':react-native-push-notification')) {
        exclude group: 'com.google.android.gms'
    }
    implementation project(':react-native-fabric')
    // Firebase dependencies
    implementation(project(':react-native-firebase')) {
        transitive = false
    }
    implementation(project(':react-native-google-signin')) {
        exclude group: "com.google.android.gms"
    }
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
    implementation 'com.google.firebase:firebase-firestore:17.0.2'
    implementation 'com.google.android.gms:play-services-base:15.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation('com.google.android.gms:play-services-gcm:15.0.1') {
        force = true;
    }
    implementation 'com.google.code.gson:gson:2.8.2'
    // implementation project(':openCVLibrary341')
}

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }
    dependencies {
        classpath 'io.fabric.tools:gradle:1.25.4'
    }
}
// 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'

Environment

harishbelamkar commented 5 years ago

@booleanBoy : Did you got solution for the above ? Even i am getting same issue in react-native 0.59.5 with gradle 3.3.1 .

booleanBoy commented 5 years ago

I'm sorry but no I don't remember or maybe even know the cause of the problem. I reviewed my commits around the time and I ended up building the app again from a new project. All I can confirm is that it wasn't the camera package causing the problem. Good luck!