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

Could not find Java class corresponding to Objective-C class: WKNSURLAuthenticationChallenge #336

Closed
MrDaande opened this Issue Nov 9, 2018 · 13 comments

Comments

Projects
None yet
2 participants
@MrDaande

MrDaande commented Nov 9, 2018

Issue details

We are using robovm to display a WebApp inside a WKWebView. On a specific page, we have implemented the Google Maps JS API to display a map which works fine in the browser, but in the WKWebView I receive this exception:

org.robovm.objc.ObjCClassNotFoundException: Could not find Java class corresponding to Objective-C class: WKNSURLAuthenticationChallenge

I searched already for the problem and i think, the basic authentication with the servers from Google is responsible for this problem.

Reproduction steps/code

  • Include Google Maps JS API inside an document, for testing purposes without an API key. You can find an example here.

Configuration

Please provide the build system, version(s), and targets affected.

Build Tools:

  • IDEA plugin
  • Eclipse plugin
  • Gradle plugin

Versions:

Please provide the version of RoboVM, XCode and JDK used

  • Robovm: 2.3.5-SNAPSHOT
  • XCode: 10.1
  • JDK: 1.8.0_92

Build Targets:

  • iOS 12 Simulator

Stacktrace

org.robovm.objc.ObjCClassNotFoundException: Could not find Java class corresponding to Objective-C class: WKNSURLAuthenticationChallenge
	at org.robovm.objc.ObjCClass.toObjCClass(ObjCClass.java:320)
	at org.robovm.objc.ObjCClass.getFromObject(ObjCClass.java:224)
	at org.robovm.objc.ObjCObject.toObjCObject(ObjCObject.java:322)
	at org.robovm.objc.ObjCObject.toObjCObject(ObjCObject.java:261)
	at org.robovm.apple.foundation.NSObject$Marshaler.toObject(NSObject.java:81)
	at org.robovm.apple.foundation.NSObject$Marshaler.toObject(NSObject.java:78)
	at org.robovm.apple.uikit.UIApplication.main(Native Method)
	at org.robovm.apple.uikit.UIApplication.main(UIApplication.java:428)
@dkimitsa

This comment has been minimized.

Contributor

dkimitsa commented Nov 9, 2018

hi, what framework this class from ? As I was not able to find it over entire ios12 SDK

@MrDaande

This comment has been minimized.

MrDaande commented Nov 9, 2018

I'm not using any framework. It's just a WKWebView which, i think, tries to make an HTTP-Call with a basic authentication.

@dkimitsa

This comment has been minimized.

Contributor

dkimitsa commented Nov 9, 2018

so to bind it we need to know sources it comes from. e.g. where this class is required. also is it enough just to put hello world html inside WKWebView to reproduce ?

@MrDaande

This comment has been minimized.

MrDaande commented Nov 13, 2018

also is it enough just to put hello world html inside WKWebView to reproduce ?

To reproduce the bug, just load the HTML-File below in the WKWebView which includes the Google Maps JS API:

<!DOCTYPE html>
<html>
<head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <style>
        #map {
            height: 100%;
        }
        /* Optional: Makes the sample page fill the window. */
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<div id="map"></div>
<script>
  var map;
  function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
      center: {lat: -34.397, lng: 150.644},
      zoom: 8
    });
  }
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
        async defer></script>
</body>
</html>

e.g. where this class is required

I don't know, where the class is required. I just use the WKWebView which comes with robovm

@dkimitsa

This comment has been minimized.

Contributor

dkimitsa commented Nov 13, 2018

just tried it with following code:

        wkWebView = new WKWebView(new CGRect(20, 250, 250, 300));
        view.addSubview(wkWebView);
        String html = "<!DOCTYPE html>\n" +
              // ... here html code from above goes
                "</html>";

        wkWebView.loadHTMLString(html, null);

and it works on simulator 12.1:
image

please let me know if there is any other details required to reproduce

@MrDaande

This comment has been minimized.

MrDaande commented Nov 16, 2018

Thank you for your help so far.
I figured out, that the Problem only appears, if you set a navigation delegate.

In the functionheader of didReceiveAuthenticationChallenge is a parameter called challenge of type NSURLAuthenticationChallenge which I think cause the crash. If i remove the delegate, the map view works.

@dkimitsa

This comment has been minimized.

Contributor

dkimitsa commented Nov 16, 2018

@MrDaande here are finding and workaround:
the issue here is that WKWebView sends WKNSURLAuthenticationChallenge instead of NSURLAuthenticationChallenge while calling following callback:

NSURLAuthenticationChallenge challenge, 
VoidBlock2<NSURLSessionAuthChallengeDisposition, NSURLCredential> completionHandler) 

problem here is that WKNSURLAuthenticationChallenge is not inherited from NSURLAuthenticationChallenge and thats why RoboVM fails to convert it. And contract is not broken here as WKNSURLAuthenticationChallenge actually NSProxy so it can intercept unhandled methods and process them.

At other side RoboVM does not support NSProxies and personally I don't think we need to support this stuff.

Workaround is primitive, we need to create WKNSURLAuthenticationChallenge that looks as NSURLAuthenticationChallenge .

Just add following class somewhere in your project:

/*<annotations>*/@Library("WebKit") @NativeClass/*</annotations>*/
public class WKNSURLAuthenticationChallenge extends NSURLAuthenticationChallenge {
}

but you need to keep reference to it somewhere otherwise it will be opted out as not used. I pinned it with ForceLinkClass to view controller.

@ForceLinkClass(WKNSURLAuthenticationChallenge.class)
public class MyViewController extends UIViewController implements WKNavigationDelegate {

I will make it a part of ios12 binding #335 but for now please try this workaround

dkimitsa added a commit to dkimitsa/robovm that referenced this issue Nov 17, 2018

@dkimitsa

This comment has been minimized.

Contributor

dkimitsa commented Nov 17, 2018

@MrDaande pushed it as part of #335

@MrDaande

This comment has been minimized.

MrDaande commented Nov 17, 2018

Thank you very much!

@MrDaande MrDaande closed this Nov 17, 2018

@MrDaande

This comment has been minimized.

MrDaande commented Nov 19, 2018

The app doesn't crash anymore, but the map view although doesn't work!
I've tried it with your testcase.

Result is just an empty window:
image

@MrDaande MrDaande reopened this Nov 19, 2018

@dkimitsa

This comment has been minimized.

Contributor

dkimitsa commented Nov 19, 2018

it seems as you have not implemented navigation delegate as expected you must call descision handlers where applicable.

@dkimitsa

This comment has been minimized.

Contributor

dkimitsa commented Nov 19, 2018

to check if it works use empty adapter (it works for me):

        wkWebView.setNavigationDelegate(new WKNavigationDelegateAdapter() {           
        });
@MrDaande

This comment has been minimized.

MrDaande commented Nov 19, 2018

it seems as you have not implemented navigation delegate as expected you must call descision handlers where applicable.

Perfect, it works now

@MrDaande MrDaande closed this Nov 19, 2018

florianf added a commit that referenced this issue Nov 27, 2018

Ios12 & 12.1 bindings (#335)
* Foundation processed

* Dispatch processed

* CoreFoundation processed

* CoreGraphics processed

* CoreImage processed, some changes are waiting for org.robovm.apple.avfoundation.AVPortraitEffectsMatte

* ImageIO processed

* CoreMotion processed

* CoreBluetooth processed

* CoreLocation processed

* CoreMidi processed

* CoreAnimation processed

* CoreMedia processed

* AddressBookUI processed

* UIKit updated

* Messages updated

* Intents updated

* networkextension updated

* networkextension updated

* Contacts updated

* Foundation: introduced `generic_typedefs` to protect NSObject classes to be converted into java ones in case these are used as generic specifiers to Foundation ones

* CloudKit updated

* CoreServices and CoreFoundation updated: some entities are moved from coreservice to corefoundation

* CoreTelephony updated

* LocalAuthentication updated

* ReplayKit updated

* Security updated

* MapView updated

* Systemconfiguration updated

* UserNotifications updated

* SafariServices updated

* EventKit updated

* PassKit updated

* Vision updated

* WatchConnectivity updated

* WebKit updated

* HealthKit updated

* HomeKit updated

* SpriteKit updated

* SceneKit updated

* SpriteKit updated

* CoreText updated

* CoreAudio updated

* CoreAudioKit updated

* AudioToolBox updated

* MediaPlayer updated

* Foundation updated with comments and exposed constructors

* CoreFoundation updated with comments and exposed constructors

* CoreGraphics updated with comments and exposed constructors

* AVFoundation updated, and updated with comments and exposed constructors

* CoreImage updated with comments and exposed constructors

* CoreMotion updated with comments and exposed constructors

* CoreBluetooth updated with comments and exposed constructors

* CoreLocation updated with comments and exposed constructors

* CoreData updated with comments and exposed constructors

* CoreAnimation updated with comments and exposed constructors

* Accounts updated with comments and exposed constructors

* AddressBook updated with comments and exposed constructors

* AddressBookUI updated with comments and exposed constructors

* Messages updated with comments and exposed constructors

* UIKit updated with comments and exposed constructors

* UIKit updated with comments and exposed constructors

* UIKit updated with comments and exposed constructors

* MessageUI updated with comments and exposed constructors

* Intents updated with comments and exposed constructors

* ClassKit updated with comments and exposed constructors

* MultiPeerConnectivity updated with comments and exposed constructors

* NetworkExtension updated with comments and exposed constructors

* NotificationCenter updated with comments and exposed constructors

* AssetsLibrary updated with comments and exposed constructors

* Contacts updated with comments and exposed constructors

* ContactsUI updated with comments and exposed constructors

* CoreServices updated with comments and exposed constructors

* CloudKit updated with comments and exposed constructors

* CoreTelephony updated with comments and exposed constructors

* FileProvider and LocalAuthentication updated with comments and exposed constructors

* QuickLook updated with comments and exposed constructors

* ReplayKit updated with comments and exposed constructors

* Security updated with comments and exposed constructors

* Social updated with comments and exposed constructors

* SystemConfiguration updated with comments and exposed constructors

* MapKit updated with comments and exposed constructors

* UserNotifications updated with comments and exposed constructors

* SafariServices updated with comments and exposed constructors

* EventKit updated with comments and exposed constructors

* EventKitUI updated with comments and exposed constructors

* PassKit updated with comments and exposed constructors

* Vision updated with comments and exposed constructors

* Webkit updated with comments and exposed constructors

* WatchKit updated with comments and exposed constructors

* HomeKit updated with comments and exposed constructors

* HealthKit updated with comments and exposed constructors

* SpriteKit updated with comments and exposed constructors

* CoreText updated with comments and exposed constructors

* SceneKit updated with comments and exposed constructors

* SpriteKit updated with comments and exposed constructors

* CoreAudioKit updated with comments and exposed constructors

* AudioToolBox updated with comments and exposed constructors

* AVKit updated with comments and exposed constructors

* Photos updated with comments and exposed constructors

* iAD updated with comments and exposed constructors

* StoreKit updated with comments and exposed constructors

* PhotosUI updated with comments and exposed constructors

* GameController updated with comments and exposed constructors

* IOSurface updated with comments and exposed constructors

* GameKit updated with comments and exposed constructors

* ARKit updated with comments and exposed constructors

* GameplayKit updated with comments and exposed constructors

* ARKit updated with comments and exposed constructors

* CoreML updated with comments and exposed constructors

* GLKit updated with comments and exposed constructors

* OpenGLS updated with comments and exposed constructors

* Metal updated with comments and exposed constructors

* MetalKit updated with comments and exposed constructors

* MetalPerformanceShaders updated with comments and exposed constructors

* CoreVideo updated with comments and exposed constructors

* ModelIO updated with comments and exposed constructors

* Another run with updated bro-gen:
- applied inherited configuration
- fixed comments in deprecated messages
- fixed automaticaly generated enum (were start of entries were cut)

* ARKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* AudioToolBox polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* AVFoundation polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* ClassKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* CloudKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* CoreBluetooth polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* CoreData polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* CoreImage polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* CoreML polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* CoreSpotLight polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* EventKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* FileProvider polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* Foundation polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* GameController polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* GameKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* GamePlayKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* HealthKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* HomeKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* Intents polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* IOSurface polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* MapKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* MediaPlayer polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* Messages polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* Metal polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* MetalPerformanceShaders polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* ModelIO polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* NetworkExtension polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* PassKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* Photos&PhotosUI polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* QuickLook polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* ReplayKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* SceneKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* SpriteKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* StoreKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* UIKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* UserNotifications polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* Vision polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* WebKit polished with recent bro-gen (fixed enums, removed `with` from methods, etc)

* new iOS12 frameworks: IdentityLookup & IdentityLookupUI

* new iOS12 framework: AuthServices

* new iOS12 framework: CarPlay

* new iOS12 framework: NaturalLanguage

* foundation: removing default constructor from NSDataDetector as parent NSRegularExpression forced to be without it

* Security extended with iOS12 ARC style object e.g. sec_sertificate

* new iOS12 framework: Network

* UIKit: first run of inherited initializers done proper Java way

* uikit optimized (removed pattern init*) to allow better initializer inheritance

* inherited initializers converted to roper Java way #1

* inherited initializers converted to roper Java way #2

* inherited initializers converted to roper Java way #3

* MetalPS reworked inherited configuration and inherited initializers converted to roper Java way #3

* inherited initializers converted to roper Java way #5

* CoreTelephony updated to ios12.1

* GameController updated to ios12.1

* IdentityLookup updated to ios12.1

* Intents updated to ios12.1

* UIKit updated to ios12.1

* Security updated to ios12.1

* MetalPerformanceShaders updated to ios12.1

* * added workaround to fix #336 (crash when using WKWebView navigation delegate)

* * added manually entered code to provide setAttributes api with high level containers to close #243

* * this commit fixes `java.lang.IllegalArgumentException: No @Marshaler found for return type of @GlobalValue method` which happens for globals that operates with blocks. Following code crashes compilation without this change. It wasn't found early as nobody had been using global value that returns a block.
```
    @GlobalValue(symbol="_nw_parameters_configure_protocol_default_configuration", optional=true)
    public static native @block VoidBlock1<NWProtocolOptions> DEFAULT_CONFIGURATION();
```

* Network framework:
- generated constant blocks for configurations that were missing
- added string marshalers to make api more friendly
- fixed underlines in names
- NWParameters.copy renamed to NWParameters.copyParameters as otherwise it cause bridge synthetic copy method generated from NSObject that caused `@bridge annotated method must be native` on it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment