Task :app:compileReleaseJavaWithJavac FAILED : cannot find symbol import com.reactnativemmkv.MmkvModulePackage
Hello,
I am running into a cannot find symbol import com.reactnativemmkv.MmkvModulePackage; error when building for android release. It seems to be related to the react-native-reanimated library but the error stems from the react-native-mmkv package.
Here is my package.json:
{
"name": "green-cents",
"version": "1.0.2",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/masked-view": "^0.1.11",
"@react-native/metro-config": "^0.72.11",
"@react-navigation/native": "^5.9.4",
"@react-navigation/stack": "^5.14.5",
"@sentry/react-native": "^2.6.0",
"react": "18.2.0",
"react-native": "0.72.4",
"react-native-confetti-cannon": "^1.5.2",
"react-native-currency-input": "^1.0.1",
"react-native-gesture-handler": "^1.10.3",
"react-native-get-random-values": "^1.7.0",
"react-native-gradle-plugin": "^0.71.19",
"react-native-mmkv": "^2.10.1",
"react-native-reanimated": "^3.4.2",
"react-native-safe-area-context": "^3.2.0",
"react-native-screens": "^3.4.0",
"react-native-segmented-control-tab": "^3.4.1",
"react-native-vector-icons": "^8.1.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "7.14.0",
"jest": "^26.6.3",
"metro-config": "^0.78.1",
"metro-react-native-babel-preset": "^0.64.0",
"react-test-renderer": "17.0.1"
},
"jest": {
"preset": "react-native"
}
}
app/build.gradle:
apply plugin: "com.facebook.react"
apply plugin: "com.android.application"
/**
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
*/
react {
/* Folders */
// The root of your project, i.e. where "package.json" lives. Default is '..'
// root = file("../")
// The folder where the react-native NPM package is. Default is ../node_modules/react-native
// reactNativeDir = file("../node_modules/react-native")
// The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
// codegenDir = file("../node_modules/@react-native/codegen")
// The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
// cliFile = file("../node_modules/react-native/cli.js")
/* Variants */
// The list of variants to that are debuggable. For those we're going to
// skip the bundling of the JS bundle and the assets. By default is just 'debug'.
// If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
// debuggableVariants = ["liteDebug", "prodDebug"]
/* Bundling */
// A list containing the node command and its flags. Default is just 'node'.
// nodeExecutableAndArgs = ["node"]
//
// The command to run when bundling. By default is 'bundle'
// bundleCommand = "ram-bundle"
//
// The path to the CLI configuration file. Default is empty.
// bundleConfig = file(../rn-cli.config.js)
//
// The name of the generated asset file containing your JS bundle
// bundleAssetName = "MyApplication.android.bundle"
//
// The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
// entryFile = file("../js/MyApplication.android.js")
//
// A list of extra flags to pass to the 'bundle' commands.
// See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
// extraPackagerArgs = []
/* Hermes Commands */
// The hermes compiler command to run. By default it is 'hermesc'
// hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
//
// The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
// hermesFlags = ["-O", "-output-source-map"]
}
/**
* Set this to true to Run Proguard on Release builds to minify the Java bytecode.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore (JSC)
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
// compileOptions {
// sourceCompatibility JavaVersion.VERSION_1_8
// targetCompatibility JavaVersion.VERSION_1_8
// }
namespace "com.financialliteracyforyou.greencents"
defaultConfig {
applicationId "com.financialliteracyforyou.greencents"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 820230
versionName "1.0.2"
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
}
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
// The version of react-native is set by the React Native Gradle Plugin
// implementation fileTree(dir: "libs", include: ["*.jar"])
implementation("com.facebook.react:react-android")
implementation project(':react-native-mmkv')
// implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
project.ext.react = [
nodeExecutableAndArgs : ["/usr/local/bin/node"],
enableHermes: true
];
android/build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
ndkVersion = "23.1.7779620"
androidXAnnotation = "1.2.0"
androidXBrowser = "1.4.0"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.1.0")
classpath("com.facebook.react:react-native-gradle-plugin")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
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")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
error log: Build command: npx react-native build-android --mode=release
> Task :app:compileReleaseJavaWithJavac FAILED
/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/android/app/src/main/java/com/financialliteracyforyou/greencents/MainApplication.java:13: error: cannot find symbol
import com.reactnativemmkv.MmkvModulePackage;
^
symbol: class MmkvModulePackage
location: package com.reactnativemmkv
/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/android/app/src/main/java/com/financialliteracyforyou/greencents/BudgetappJSIPackage.java:6: error: cannot find symbol
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
^
symbol: class ReanimatedJSIModulePackage
location: package com.swmansion.reanimated
/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/android/app/src/main/java/com/financialliteracyforyou/greencents/BudgetappJSIPackage.java:13: error: cannot find symbol
public class BudgetappJSIPackage extends ReanimatedJSIModulePackage {
^
symbol: class ReanimatedJSIModulePackage
/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/android/app/src/main/java/com/financialliteracyforyou/greencents/MainApplication.java:54: error: incompatible types: BudgetappJSIPackage cannot be converted to JSIModulePackage
return new BudgetappJSIPackage();
^
/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/android/app/src/main/java/com/financialliteracyforyou/greencents/MainApplication.java:72: error: cannot find symbol
ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
^
symbol: variable ReactNativeFlipper
location: class MainApplication
/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/android/app/src/main/java/com/financialliteracyforyou/greencents/BudgetappJSIPackage.java:14: error: method does not override or implement a method from a supertype
@Override
^
/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/android/app/src/main/java/com/financialliteracyforyou/greencents/BudgetappJSIPackage.java:16: error: cannot find symbol
super.getJSIModules(reactApplicationContext, jsContext);
^
symbol: variable super
location: class BudgetappJSIPackage
/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/android/app/src/main/java/com/financialliteracyforyou/greencents/BudgetappJSIPackage.java:17: error: method install in class MmkvModule cannot be applied to given types;
MmkvModule.install(jsContext, reactApplicationContext.getFilesDir().getAbsolutePath() + "/mmkv");
^
required: String
found: JavaScriptContextHolder,String
reason: actual and formal argument lists differ in length
8 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/8.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 28s
177 actionable tasks: 172 executed, 5 up-to-date
info 💡 Tip: Make sure that you have set up your development environment correctly, by running react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor
error Failed to build the app.
Error: Command failed with exit code 1: ./gradlew app:bundleRelease
at makeError (/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/node_modules/@react-native-community/cli-platform-android/node_modules/execa/lib/error.js:60:11)
at module.exports.sync (/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:194:17)
at build (/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/node_modules/@react-native-community/cli-platform-android/build/commands/buildAndroid/index.js:95:22)
at Object.buildAndroid [as func] (/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/node_modules/@react-native-community/cli-platform-android/build/commands/buildAndroid/index.js:87:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Command.handleAction (/Users/jimfang/Documents/Projects/Green-Cents/mobile/budgetApp/node_modules/@react-native-community/cli/build/index.js:111:9)
info Run CLI with --verbose flag for more details.
Things I've tried already:
- downgrading to react-native-reanimated v2
- moving to react-native-mmkv 2.4
- removing the
getJSIModulePackage()method import com.facebook.react.bridge.JSIModulePackage;in MainApplication.java. (see)- moving/downgrading to node v16 LTS when building
- nuking gradle cache, build, .cxx folders and rebuilding using
./gradlew clean - manually linking the react-native-reanimated package (see here)
Target SdkVersion: 33
Let me know if you need anything else - or if you want me to upload these/other logs to a pastebin/gist for easier viewing.
Thanks in advance.
Hi, try following https://deksmond.medium.com/deprecated-gradle-features-were-used-in-this-build-making-it-incompatible-with-gradle-8-0-cdbe9f2fa628, it might help you if the problem still exists.
Hey - I think this has been fixed in V3 beta.