Home Features Docs Blog Support GitHub

Problem with proguard and notifications processing


(Nicolas Prugne) #1

Hello,

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
      readUserInfoAndLaunchMainViewController(userInfo);
  } 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){
      readUserInfoAndLaunchMainViewController(userInfo);
  }
}

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

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,
Nicolas


(Nicolas Prugne) #3

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 ?

Regards,
Nicolas


(Roland Vigh - Migeran) #4

Hi!

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

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

Best Regards,
Roland


(Nicolas Prugne) #5

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,
Nicolas


#6

You could try https://discuss.multi-os-engine.org/t/script-automatically-verify-missing-proguard-rules-when-proguardlevel-app which could possibly generate a finer proguard rule and hopefully reduce your app size for a little bit more.


(Nicolas Prugne) #7

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.

Regards,
Nicolas