Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execution failed for task ':react-native-navigation:compileReactNative71DebugKotlin'. #7819

Open
1 task done
HaNguyenRN opened this issue Dec 8, 2023 · 17 comments · May be fixed by #7831
Open
1 task done

Execution failed for task ':react-native-navigation:compileReactNative71DebugKotlin'. #7819

HaNguyenRN opened this issue Dec 8, 2023 · 17 comments · May be fixed by #7831

Comments

@HaNguyenRN
Copy link

HaNguyenRN commented Dec 8, 2023

What happened?

Execution failed for task ':react-native-navigation:compileReactNative71DebugKotlin'.

'compileReactNative71DebugJavaWithJavac' task (current target is 17) and 'compileReactNative71DebugKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain

  • 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.
For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 1m 11s
619 actionable tasks: 619 executed

What was the expected behaviour?

...

Was it tested on latest react-native-navigation?

  • I have tested this issue on the latest react-native-navigation release and it still reproduces.

Help us reproduce this issue!

...

In what environment did this happen?

React Native Navigation version: 7.37.2
React Native version: 0.73.0
Node version: v20.3.0
Device model: Pixel
Android version: 14

Tasks

No tasks being tracked yet.
@HaNguyenRN
Copy link
Author

Java version: OpenJDK 64-Bit Server VM Zulu17.46+19-CA (build 17.0.9+8-LTS, mixed mode, sharing)

@joakimwennergren
Copy link

joakimwennergren commented Dec 8, 2023

I'm having the same issue, tried installing openjdk 11 and setting targetsdk.

java { targetCompatibility = JavaVersion.VERSION_11 }

kotlin { jvmToolchain(11) }

tasks.withType<KotlinCompile>().configureEach {
  kotlinOptions {
    apiVersion = "1.6"
    // See comment above on JDK 11 support
    jvmTarget = "11"
    allWarningsAsErrors = true
  }
}

@hachther
Copy link

hachther commented Dec 8, 2023

You can manually update update theses files for now

  • lib/android/app/build.gradle[64-70]
compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
    jvmTarget = JavaVersion.VERSION_17
}
  • lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt[197-200]
override fun onInitializeAccessibilityNodeInfo(
    host: View,
    info: AccessibilityNodeInfoCompat
) {

@predescu
Copy link

predescu commented Dec 8, 2023

@hachther , could you please share your MainApplication.kt? I did the updates you suggested (thanks for it) but I have a definite error.
The build works, but the app crashes at the start: java.lang.RuntimeException: Unable to instantiate application

@ertugruldogan
Copy link

ertugruldogan commented Dec 8, 2023

@hachther
Copy link

hachther commented Dec 8, 2023

@hachther , could you please share your MainApplication.kt? I did the updates you suggested (thanks for it) but I have a definite error. The build works, but the app crashes at the start: java.lang.RuntimeException: Unable to instantiate application

package com.graphicssystem.fujisat

import com.facebook.react.PackageList
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.soloader.SoLoader
import com.reactnativenavigation.NavigationApplication
import com.reactnativenavigation.react.NavigationReactNativeHost

class MainApplication : NavigationApplication() {
    private val mReactNativeHost: NavigationReactNativeHost =
        object : NavigationReactNativeHost(this) {
            override fun getUseDeveloperSupport(): Boolean {
                return BuildConfig.DEBUG
            }

            override fun getPackages(): List<ReactPackage> {
                val packages: MutableList<ReactPackage> = PackageList(this).packages
                // Packages that cannot be autolinked yet can be added manually here, for example:
                return packages
            }

            override fun getJSMainModuleName(): String {
                return "index"
            }
        }
    override val reactNativeHost: ReactNativeHost
        get() = mReactNativeHost

    override fun onCreate() {
        super.onCreate()
        // If you opted-in for the New Architecture, we enable the TurboModule system
        SoLoader.init(this,  /* native exopackage */false)
        if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
            // If you opted-in for the New Architecture, we load the native entry point for this app.
            load()
        }
    }
}

@predescu
Copy link

predescu commented Dec 8, 2023

@hachther

Thank You. It worked perfectly. I did the conversion of the class wrongly.

@OskarEichler
Copy link

You can manually update update theses files for now

  • lib/android/app/build.gradle[64-70]
compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
    jvmTarget = JavaVersion.VERSION_17
}
  • lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt[197-200]
override fun onInitializeAccessibilityNodeInfo(
    host: View,
    info: AccessibilityNodeInfoCompat
) {

@hachther Made these changes but still running into the same error:

Execution failed for task ':react-native-navigation:compileReactNative71DebugKotlin'.
> Inconsistent JVM-target compatibility detected for tasks 'compileReactNative71DebugJavaWithJavac' (17) and 'compileReactNative71DebugKotlin' (1.8).

@lyswhut
Copy link

lyswhut commented Dec 12, 2023

Before the official supports RN v0.73, try the steps, it works for me:

  1. Add dependencies-patch.js:
const fs = require('node:fs')
const path = require('node:path')

const rootPath = path.join(__dirname, './')

const patchs = [
  [
    path.join(rootPath, './node_modules/react-native-navigation/lib/android/app/build.gradle'),
    `
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }`,
    '',
  ],
  [
    path.join(rootPath, './node_modules/react-native-navigation/lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt'),
    `override fun onInitializeAccessibilityNodeInfo(
                        host: View?,
                        info: AccessibilityNodeInfoCompat?
                    ) {
                        super.onInitializeAccessibilityNodeInfo(host, info)

                        // Expose the testID prop as the resource-id name of the view. Black-box E2E/UI testing
                        // frameworks, which interact with the UI through the accessibility framework, do not have
                        // access to view tags. This allows developers/testers to avoid polluting the
                        // content-description with test identifiers.
                        val testId = host?.tag as String?
                        if(testId != null){
                            info!!.viewIdResourceName = testId
                        }
                    }`,
    `override fun onInitializeAccessibilityNodeInfo(
                      host: View,
                      info: AccessibilityNodeInfoCompat
                    ) {
                        super.onInitializeAccessibilityNodeInfo(host, info)

                        // Expose the testID prop as the resource-id name of the view. Black-box E2E/UI testing
                        // frameworks, which interact with the UI through the accessibility framework, do not have
                        // access to view tags. This allows developers/testers to avoid polluting the
                        // content-description with test identifiers.
                        val testId = host.tag as String?
                        if(testId != null){
                            info.viewIdResourceName = testId
                        }
                    }`,
  ],
]

;(async() => {
  for (const [filePath, fromStr, toStr] of patchs) {
    console.log(`Patching ${filePath.replace(rootPath, '')}`)
    try {
      const file = (await fs.promises.readFile(filePath)).toString()
      await fs.promises.writeFile(filePath, file.replace(fromStr, toStr))
    } catch (err) {
      console.error(`Patch ${filePath.replace(rootPath, '')} failed: ${err.message}`)
    }
  }
  console.log('\nDependencies patch finished.\n')
})()
  1. Edit package.json and add scripts: "postinstall": "node ./dependencies-patch.js"
  2. Edit android/app/proguard-rules.pro and add rule -keep class com.reactnativenavigation.views.element.animators.** { *; } (It fixed shared element transitions)
  3. Remove node_modules and then run npm install

@HaNguyenRN
Copy link
Author

You can manually update update theses files for now

  • lib/android/app/build.gradle[64-70]
compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
    jvmTarget = JavaVersion.VERSION_17
}
  • lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/topbar/button/ButtonPresenter.kt[197-200]
override fun onInitializeAccessibilityNodeInfo(
    host: View,
    info: AccessibilityNodeInfoCompat
) {

Hi @OskarEichler could you show me the file MainApplication.kt & MainActivity.kt?

@OskarEichler
Copy link

Hey @HaNguyenRN

Please find both files attached (had to change the file extension to .txt in order to upload them here, so please change back to .kt). Thanks for looking into this!

MainApplication.txt
MainActivity.txt

@elmalakomar
Copy link

I'm the only one that didn't understand where to copy the dependencies in the gradle file?
I have 3 main objects:

  1. react
  2. android
  3. dependencies

In every way I copy the code I receive and error.
This is a new error also:

Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * Where:
Build file '/android/app/build.gradle' line: 120 * What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method compileOptions() for arguments [build_as7kgs715znh3750q73r32jel$_run_closure3$_closure10@419c928e] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

@OskarEichler can you help me please?

@kauly
Copy link

kauly commented Dec 28, 2023

@elmalakomar its inside of the android {} section, like this:

android {
    ndkVersion rootProject.ext.ndkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    compileSdk rootProject.ext.compileSdkVersion

    namespace "com.boatapp"
    defaultConfig {
        applicationId "com.boatapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    }
    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.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }
}

@elmalakomar
Copy link

Ok, I tried as you suggested but I'm still getting the same error. I need to do something else? run some script? @kauly

'compileReactNative71DebugJavaWithJavac' task (current target is 17) and 'compileReactNative71DebugKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version

@kauly
Copy link

kauly commented Dec 28, 2023

Try to do the same thing but in the build.gradle of the rnn library

@elmalakomar
Copy link

I fixed running the script suggested a few comments above

@Halilibrahimakyz
Copy link

Try to do the same thing but in the build.gradle of the rnn library

this worked for me thanks @kauly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants