microsoftconnect / intune-app-wrapping-tool-android

Use the Intune App Wrapping Tool for Android to enable Android apps to be managed by Microsoft Intune
29 stars 11 forks source link

Flutter support? #36

Closed JosephNK closed 4 years ago

JosephNK commented 4 years ago

Describe the bug: I created a basic project with Flutter and tested MDM using a wrapping tool. As a wrapping tool, apk was output without failure. After uploading the apk to Intune and downloading and running the app, the app crashes. Please tell me how to fix it.

Screenshots and logs:

04-07 10:36:20.632 22915 22915 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onUserLeaveHint()' on a null object reference
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at io.flutter.embedding.android.FlutterActivity.onUserLeaveHint()
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.app.Activity.performUserLeaving(Activity.java:7146)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnUserLeaving(Instrumentation.java:1340)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.app.ActivityThread.performUserLeavingActivity(ActivityThread.java:4060)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4036)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.app.ActivityThread.-wrap18(ActivityThread.java)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:154)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:6682)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
04-07 10:36:20.632 22915 22915 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
rygo-msft commented 4 years ago

This appears to be related code shrinking in flutter. While we haven't determined why this failure is occurring, it appears that it doesn't occur when code shrinking is disabled.

@JosephNK, can you try building your app with --no-shrink then rewrap and see if that mitigates the issue?

JosephNK commented 4 years ago

@rygo-msft

flutter build apk --no-shrink 

I tried.. but.. same error. :(

buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

Note that there is no proguard setting.

rygo-msft commented 4 years ago

@JosephNK did you try cleaning the build prior to using --no-shrink. I believe that flutter might not switch between shrink/no-shrink incrementally so you may still have a shrinked build if you don't clean first.

If this doesn't mitigate the issue, would you be willing to share a sample app that reproduces the issues when built with debug or --no-shrink? We are able to reproduce with shrinking enabled, but want to ensure we are investigating the same root issue.

JosephNK commented 4 years ago

@rygo-msft I invited you to my private GitHub. I tried clean, but the error is the same. :( Projects created with flutter default create are also on github. For reference, the apk file is at the link below. https://github.com/JosephNK/flutter_mdm_test/tree/master/archive Please also refer to the README.md file. https://github.com/JosephNK/flutter_mdm_test/blob/master/README.md Thank you :)

JosephNK commented 4 years ago

@rygo-msft please check the reply link. :)

rygo-msft commented 4 years ago

We have a fix for this that will ship in our next release. The updated App Wrapper release is targeted for mid-June

paulpopiel commented 4 years ago

Hi @rygo-msft , we have this exact same issue. Can confirm that we have been using --no-shrink as well and still face this error.

Has the fix that you mentioned been shipped yet? we are working off the current latest version and still have this issue.

This is quite critical for us.

paulpopiel commented 4 years ago

@rygo-msft also if it isnt too much trouble - could you provide an issue link, or a brief description, of what the problem is/was?

rygo-msft commented 4 years ago

The fix is now available in the latest release https://github.com/msintuneappsdk/intune-app-wrapping-tool-android/releases/tag/1.0.2963.3

When we block app launch due to conditional launch requirements we skip the call to the app implementations of lifecycle functions, however, we were missing handling for onUserLeaveHint() which was being called even though onCreate() was skipped.

The fix was to ensure that app implementations of onUserLeaveHint() is not called if the app implementation of onCreate() was not called.