Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Kotlin target tries to build Android app with system's JDK #106

Open
batkov opened this issue Jun 1, 2021 · 5 comments
Open

Kotlin target tries to build Android app with system's JDK #106

batkov opened this issue Jun 1, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@batkov
Copy link

batkov commented Jun 1, 2021

Basically I'm getting error:

Showing All Messages
> 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 @165ff712

Screen Shot 2021-06-01 at 8 15 51 PM

But from Android Studio everything looks good.
It looks like when we are building from the Xcode with Kotlin target, jdk installed in the macOS system.
I've tried to change STUDIO_JDK and JAVA_HOME but it did not work.

I believe there is some simple solution, like set env variable, pass script parameter or update Android project settings.

@batkov batkov added the bug Something isn't working label Jun 1, 2021
@vinivendra
Copy link
Owner

Thanks for reporting this bug. I don't have a lot of experience with Android compilation but let's try to figure out what's happening to see how we can fix it with Gryphon.

Basically what Gryphon does in the Kotlin target is switch to the Android app's folder and call Gradle to compile the app:

cd "$ANDROID_ROOT"
./gradlew compileDebugSources

This is the main part of a larger script that you can probably see in your iOS project's folder under .gryphon/scripts/compileKotlin.sh if you want to.

Could you try to run ./gradlew compileDebugSources in your Android app's folder and see what you get?

@vinivendra vinivendra added the question Further information is requested label Jun 5, 2021
@batkov
Copy link
Author

batkov commented Jun 5, 2021

Ok, trying to reproduce.
First, I forgot to set $ANDROID_ROOT again and got an error .gryphon/scripts/compileKotlin.sh: line 21: cd: ../Android: No such file or directory

I believe it would be beneficial to expand an error with message like Please make sure you've set $ANDROID_ROOT build variable properly

@batkov
Copy link
Author

batkov commented Jun 5, 2021

So, on fresh macOS i'm getting

./gradlew compileDebugSource
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

Which means that build tries to build app with system's JDK. Bunch of fixes is here.
But basically I think it is not right way to fix the issue, because the tools to build app via Xcode and Android Studio will differ.
I'll try to find solution and come back to you.

@batkov
Copy link
Author

batkov commented Jun 5, 2021

Here is my findings.

I've resolved problem locally by changing the script:
from

bash .gryphon/scripts/compileKotlin.sh

to

env JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home bash .gryphon/scripts/compileKotlin.sh

This is far from elegant solution, but it is much better than using duplicate JDK in one system.
I would like to see the good solution as following.
root folder of project would be having:

.gryphon-android-root // '../my_android_app_folder'
.gryphon-jdk-path // empty/nonexistent means using of system's JAVA_HOME, existent passed though 'env JAVA_HOME='
.gryphon-android-src // root path to all files

I know I mentioning another issue here, but having .gryphon-android-root + .gryphon-android-src would mean that android app could change location/package/module without having iOS app changing its sources, only few files that could be in gitignore.

@vinivendra
Copy link
Owner

Hey @batkov, I implemented the config file. It doesn't yet support the Java home setting you asked for, but it's a first step. Let me know if it works for you for now, ok? I'll try to add the Java home support later using this system, that sounds like a good idea.

@vinivendra vinivendra removed the question Further information is requested label Jul 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants