delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

error onUnhandledInputEvent on api 24 #83

Open dawud-tan opened 8 years ago

dawud-tan commented 8 years ago

Error:(569, 27) error: cannot find symbol method onUnhandledInputEvent(WebView,InputEvent)

ocram commented 8 years ago

Thanks for reporting this!

Indeed, this method has been removed in Android 7.0 (API level 24).

Did you compile this library yourself from source? Is it just a warning or is it something that prevents your app (using this library) from compiling successfully?

dawud-tan commented 8 years ago

If my app target API 24, the gradle prevents my ap from compiling successfully, but, if I just compile it using API 23, the compilation is successful

ocram commented 8 years ago

Thanks a lot!

Please compile your app with API level 23 for now as a workaround, if that works for you. Apart from that, I'm afraid we'll have to remove that onUnhandledInputEvent method, which will break things for developers who rely on this callback.

Let's leave this issue open, there's definitely still something to do here.

recoverrelax commented 7 years ago

have this issue also. Need Api24 for support library =(. Will just copy the class and remove the code, i'm not using it at the moment.

ocram commented 7 years ago

@recoverrelax Sorry for that! We'll definitely have to find a solution here.

Will just copy the class and remove the code, i'm not using it at the moment.

That's a proper workaround, you're right.

Perhaps, instead of removing that method from the library code right away, would you mind testing a fix? In the onUnhandledInputEvent method, there's a

if (Build.VERSION.SDK_INT >= 21) {

condition and, maybe, changing it to

if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT <= 23) {

fixes the issue without removing that method. Can you check this?

ocram commented 7 years ago

Okay, that doesn't work. The library must not be compiled against API levels 24+. Otherwise, the content of this callback must be removed. The callback itself is fine, since we don't override anything (explicitly). But the calls inside are not. We could throw an exception in that callback saying that it's now deprecated, for example.

But I still can't re-produce your original issue. If I set compileSdkVersion 24 and/or targetSdkVersion 24 for my app, it compiles fine. Only when I set that level for the library, the build will fail. That makes sense, of course: The library is what must be compiled against an API level that still has that callback. It shouldn't matter what API level you compile your app against.

YuanWenHai commented 7 years ago

I found a problem about that. If you use the dependency in your project and target version is greater than 23, when the page is showing certain contents(such as video), the project will be crashed. Apologize for my poor English (:

ocram commented 7 years ago

Thanks, @YuanWenHai!

I found a problem about that.

About what exactly?

About the onUnhandledInputEvent still in the library or about this callback being removed?

If you use the dependency in your project and target version is greater than 23, when the page is showing certain contents(such as video), the project will be crashed.

  1. Are you sure this is not happening on API level 23 and below? Can you please double-check this? Apart from that, does adding or removing the onUnhandledInputEvent callback have any effects? Thanks!
  2. Are you sure this is related to the current issue at all? It might just be because of some changes that come with the adjusted target level.

Apologize for my poor English (:

It's fine!

ocram commented 7 years ago

Regarding the initial problem in this issue thread: Still can't re-produce!

Are you sure you didn't actually update the compileSdkVersion or targetSdkVersion in the library (instead of your application using the library) while building from source?

Setting compileSdkVersion or targetSdkVersion to 24+ doesn't seem to cause any problems as long as the library itself does have compileSdkVersion and targetSdkVersion set to 23 or below.

nasznjoka commented 7 years ago

So how come this issue is still there? I'm supposed to release my product today and I built around this library, and I'm targeting sdk 26 and build tools 26.0.1 but this bug just appears there!

ocram commented 7 years ago

It's still there because so far, no reliable and accurate information has been provided on how to re-produce this. In fact, it could not actually be re-produced by us, and I'm sure it's working correctly for quite a few users. If we know how to re-produce (and thus fix) this, we'll be happy to do so.

kambizira commented 6 years ago

so , should i remove those line of code?i did not understand what i should do to solve that.

ocram commented 6 years ago

Actually, you shouldn’t have to do anything if you compiled the library against API level 23 or below, or if you just used the pre-built dependency. If that still doesn’t work for you, yes, you can simply remove the onUnhandledInputEvent method (or only its contents) from the library’s code.

rignaneseleo commented 6 years ago

I can write my case: with your v3, if I use compileSdkVersion and compile the 'com.android.support:support-v4:X.X.X' greater than 24, I got the same error with onUnhandledInputEvent I can only use compileSdkVersion 23 and compile 'com.android.support:support-v4:23.4.0'

Any fix?

ocram commented 6 years ago

@rignaneseleo Thank you!

To everyone still having this problem, could you try the following version as your Gradle dependency and check if it works with API levels 24+ then?

compile 'com.github.delight-im:Android-AdvancedWebView:cf7f6b78a014d99dc24b7d66beaa2ba02a1000a8'

Thanks!

rignaneseleo commented 6 years ago

I tried and it looks like compiling and working.

What did you change? I need to know because in my project I've copied your entire class in order to make some modifications.

ocram commented 6 years ago

@rignaneseleo Sure, I have just removed the callback that was removed from Android: https://github.com/delight-im/Android-AdvancedWebView/commit/cf7f6b78a014d99dc24b7d66beaa2ba02a1000a8

RanjithSri commented 6 years ago

As mentioned that Target SDK Version and Compile SDK Version should be the same. Will there be any problem If set ' ie Compile SDK version as 23 and Target SDK version as 26 app/build.gradle file

**apply plugin: 'com.android.application'

android { compileSdkVersion 23 buildToolsVersion '26.0.2'

defaultConfig {

    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies { implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support:design:26.0.2' compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:26.0.2'

}**

ocram commented 6 years ago

@RanjithSri Please see this comment above for an updated dependency that you can use in your build.gradle. With that dependency, there should be no need for a lower compileSdkVersion anymore, at least not due to this library.

RanjithSri commented 6 years ago

Thanks for the reply Bro....:)

On Tue, Feb 20, 2018 at 4:00 AM, Marco notifications@github.com wrote:

@RanjithSri https://github.com/ranjithsri Please see this comment above https://github.com/delight-im/Android-AdvancedWebView/issues/83#issuecomment-366420185 for an updated dependency that you can use in your build.gradle. With that dependency, there should be no need for a lower compileSdkVersion anymore, at least not due to this library.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/delight-im/Android-AdvancedWebView/issues/83#issuecomment-366817881, or mute the thread https://github.com/notifications/unsubscribe-auth/Ai8qWfMtRLMtxxWx5S9k1FsFAUZGk8L5ks5tWfYOgaJpZM4KIe_Q .

anggrayudi commented 6 years ago

We can use Java Reflection for that purpose:

                    if (mCustomWebViewClient != null) {
//                        mCustomWebViewClient.onUnhandledInputEvent(view, event);
                        try {
                            Method method = mCustomWebViewClient.getClass().getMethod(
                                    "onUnhandledInputEvent", view.getClass(), event.getClass());
                            method.invoke(mCustomWebViewClient, view, event);
                        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                            e.printStackTrace();
                        }
                    } else {
//                        super.onUnhandledInputEvent(view, event);
                        try {
                            MethodHandle method = MethodHandles.lookup().findSpecial(WebViewClient.class,
                                    "onUnhandledInputEvent", MethodType.methodType(Void.TYPE),
                                    AdvancedWebView.class);
                            method.invoke(view, event);
                        } catch (Throwable e) {
                            e.printStackTrace();
                        }
                    }
doc-rj-celltrak commented 5 years ago

I'm using v3.0.0 of this library with target and compile sdk version 29, and I still get the warning:

Warning: im.delight.android.webview.AdvancedWebView$1: can't find referenced method 'void onUnhandledInputEvent(android.webkit.WebView,android.view.InputEvent)' in library class android.webkit.WebViewClient Warning: there were 1 unresolved references to library class members. You probably need to update the library versions. (docs/troubleshooting.html#unresolvedlibraryclassmember)

Screen Shot 2019-10-23 at 9 35 19 PM
doc-rj-celltrak commented 4 years ago

Still having this problem with version 3.2.1 of the library.

digitpk commented 3 years ago

If the bug is still there for some of the users then I sort it out by replacing onUnhandledInputEvent with onUnhandledKeyEvent