Flutter release apk not working correcty but debug app works fine

Viewed 4256

I've built simple meme/photo editor app using flutter.It is working perfectly in debug mode but It's not working in release mode.There is a container in my app which is used to show user image loaded using image picker.When I select image in debug app it's showing but when tried it in release version It shows only a blank container and also it alignments are changed.I've tried flutter clean and have added the Internet permission to manifest file.But nothing correct that issue.

Also I've tried app bundle and split apks but Issue is remaining.Is there any method to generate and upload debug apk to playstore without getting any security issues?

This is the part with issues...It is working correctly in debug but not in release mode.

 Center(child: Stack(
           children: <Widget>[
             _image != null ?  Expanded(
                       child: Container(
                       child: Image.file(
                        _image,
                        height: 400,
                        width: 400,
                        fit: BoxFit.cover,),
                              ),
                            )
5 Answers

By what you've shared (which is not a lot) I can assume you've missed adding the INTERNET permission on the main manifest.

Usually 3 manifests are created. Open your android/app/src folder, you'll see 3 subfolders:

  • debug
  • profile
  • main

It's easy to be mistaken and put the permission in the wrong Manifest, I've been there some times!

I had this exact problem. I solved it with these solutions:

  1. Add android/app/proguard-rules.pro

    #Flutter Wrapper
    -keep class io.flutter.app.** { *; }
    -keep class io.flutter.plugin.**  { *; }
    -keep class io.flutter.util.**  { *; }
    -keep class io.flutter.view.**  { *; }
    -keep class io.flutter.**  { *; }
    -keep class io.flutter.plugins.**  { *; }
    -keep class androidx.lifecycle.** { *; } 
    -keep @interface com.google.gson.annotations.SerializedName
    -keep @interface com.google.gson.annotations.Expose
    -keepattributes *Annotation*
     #https://github.com/flutter/flutter/issues/58479
     #https://medium.com/@swav.kulinski/flutter-and-android-obfuscation-8768ac544421
    
  2. add proguard to buildTypes in app level build.gradle

    buildTypes {
    release {
        profile {
            matchingFallbacks = ['debug', 'release']
        }
    minifyEnabled true
    useProguard true
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    signingConfig signingConfigs.release
    }
    }
    lintOptions {
    disable 'InvalidPackage'
    checkReleaseBuilds false
    }
    
  3. edit the kotlin main activity file:

    import androidx.annotation.NonNull;
    import io.flutter.embedding.android.FlutterActivity
    import io.flutter.embedding.engine.FlutterEngine
    import io.flutter.plugins.GeneratedPluginRegistrant
    
    class MainActivity: FlutterActivity() {
         override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
          GeneratedPluginRegistrant.registerWith(flutterEngine);
      }
    }
    

Problem disappeared when I replaced the expanded with container..Thanks for support

Hi Axen_Ranges sorry I am late to the party. Today I experienced the same behavior. The fix was to remove the Expanded() from my UI code. It seems there is a problem with some types of layouts.

Earlier I had a Column() with an Expanded(). This works! :)

 body: Column(
    children: <Widget>[
      SizedBox(height: 30.0),
      logoSection,
      logoTextSection,
      Expanded(
        child: Column(children: [
          userImageSection,
          infoTextSection,
        ])
      ),
      pleaseConfirmSection,
      buttonSection,
      ],
    ),
  )

I changed the Column() into a Scrollbar() with a ListView(), still containing the Expanded(), this does not work! :(

body: Scrollbar(
    isAlwaysShown: true,
    controller: _scrollController,
    child: ListView(
      controller: _scrollController,
      primary: false,
      children: <Widget>[
        SizedBox(height: 30.0),
        logoSection,
        logoTextSection,
        Expanded(   // This Expanded() does not work with Scrollbar() or ListView() removing it fixes everything :)
          child: Column(
            children: [
              userImageSection,
              infoTextSection,
            ]
          )
        ),
        pleaseConfirmSection,
        buttonSection,
      ],
    ),
  )

The problem here is that the flutter framework does not tell you that there is a problem. It works no problem in debug mode. But in release mode it only shows an empty container.

My problem was solved by removing expanded widget,

My debug mode was working perfect but when I release Apk bundle to publish the main screen was not showing images and detail so I just remove Expanded widget by container and it's working for me.

Related