Unable to make field private final java.lang.String java.io.File.path accessible Qt Android
Asked Answered
T

12

50

I am trying to run my android program in Qt however I am getting the following error:

Execution failed for task ':processDebugManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @13d72a22

I tried different versions of jdk and gradle however nothing helps.

Gradle version: 7.4.2 JDK version: 18

Taiwan answered 20/5, 2022 at 17:57 Comment(1)
I get the same error with openjdk version "18.0.1" 2022-04-19 and Gradle 7.3.3.Sebastiansebastiano
F
89

Answer for Flutter Devs

I ran into this error in IntelliJ while trying to build a Flutter app for Android. I was updating an app I had worked on almost a year ago so the com.android.tools.build:gradle dependency in android/build.gradle was way out of date.

Fixed by changing dependency to this:

 classpath 'com.android.tools.build:gradle:7.4.1'
Feign answered 19/2, 2023 at 17:59 Comment(5)
This is valid also for native Android. Thanks!Filose
that's worked for me tooBemire
upgrade to latest gradle version, it's now 7.4.2. In future 8.x.x, 9.x.xJessiejessika
Yeah worked for me too, for flutter project i did in 2022.Amias
this worked for me as well on Flutter 3.22 version, dated 28th May, 2024Lareine
S
38

Adding --add-opens=java.base/java.io=ALL-UNNAMED to your JAVA_OPTS environment variable or the org.gradle.jvmargs gradle property will resolve this issue with Java 18.

Here is the full org.gradle.jvmargs gradle property value that I'm using:

org.gradle.jvmargs = -Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED

Another option is to downgrade to JDK 17. I downgraded to openjdk version "17.0.3" 2022-04-19 and did not get the error.

Sebastiansebastiano answered 26/5, 2022 at 17:21 Comment(2)
worked like a charm! openjdk 19.0.1 2022-10-18Fullerton
worked on my java 19.0.2 2023-01-17Outdoor
B
19

I just figured out the solution All I did is to add

org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED

to the gradle.properties file

See this link : How to solve InaccessibleObjectException ("Unable to make {member} accessible: module {A} does not 'opens {package}' to {B}") on Java 9?

Burrow answered 23/9, 2023 at 18:19 Comment(7)
Please don't post the same answer to multiple posts or post answers that already exist for the said question.Rainband
thank you for your comment, I tried to mention the answer related to this problem, in which I did answered beforeBurrow
If two questions are asking the same, you can flag one as a duplicate of another. Aside from that, there is already an answer saying the same for this question.Rainband
Solved for me, thanks! Also important to re-sync with gradle files after changing that, cf: #72448723Emmalynn
thanks you @chesterbr, but android studio can do the re-sync automatically, if it is diabled you need to do that yourselfBurrow
yes it worked for me on flutter @AbdeldjalilChouguiMcdonald
Worked for me! I don't know what @dan1stiscrying is talking about, this is a much better answer than the one he linked. Thank you Abdeldjalil Chougui for posting this.Burgee
A
12

The Java version is too high, downgrading will solve this problem.

You can do it with following the breadcrumbs below:

File->Project Structure->SDK Location->Gradle Settings->Gradle JDK

Away answered 4/5, 2023 at 6:58 Comment(0)
P
5

Just doing an update to the project dependencies fix this.

File > Project Structure > Suggestions

Phantasm answered 16/6, 2023 at 5:7 Comment(0)
B
3

I got this weird error in IntelliJ when trying to build an Android project. I think the core reason was me changing the JDK version that Gradle uses in Settings -> Build, Execution, Deployment -> Build Tools -> Gradle and Gradle JVM down there at the bottom. I tried increasing that to fix something else and got this error. Just changing back to the exact version I always used seemed to fix it. This is kind of a terrible answer but I'm going to post it anyway, it might help someone.

Bodiless answered 4/10, 2022 at 19:38 Comment(0)
B
3

In my case I modified my gradle.properties file, since I had more than one flag to set for org.gradle.jvmargs

org.gradle.jvmargs=--add-opens java.base/java.io=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8

You can't simply add more than one instance of org.gradle.jvmargs This is a whole lot better than changing jdk to address something that does not require it.

Bludgeon answered 28/2 at 19:2 Comment(0)
H
1

After Flutter 3.16 imperative apply is deprecated Deprecated imperative apply of Flutter's Gradle plugins

In Flutter 3.16, support has been added for applying these plugins with Gradle’s declarative plugins {} block (also called the Plugin DSL) and it is now the recommended approach. Since Flutter 3.16, projects generated with flutter create use the Plugin DSL to apply Gradle plugins. Projects created with versions of Flutter prior to 3.16 need to be migrated manually.

in android/app/build.gradle replace

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

with

plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

and in android/settings.gradle replace this

include ':app'

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

with

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }
    settings.ext.flutterSdkPath = flutterSdkPath()

    includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }

    plugins {
        id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
    }
}

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "7.3.0" apply false
}


include ':app'

and don't forget to update the Kotlin Gradle plugin to version 1.5.20 or higher.

Hilton answered 23/1 at 1:1 Comment(0)
J
0

Downgrading the JDK version from 17 to 11 works for me. Note: Do not forget to set the path for the JDK for respective platforms.

Jackstraw answered 22/10, 2023 at 1:54 Comment(0)
A
0

I fix it by check the JDK Version

javac -version

Downgrading the JDK version from 17 to 11 like this in bash_profile source bash_profile then build

export JAVA_HOME="/Users/{$YOURNAME}/Library/Java/JavaVirtualMachines/corretto-1.8.0_382/Contents/Home"

export PATH=$JAVA_HOME/bin:$PATH
Autarky answered 23/11, 2023 at 6:46 Comment(0)
T
0

i am getting this error

Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @28da2d6f

just change the gradle settings to 1.8 correto

Tingley answered 19/2 at 8:51 Comment(0)
G
-1

For Flutter :

I downloaded 2 JDK jdk-17.0.1 and jdk-11.0.13 and add below line on gradle.properties

For Android :

org.gradle.java.home=C\:\\Program Files (x86)\\Java\\jdk-11.0.13

For Mac :

org.gradle.java.home=/Applications/Android Studio 2.app/Contents/jbr/Contents/Home
Gorky answered 19/6, 2023 at 19:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.