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

Initial Android support (issues #103 #132 #406) #426

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rainbyte
Copy link

Hello webviewers.

I have written some code to support webview on Android. It may be not so good yet, but at least compiles and supports some features (bind, dispatch, init, eval, navigate, etc).

An Android project should be used as wrapper because a bit of Java code is needed as glue (couldn't avoid it) and also to generate the apk.

The implementation needs testing and there are some parts which should be improved or replaced (eg. init has some ugly workarounds).

I hope you can leave some comments.

@suutaku
Copy link

suutaku commented Jul 20, 2020

good job! man.

webview.h Show resolved Hide resolved
@carbotaniuman
Copy link

How much of this should go in a future Java binding?

@wusyong
Copy link

wusyong commented Jul 25, 2020

Thanks for the work! I took some time to dig up the android webview and I pretty sure it's actually written C/C++ with JNI layer for Java. I think we should try to build a ndk that can link the system library directly.
image

@rainbyte
Copy link
Author

rainbyte commented Jul 25, 2020

How much of this should go in a future Java binding?

Most of the code is Android specific, but I can try to do a Java binding after this one is completed.

Thanks for the work! I took some time to dig up the android webview and I pretty sure it's actually written C/C++ with JNI layer for Java. I think we should try to build a ndk that can link the system library directly.
image

I'm not so sure if it could be done without JNI, because NDK doesn't expose native webview, and those are implementation details which are not guaranteed to stay the same on every device as some phone use different backends.

Everywhere I consulted it is said that JNI is the only option to use system webview. The alternative could be to bundle full webview, but I think it would be too big and complex to do so.


edit: it seems using system libraries which are not exposed by NDK is forbidden in Android. See this message:

Your app directly accesses private platform libraries. You should update your app to include its own copy of those libraries or use the public NDK APIs.

Then JNI is the only valid option to use native webview, or ask Google to expose it in the NDK.

@wusyong
Copy link

wusyong commented Jul 26, 2020

Hmm, looks like maybe there are stricter rules on ndk these days. I searched some other works like crosswalk and NDK webkit. They are either unmaintained or abandoned.

@rainbyte
Copy link
Author

crosswalk

Those are external libraries used at Android 4 times, ie. they compile the entire webkit and include it inside the apk, similar to electron on the desktop, and also really heavy.

Most apps do not need it anymore, because the system uses Chrome from the store as backend or fallback to vendor webview, that nowadays is enough for many cases. But those are only exposed by the Java SDK, and non-exposed native libraries cannot be used at least since Android 6.

I think the spirit of this library is to use webview backend included in the system (ie. store or vendor one) instead of having to bundle a custom one making the apk bigger... Even if that means using JNI.

The thing I'm not so sure is if avoiding Java code is convenient or not. I tried to implement everything using C++, but Java interface implementations (eg. Runnable) cannot be done using C++ code.

@gedw99
Copy link

gedw99 commented Jul 3, 2021

crosswalk

Those are external libraries used at Android 4 times, ie. they compile the entire webkit and include it inside the apk, similar to electron on the desktop, and also really heavy.

Most apps do not need it anymore, because the system uses Chrome from the store as backend or fallback to vendor webview, that nowadays is enough for many cases. But those are only exposed by the Java SDK, and non-exposed native libraries cannot be used at least since Android 6.

I think the spirit of this library is to use webview backend included in the system (ie. store or vendor one) instead of having to bundle a custom one making the apk bigger... Even if that means using JNI.

The thing I'm not so sure is if avoiding Java code is convenient or not. I tried to implement everything using C++, but Java interface implementations (eg. Runnable) cannot be done using C++ code.

I agree that the approach of using the native webvie is best as opppsed to bundling your own.

Did you have any luck with JNI ?

https://git.wow.st/gmp/jni

@justjosias
Copy link
Member

@rainbyte I'm still intending on reviewing this. I just have to set aside some time to set up an Android development environment and test it on an Android device, which I don't have readily available.

@gedw99
Copy link

gedw99 commented Apr 8, 2022

Here is an webview written in golang. https://github.com/inkeliz/gowebview

Its based on https://github.com/webview/webview, but takes a different approach where it does not use CGO.

It supports desktops and mobile.

Mobile.

  • android works
  • ios needs some work

Desktop.

  • windows works
  • Mac OS also needs some work.

@justjosias justjosias added this to the v0.12.0 milestone May 20, 2022
@justjosias
Copy link
Member

@rainbyte I have an Android development environment set up and I'm starting to test this. Sorry for the delay.

@rainbyte
Copy link
Author

@rainbyte I have an Android development environment set up and I'm starting to test this. Sorry for the delay.

That would be great @justjosias , I didn't look into the codebase recently, but feel free to ask anything you need

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

Successfully merging this pull request may close these issues.

None yet

6 participants