dart Flutter发布apk不工作correcty但调试应用程序工作正常

1szpjjfi  于 2023-07-31  发布在  Flutter
关注(0)|答案(7)|浏览(127)

我已经建立了一个简单的meme/照片编辑器应用程序使用flutter.它是完美的调试模式下工作,但它不是在发布模式下工作.有一个容器在我的应用程序,用于显示用户图像加载使用图像拾取器.当我选择图像在调试应用程序中显示,但当尝试在发布版本它只显示一个空白的容器,它的路线也被改变.我已经尝试flutter clean,并已添加Internet permission清单文件.但没有纠正这个问题.
此外,我已经尝试了应用程序捆绑和拆分apks,但问题仍然存在。有没有任何方法可以生成并上传调试apk到playstore而不会出现任何安全问题?
这是有问题的部分...它在调试模式下工作正常,但在发布模式下不正常。

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

字符串

kcwpcxri

kcwpcxri1#

根据您所分享的内容(并不多),我可以假设您错过了在main清单上添加INTERNET权限。
通常创建3个清单。打开你的android/app/src文件夹,你会看到3个子文件夹:

  • 调试
  • 轮廓
  • 主要

这很容易被误解,并把许可证在错误的清单,我已经有几次!

jaql4c8m

jaql4c8m2#

”我有这个确切的问题。我用这些方法解决了这个问题:**
1.添加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

字符串
1.在应用级build.gradle中将proguard添加到buildTypes

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
}


1.编辑Kotlin主活动文件:

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);
  }
}

snz8szmq

snz8szmq3#

当我用容器更换扩展后问题消失了。.谢谢支持

ljsrvy3e

ljsrvy3e4#

这可能是因为您的应用需要互联网连接,但您尚未在AndroidManifest.xml文件中指定此权限:yourProject/android/app/src/main/AndroidManifest.xml
确认是否启用了internet权限。

之前:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application...

字符串

现在:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<application..


希望这能帮上忙。

shstlldc

shstlldc5#

嗨,Axen_Ranges,对不起,我来晚了。今天我也经历了同样的行为。修复方法是从我的UI代码中删除Expanded()。某些类型的布局似乎有问题。
之前我有一个Column()和一个Expanded()。这个管用!:)

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

字符串
我把Column()改成了Scrollbar()和ListView(),仍然包含Expanded(),这不起作用!:(

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,
      ],
    ),
  )


这里的问题是flutter框架并没有告诉您存在问题。它在调试模式下工作没有问题。但在释放模式下,它只显示一个空容器。

vmdwslir

vmdwslir6#

我的问题是通过删除扩展的小部件解决的,
我的调试模式是完美的工作,但当我发布的APK包发布主屏幕不显示图像和细节,所以我只是删除容器扩展部件,它为我工作.

yzuktlbb

yzuktlbb7#

从UI代码中删除不必要的Expanded()

相关问题