Vorotnyak_Nazar Vorotnyak_Nazar - 2 months ago 17
Android Question

Xamarin android. Works in debug. Doesn't work in release (createSubDecor null reference)

Application works in debug mode without

shared runtime
option and with
link sdk and user assemblies

In release mode it doesn't work. Tried different link options and enabling
shared runtime


I am using 23.4.0.1 android.support library

Here is log:


java.lang.NullPointerException 09-17 21:25:33.987 I/MonoDroid( 3557):
at
android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:491)
09-17 21:25:33.987 I/MonoDroid( 3557): at
android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
09-17 21:25:33.987 I/MonoDroid( 3557): at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
09-17 21:25:33.991 I/MonoDroid( 3557): at
android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
09-17 21:25:33.991 I/MonoDroid( 3557): at
md5cc34a7196a93e5e13d1bb5964f64c350.MainActivity.n_onCreate(Native
Method) 09-17 21:25:33.991 I/MonoDroid( 3557): at
md5cc34a7196a93e5e13d1bb5964f64c350.MainActivity.onCreate(MainActivity.java:30)
09-17 21:25:33.991 I/MonoDroid( 3557): at
android.app.Activity.performCreate(Activity.java:5231) 09-17
21:25:33.995 I/MonoDroid( 3557): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-17 21:25:33.995 I/MonoDroid( 3557): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
09-17 21:25:33.995 I/MonoDroid( 3557): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
09-17 21:25:33.995 I/MonoDroid( 3557): at
android.app.ActivityThread.access$800(ActivityThread.java:135) 09-17
21:25:33.995 I/MonoDroid( 3557): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-17 21:25:33.995 I/MonoDroid( 3557): at
android.os.Handler.dispatchMessage(Handler.java:102) 09-17
21:25:33.999 I/MonoDroid( 3557): at
android.os.Looper.loop(Looper.java:136) 09-17 21:25:33.999
I/MonoDroid( 3557): at
android.app.ActivityThread.main(ActivityThread.java:5017) 09-17
21:25:33.999 I/MonoDroid( 3557): at
java.lang.reflect.Method.invokeNative(Native Method) 09-17
21:25:33.999 I/MonoDroid( 3557): at
java.lang.reflect.Method.invoke(Method.java:515) 09-17 21:25:33.999
I/MonoDroid( 3557): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-17 21:25:33.999 I/MonoDroid( 3557): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 09-17
21:25:33.999 I/MonoDroid( 3557): at
dalvik.system.NativeStart.main(Native Method)

FATAL EXCEPTION: main 09-17 21:25:34.011 E/AndroidRuntime( 3557):
Process: com.SlaveryGames.PhoneChecker, PID: 3557 09-17 21:25:34.011
E/AndroidRuntime( 3557): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{com.SlaveryGames.PhoneChecker/md5cc34a7196a93e5e13d1bb5964f64c350.MainActivity}:
java.lang.NullPointerException 09-17 21:25:34.011 E/AndroidRuntime(
3557): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.app.ActivityThread.access$800(ActivityThread.java:135) 09-17
21:25:34.011 E/AndroidRuntime( 3557): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.os.Handler.dispatchMessage(Handler.java:102) 09-17
21:25:34.011 E/AndroidRuntime( 3557): at
android.os.Looper.loop(Looper.java:136) 09-17 21:25:34.011
E/AndroidRuntime( 3557): at
android.app.ActivityThread.main(ActivityThread.java:5017) 09-17
21:25:34.011 E/AndroidRuntime( 3557): at
java.lang.reflect.Method.invokeNative(Native Method) 09-17
21:25:34.011 E/AndroidRuntime( 3557): at
java.lang.reflect.Method.invoke(Method.java:515) 09-17 21:25:34.011
E/AndroidRuntime( 3557): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 09-17
21:25:34.011 E/AndroidRuntime( 3557): at
dalvik.system.NativeStart.main(Native Method) 09-17 21:25:34.011
E/AndroidRuntime( 3557): Caused by: java.lang.NullPointerException
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:491)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
md5cc34a7196a93e5e13d1bb5964f64c350.MainActivity.n_onCreate(Native
Method) 09-17 21:25:34.011 E/AndroidRuntime( 3557): at
md5cc34a7196a93e5e13d1bb5964f64c350.MainActivity.onCreate(MainActivity.java:30)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.app.Activity.performCreate(Activity.java:5231) 09-17
21:25:34.011 E/AndroidRuntime( 3557): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-17 21:25:34.011 E/AndroidRuntime( 3557): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)

Answer

Android Bug : https://code.google.com/p/android/issues/detail?id=207638

  • Compat 23.1.1, 23.3.0, 23.2.1, 23.3.0

Workaround (access Window.DecorView before base.OnCreate is called):

    protected override void OnCreate(Bundle savedInstanceState)
    {
        // https://code.google.com/p/android/issues/detail?id=207638
        #pragma warning disable CS0219
        var bugWorkAround = Window.DecorView.Handle;
        #pragma warning restore CS0219
        base.OnCreate(savedInstanceState);
        ~~~~~

Fixed(?) in 23.4.0.1+:

Note: I am still using the workaround in this version...

<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v4" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="23.4.0.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.4.0.1" targetFramework="monoandroid70" />

Note: Refer to this SO as this is where i first found the Android bug number when I was getting CreateSubDecor null reference crashes.

Comments