flutter android app freezes on the splash screen in release mode - android

I have a problem using the storage to persist the user login data .
the scenario like that : after login , I clear the app and try to reopen it again , sometimes it open and sometimes it's freezes on the splash screen.
this only happen in the release mode .
I tried to remove every package until I found the problem with using the storage after login. so I if I not login nothing freezes .
I used get_storage and shared_preferences and secured_storage packages but nothing changed .
flutter 2.10.2.
tested on real device
also this the the used packages
module:
androidX: true # Add this line.
environment:
sdk: ">=2.11.0 <3.0.0"
dependencies:
dio: ^4.0.0
get: ^4.1.4
get_storage:
flutter:
sdk: flutter
dev_dependencies:
flutter_launcher_icons: ^0.9.2
flutter_icons:
android: true
ios: false
image_path: "assets/icons/launcher_icon.png"
flutter_test:
sdk: flutter
name: delivery
description: manager App
version: 1.6.3
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
finally I decided to share the verbose hope someone can help
https://github.com/flutter/flutter/issues/98862

I had the same problem in our production app few days back. I released an update (where just a couple of tables were updated in the local app database) with Flutter 2.10.2 and many users started getting frozen launch screen.
After spending days trying to solve it, I finally downgraded the Flutter to 2.8 and released an update and the issue was gone.

I had a similar bug:
By default on Android, android:allowBackup is set to true which means that your app's data is automatically backed up to your Google Drive
The problem is when something in your data structure changes but you have an old backup with an old and incompatible data structure. When reinstalling a new version of the app which is incompatible with the old data structure which was backed up, it will freeze on the native splash screen.
I solved this by adding android:allowBackup="false" to android/app/src/main/AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...
<application
...
android:allowBackup="false"
...
</application>
</manifest>

You could install sentry_flutter in your application to capture exceptions in your release app.
Also, try moving flutter_native_splash: ^2.0.4 from dev_dependencies to dependencies.

Take you real device and connect it to you pc via cable and install release version of you app
Go-to terminal and run flutter logs to see what's going on
In some cases, may be permissions are reason. You need to specify them (don't relax because of default permissions set)

I think there should be 2 things --
first make sure you added the Internet permission and other required permissions in AndroidManifest.xml file
Second if you already defined all the required permissions then try this--
in your app/build.gradle file add these 3 lines
minifyEnabled false
useProguard false
shrinkResources false
in
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled false
useProguard false
shrinkResources false
}
}
then clean your project and try again I hope this will work and if you still faced that problem check the documentation again of flutter_native_splash package you used, also watch the video of Johannes Milke's tutorial which is already linked in the documentaion.
Thankyou.

Since the other answers haven't given any luck, I would suggest that you start by disabling everything in your app, and gradually enable portions of the app until you reproduce the problem. For example, start by replacing your MyApp() in your main() with a blank shell of an app:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent, // transparent status bar
));
await initServices();
runApp(MaterialApp(
home: Container(color: Colors.blue),
));
}
This will tell you if the problem is in your initialization or the rest of your app. If the blue screen loads, it tells you that the initialization is fine. Keep dividing your app like this until you find the part this is causing the app to hang.

I recommend you to install the flutter sdk again from scratch and try it.

Related

Flutter launcher_icon and native_splash android problem

I am beginner in flutter, and I started learning from the very beginning of creating the application and immediately encountered a problem that I cannot solve only on android. When i create packages launcher_icon and native_splash, on ios everything works as it should, but on android at the splash screen all the time it gives me only the application icon and not default splash screen as in ios.
how could i fix it to work on android?
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter_launcher_icons: ^0.10.0
flutter_native_splash: ^2.2.7
flutter_icons:
android: true
ios: true
image_path: "assets/icon_anny.png"
min_sdk_android: 21
flutter_native_splash:
color: "#fafafa"
image: assets/splash_screen.png
color_dark: "#000000"
image_dark: assets/splash_screen_dark.png
android: true
ios: true
android_gravity: fill
ios_content_mode: scaleAspectFill
I managed to solve the problem, Android 12 has a different way of showing the splash screen. It is also necessary to open a new one flutter_native_splash.yaml and there are all the instructions and it works perfectly.
You should run a command line after adding parameters to pubspec.yaml:
flutter pub run flutter_native_splash:create
I just fixed this problem today go in your project and create a flutter_native_splash.yaml and follow the instructions on https://pub.dev/packages/flutter_native_splash.

App Center force update for Android not working

i am trying to implement the force update feature using app center, i have followed their documentation found here and it doesnt seem to work at all
here's the code inside the App Class
AppCenter.start(
getApplication(), {APP SECRET HERE}, Crashes::class.java,
Distribute::class.java, Analytics::class.java
)
and i have tried uploading a build like this then downloading first, and after that i uploaded a newer version with higher version code / version name and set the checkbox for "Mandatory Update", i don't get any prompt at all to update when i start the app then.
Found the problem with the appcenter force update, AppCenter Distribute will not work on release mode if debuggable in gradle is set to true.
so make sure to leave it on false at the build type you will be testing on
debuggable false
adding this line before starting AppCenter showed me the logs that clued me to this.
AppCenter.setLogLevel(Log.VERBOSE)

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"/>
The previous solutions did not work in my case, then I tried disabling these two then it worked.
minifyEnabled false
shrinkResources false
My app was also not working in the release build and the issue is due to the shared_preferences package.
I'm getting the following error in the release build:
MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
I tried several solutions:
switching the flutter channel
tried several versions of shared_preferences
deleting the .pub-cache folder as described here https://github.com/flutter/flutter/issues/38873#issuecomment-680788165
but nothing worked.
The app worked fine in the debug build but not in the release build.
Then I tried
flutter build apk --no-shrink
flutter build appbundle --no-shrink
and the app worked fine in the release build as well. But the issue is resolved without shrinking the code.
So this needs to be fixed.
Hopefully, the Flutter team will look into the issue and will resolve that.
Edit:
Already reported the issue to the Flutter team.
https://github.com/flutter/flutter/issues/65334
I also faced the same problem. In my case the problem is not my code, the problem is the Gradle version. When I used any Gradle version greater than 4 then this problem occur. But when I reduced the Gradle version to 3.5.0 then It works fine. I also tested with Gradle 3.6.4 it also works fine.
Change this
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
}
Note: In flutter don't always upgrade your Gradle version
I just changed :
dependencies {
classpath 'com.android.tools.build:gradle:**4.1.0**'
}
TO
dependencies {
classpath 'com.android.tools.build:gradle:**3.5.0**'
}
Then
flutter clean
flutter build apk --release
it will work for sure.
Building with flutter build apk --no-shrink solved to me
replacing classpath 'com.android.tools.build:gradle:4.1.0' with
classpath 'com.android.tools.build:gradle:3.5.0'
in android/build.gradle file fixed the problem for me
it's really works for me and you can try----
use -> SharedPreferences.setMockInitialValues({});
void main() {
SharedPreferences.setMockInitialValues({});
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor: Colors.indigo[900], // navigation bar color
statusBarColor: Colors.indigo[900],
systemNavigationBarIconBrightness: Brightness.light));
runApp(MyApp());
}
Maybe u have forgetten to add this line of code on MainActivity.java
`#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this.getFlutterEngine());
}`
It worked on me

Flutter InAppPurchase products not showing on release build

I've added the in_app_purchase flutter package and was working fine on debug (followed the setup instructions etc.) but when I build the release apk it cannot find any of the products, all are returned under notFoundIDs without stating any error.
I've tried flutter clean.
Also Tried using the exact same buildTypes config on both, same result.
Any idea why the release build would not return any queried items? Thanks.
Well, found the problem,
apparently queryProductDetails([...]) needs to be called after isAvailable() returns true.
I had both calls running asynchronously and for some reason it was working in debug mode but not release.
You need to use a reserved SKU for the test: android.test.purchased
const List<String> _kProductIds = <String>[
'android.test.purchased'
];
ProductDetailsResponse productDetailResponse =
await _connection.queryProductDetails(_kProductIds.toSet());

Remove console logs from ionic app (release)

How do I get rid of console logs from an ionic 2 release application?
I am developing an ionic 2 app. When I build the release apk and run on a device, I can still attach to the process from chrome://inspect, and view console logs. I have tried removing the cordova-plugin-console, but that makes no difference.
Edit: I found a package that can remove console logs: https://www.npmjs.com/package/remove-console-logs
Just not sure how I can use it to automatically remove them when I build release. Please help.
Thanks.
You can use uglifyjs.config.js for drop all console logs when is a production build.
1 . Copy uglifyjs.config.js from node_modules into your project folder
2 . In the new config file set the flag drop_console to true if production
var isProduction = process.env.IONIC_ENV === 'prod';
...
compress: {
drop_console: isProduction
}
3 . Set your custom configuration in the package.json
"config": { "ionic_uglifyjs": "uglifyjs.config.js" },
And that's all !
If you can still connect with the debugger then it is not a release build - sounds like you may be unintentionally installing the debug build OR connecting to some other app.
EDIT; Above is not necessarily true - there are instances where you can debug the js/html/css content via chrome in a release build ; specifically if the webview debuggability flag is set in code / not set by the build system etc. - this flag is seperate from the application debug flags so if not properly set you will be able to debug a "release" build / not be able to debug a "debug" build - see remote debugging webviews.
END OF EDIT.
( note you have to sign a release build before it will install )
Is it possible the release install failed and you're still looking at a previous debug build ?
Assuming you have a release build and can't connect to see logs via chrome inspect then ;
console.log calls will still be in the release build unless you comment them out - and possibly visible in other ways eg. android tools sdk\tools\monitor - The only way to be sure they aren't visible is to comment them out. You could use something like ;
console.log = function(){} ;
at the end of your device ready function after any plugins have done anything they're likely to do - though there's still no 100% guarantee with this as a badly behaving 3rd party plugin or library might reassign it later and then your calls will still happen - to be absolutely sure you will need to comment them out.
Have you tried remove console logs ?
cordova plugin rm cordova-plugin-console
Then
cordova build --release android

Categories

Resources