今天因为支持kitkat,所以将项目的targetsdkversion升级到19. 结果运行后,browser就挂了,
一直显示没有execute方法,这个方法是暴露给js的。js代码会调用本地的类中的该方法。
到官方文档上看了看,果然是android这个垃圾造成的。之前我们的targesdkversion是10,execute方法上未添加任何annotation。
结果android要求当target sdkversion到17或者更高后,必须使用一个annotation @JavascriptInterface
估计是用来运行时捕捉所有可调用的接口。
大家以后在升级targetsdkversion的时候还是小心点。各种类似的坑非常多。
Caution: If you've set your targetSdkVersion
to 17 or higher, you must add the @JavascriptInterface
annotation to any method that you want available to your JavaScript (the method must also be public). If you do not provide the annotation, the method is not accessible by your web page when running on Android 4.2 or higher.