Home Features Docs Blog Support GitHub

JNI DETECTED ERROR IN APPLICATION: java_array == null

There is method.

  @Override
  public boolean applicationContinueUserActivityRestorationHandler(UIApplication application, NSUserActivity userActivity, @ObjCBlock(name = "call_applicationContinueUserActivityRestorationHandler") Block_applicationContinueUserActivityRestorationHandler restorationHandler) {
    NSURL url = userActivity != null ? userActivity.webpageURL() : null;
    return doOpenUrl(url, fromApplication(application));
  }

When it run, app crashed with error:


How can I avoid this?

Hi,

Can you provide us with a full project to reproduce this issue?

Best Regards,
Gergely

actually it crashes even when I just return true in applicationContinueUserActivityRestorationHandler method.


If I don’t overrite that method then no crash on opening url, but no useful business logic too.
Ok, I’ll try to provide you sample application.

Is there any workaround for it? Can I write some jni code to handle this selector?

class MoeLauncher extends NSObject implements UIApplicationDelegate {      
  @Selector("application:continueUserActivity:restorationHandler:")
  public native boolean applicationContinueUserActivityRestorationHandler(UIApplication application, NSUserActivity userActivity,  @ObjCBlock(name = "call_applicationContinueUserActivityRestorationHandler") Block_applicationContinueUserActivityRestorationHandler restorationHandler);
......
}

If I use “native”, then that method doesn’t invoked.

There is simple sample to reproduce this bug:

import apple.NSObject;
import apple.foundation.*;
import apple.uikit.*;
import apple.uikit.c.UIKit;
import apple.uikit.protocol.UIApplicationDelegate;

import org.moe.natj.general.Pointer;
import org.moe.natj.general.ann.RegisterOnStartup;
import org.moe.natj.objc.ann.Selector;

@RegisterOnStartup
public class Main extends NSObject implements UIApplicationDelegate {

  public static void main(String[] args) {
    UIKit.UIApplicationMain(0, null, null, Main.class.getName());
  }

  @Override
  @Selector("application:didFinishLaunchingWithOptions:")
  public boolean applicationDidFinishLaunchingWithOptions(UIApplication application, NSDictionary<?, ?> launchOptions) {
    System.out.println("Hello");

    UIWindow window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen().bounds());
    window.setRootViewController(UIViewController.alloc().init());
    window.makeKeyAndVisible();

    return true;
  }

  @Override
  public boolean applicationContinueUserActivityRestorationHandler(UIApplication application, NSUserActivity userActivity, Block_applicationContinueUserActivityRestorationHandler restorationHandler) {
    return false;
  }

  protected Main(Pointer peer) {
    super(peer);
  }
}

you should also set correct provisioning profile and Entitlements.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.developer.associated-domains</key>
	<array>
		<string>applinks:mysampl.es</string>
	</array>
</dict>
</plist>

and open link mysampl.es. Then it crash:

Hi,

thanks, we will take a look.

Best Regards,
Gergely

Hi,

@ObjCBlock(name = “call_applicationContinueUserActivityRestorationHandler”) annotation is missed in the method. Please add to method, see:

    @Selector("application:continueUserActivity:restorationHandler:")
    public boolean applicationContinueUserActivityRestorationHandler(UIApplication application,
                                                                      NSUserActivity userActivity,
                                                                      @ObjCBlock(name = "call_applicationContinueUserActivityRestorationHandler") Block_applicationContinueUserActivityRestorationHandler restorationHandler) {
        return false;
    }

Best Regards,
Roland

Same crash with that @ObjCBlock
no difference

My test project worked
ifaddrs.zip (77.3 KB)

Can you confirm that the annotation is still there after the retrolambda phase (build/moe/main/retro/output)?

Yes, annotation still here.
Your sample works. My sample doesn’t work.
I found where is problem - proguard. I use proguard ‘all’ with rules(moe-specific part is here):

#moe
-keep interface apple.uikit.protocol.UIApplicationDelegate { *; }
-keepclassmembers class ** {
  @org.moe.natj.objc.ann.** public *;
}

Do you have recommended proguard rules? To avoid similar problems in future?

fixed it by add

-keepattributes RuntimeVisibleParameterAnnotations