Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharedPreferences not instantiating in release build

In my flutter application I have implemented a an onboarding view. As it should load only once, I have used shared preferences to store an integer to indicate that onboarding is already shown. When I run the application in debug mode everything works perfectly. But when I build the release version of it, it doesn’t work.

And also my application uses firebase mobile authentication. I am mentioning this since it may be a reason as well.

The code:

case InitializeEvent:
        SharedPreferences prefs = await SharedPreferences.getInstance();
        int initScreen = prefs.getInt(SharedPrefUtil.INIT_SCREEN);
        await prefs.setInt(SharedPrefUtil.INIT_SCREEN, 1);
        if (initScreen == 1) {
          add(CheckAppConfigEvent());
        } else {
          yield state.clone(page: RootState.ONBOARDING_PAGE);
        }
        yield state.clone(loading: false);
        break;

So in the above code, if I comment initializing shared pref, reading and writing lines and set true or false in if else statement everything works fine in release build. That’s why I think the issue is in initializing shared preferences.

And also I have given permission only for internet. Am I missing any permission in AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
like image 982
Azeem Muzammil Avatar asked Jul 22 '20 11:07

Azeem Muzammil


1 Answers

The previous solutions did not work in my case, then I tried disabling these two then it worked.

minifyEnabled false shrinkResources false

like image 54
Javokhir Sherbaev Avatar answered Sep 21 '22 06:09

Javokhir Sherbaev