expo: expo-constants:compileDebugJavaWithJavac FAILED

error: package android.support.annotation does not exist

in:

node_modules/expo-constants/android/src/main/java

/Users/ushbaybeibars1/Documents/GitHub/platform-rn/node_modules/expo-constants/android/src/main/java/expo/modules/constants/ConstantsService.java:6: error: package android.support.annotation does not exist
import android.support.annotation.Nullable;

/Users/user/Documents/GitHub/project/node_modules/expo-constants/android/src/main/java/expo/modules/constants/ConstantsService.java:51: error: cannot find symbol
  @Nullable
   ^
  symbol:   class Nullable
  location: class ConstantsService
2 errors

my app build.gradle:

def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.bmintegrityapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        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", "x86_64"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // 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) * 1048576 + defaultConfig.versionCode
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation project(':react-native-gesture-handler')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    androidImplementation "com.android.support:support-annotations:28.0.0"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-svg')
    addUnimodulesDependencies()
}

// 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'
}

Any ideas?

Many thanks

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 16 (1 by maintainers)

Most upvoted comments

delete the build directory

cd android && ./gradlew clean

then return to the root of your project and run

npx jetify

npx react-native run-android

your app should correctly compile and work

@Rizaldinurm hi I found the solution by using Jetifier https://www.npmjs.com/package/jetifier Hope it will resolve your problem too.

I have some familiar error,

./node_modules/expo-constants/android/src/main/java/expo/modules/constants/ConstantsService.java:6: error: cannot find symbol import androidx.annotation.Nullable;

./node_modules/expo-constants/android/src/main/java/expo/modules/constants/ConstantsService.java:51: error: cannot find symbol

  • What went wrong: Execution failed for task ‘:expo-constants:compileDebugJavaWithJavac’.

Compilation failed; see the compiler error output for details.

In Ios work well, but in android I get an error like that.