Home Features Docs Blog Support GitHub

Too many crashes for JNIEnv:CallStaticObjectMethod

When Apple require App to add AppTrackingTransparency framework, and must call ATTrackingManager requestTrackingAuthorizationWithCompletionHandler before ad request.
Solution and issues are here.
Solution 1: Try to call Moe ATT API, no ATT framework api in MOE plugin. Result: failed.
Solution 2: Try to generate ATT API by ATT framework, failed to generate. Result: failed.
Solution 3: Try to OC call ATTracking + binding + binding call java init admob ad + java Admob ads
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
dispatch_async(dispatch_get_main_queue(), ^{
// must call in the main thread, will call initWithFrame
//[AdsManager initAds]; //
_adsManager = [[AdsManager alloc] init];
[_adsManager initAds]; // moe bridge native to call java
});
}

MOE bridge code
public class AdsManagerBridge extends NSObject {

static {
    NatJ.register();
}

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

@Selector("initAds")
public void initAds() {

    //IOSMoePlatform.initAds();

    IOSMoePlatform.getInstance().grantAdRequest();
}

}
and then, too many crash JNIEnv:CallStaticObjectMethod.

Solution 4: Using jni call
iOSMoePlatformClass = (*env)->FindClass(env, “com/XXXXX/IOSMoePlatform”);
initAdsMethod = (*env)->GetStaticMethodID(env, iOSMoePlatformClass, “initAds”, “()V”);
Work fine in xcode debug. 100% Crash when published on Apple Store online.

How to debug and fix this issue.

I had this issue a few months ago, so I ended up tracking down the ATT framework on my Mac in the iOS libraries and I generated bindings for it. They work fine for me so I’ve zipped and attached them here if you want to give them a try:

apptrackingtransparency.zip (5.4 KB)

Just add these somewhere in your Java source folder, then make sure you add the ATT framework to your project’s frameworks in Xcode and you should be good to go.

Thanks for your share, I am trying.
Could you share the nbc file, I failed to generate the java bindings. apptracking_nbc

Do you know why [JNIEnv:CallStaticObjectMethod] crash? I don’t catch the crash in my test device when I am debugging. Firebase Crashlytics show too many crashes cause the CallStaticObjectMethod.

Here’s the nbc file: att.nbc (399 Bytes)

Keep in mind that you have to fill in the path to the actual framework file. I think I found it at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AppTrackingTransparency.framework and then I just copied it to an easier-to-find location and pointed the Framework path to that.

Sorry, no clue about the crashes. But if you use the bindings, you can make calls to things like ATTrackingManager.requestTrackingAuthorizationWithCompletionHandler() without having to do anything complicated like the JNI solution. No issues with it crashing for me and I’ve updated multiple apps on the App Store with my ATT code.

Same way, but failed to generate binding. I tried your nbc file, the same errors.
generate binding error
xcode version is 12.5.1

Ah I see. I get those “errors” all the time too, but they’re more like warnings. Only a fatal error stops it from generating the bindings in my experience. The ones about “attributes may not be specified on a category” are harmless. Don’t know why, but it’s been that way for a while now with the MOE plugin.

You should be able to find your generated bindings in your source folder despite the errors.

Thanks for your info. No any generated bindings in my source folder.

I’ve updated app on the Apple Store with your ATT code. Fixed the jni crashes.