Reputation: 427
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,),
),
)
Upvotes: 4
Views: 19919
Reputation: 236
It's probably because your app requires internet connection, but you haven't specified this permission in your AndroidManifest.xml file at: YOUR_PROJECT/android/app/src/main/AndroidManifest.xml
Confirm whether the internet permission is enabled.
Before:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application...
Now:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application..
I hope this helps.
Upvotes: 6
Reputation: 460
I have found a very good solution for this .It also work for packages like autoscale_tabbarview that work perfectly fine on debug mode but causes problem in release mode. Just like the above comment add proguard for all plugins.
In your Flutter project's 'android/app' directory, create a file named 'proguard-rules.pro' if it doesn't already exist.
#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.** { *; }
-keepattributes *Annotation*
In your 'android/app/build.gradle' file, make sure that the proguardFiles directive includes the custom rules file you created. The proguardFiles line should look like this:
buildTypes {
release {
signingConfig signingConfigs.debug
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
In your 'MainActivity.java' file, add the below code and for .kt file you can see above comments or can ask chatgpt to convert into .kt file
package com.example.pettera_project;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine;
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
And don't forget to change the package name.
Upvotes: 1
Reputation: 15
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.
Upvotes: 0
Reputation: 157
I had this exact problem. I solved it with these solutions:
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
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
}
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);
}
}
Upvotes: 4
Reputation: 1648
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.
Upvotes: 0
Reputation: 427
Problem disappeared when I replaced the expanded with container..Thanks for support
Upvotes: 1
Reputation: 5162
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:
It's easy to be mistaken and put the permission in the wrong Manifest, I've been there some times!
Upvotes: 14