Problem with proguard and notifications processing


I have recently tried to custom my proguard.append.cfg file to reduce the size of the IPA generated by my MOE project. Everything works normally and the size of my IPA has drastically decreased. However, I have now a very specific problem which occurs when a notification is received and when the user tap on it to launch the app.

I have implemented the method “applicationDidReceiveRemoteNotificationFetchCompletionHandler” in my Main class like below:

public void applicationDidReceiveRemoteNotificationFetchCompletionHandler(
            UIApplication application,
            NSDictionary<?, ?> userInfo,
            @ObjCBlock(name = "call_applicationDidReceiveRemoteNotificationFetchCompletionHandler")
                    Block_applicationDidReceiveRemoteNotificationFetchCompletionHandler completionHandler) {
  if(application.applicationState() == UIApplicationState.Active) {
      //app is currently active, can update badges count here
  } else if(application.applicationState() == UIApplicationState.Background){
      //app is in background, if content-available key of your notification is set to 1,
      // poll to your backend to retrieve data and update your interface here

  } else if(application.applicationState() == UIApplicationState.Inactive){

When the proguard level is set to “app”, this piece of code works as expected but when I set it to “all”, I cannot start my app by clicking on a notification anymore. The app crashes and I get the following stack trace in the logs:

art I  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/] Exception in AnnotationFactory.createAnnotation
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/] JNI DETECTED ERROR IN APPLICATION: java_array == null
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]     in call to GetArrayLength
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]     from long apple.uikit.UIApplication.applicationState()
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/] "main" prio=5 tid=1 Runnable
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   | group="main" sCount=0 dsCount=0 obj=0x10a8e40a0 self=0x11c01ac00
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   | sysTid=1344421 nice=-1 cgrp=default sched=1/31 handle=0x1b734ab80
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   | state=? schedstat=( 0 0 0 ) utm=0 stm=0 core=0 HZ=100
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   | stack=0x16fa08000-0x16fa10000 stackSize=1008KB
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   | held mutexes= "mutator lock"(shared held)
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   at apple.uikit.UIApplication.applicationState(Native method)
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   at com.digitalplumecompany.boostyourteam.Main.applicationDidReceiveRemoteNotificationFetchCompletionHandler(
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   at apple.uikit.c.UIKit.UIApplicationMain(Native method)
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/]   at com.digitalplumecompany.boostyourteam.Main.main(
art F  2330 1344421 /Users/rolandvigh/public-repo/aosp/art/runtime/] 

Here is the full stack trace: stacktrace.txt (16.6 KB)

It seems that the method “apple.uikit.UIApplication.applicationState()” cannot be called. Am I missing a rule in my proguard.append.csv file ? (proguard.append.txt (1.3 KB))

Best regards,

I am currently using the MOE IDE plug-in for Android Studio 1.4.3 and the gradle plug-in 1.4.4. The problem is still there… :frowning: Any ideas ? Is it a bug from MOE ?



Please try append this proguard settings to proguard.append.cfg:

-keep class apple.usernotifications.** { *; }
-keep class libcore.reflect.AnnotationMember { *; }

Best Regards,

Hi Roland!

Thanks for your help, I have tried to add these two lines:

-keep class apple.usernotifications.** { *; }
-keep class libcore.reflect.AnnotationMember { *; }

But nothing changed. However I have understood what you were trying to suggest and I have added this line instead:

-keep class apple.uikit.** { *; }

And now it’s all good! :smiley:

The size of my IPA is optimized and I can launch my app by clicking on notifications.

Best Regards,

You could try which could possibly generate a finer proguard rule and hopefully reduce your app size for a little bit more.

Hi Noisyfox!

Thanks for your script which is really helpful, but it only generates the rules for missing delegates. Here I needed to keep some classes from the apple.uikit package and the script did not check for them.