Flutter版本APK无法正常工作,但调试应用程序正常

时间:2020-06-29 06:31:45

标签: flutter dart

我使用flutter构建了一个简单的meme /照片编辑器应用程序。它在调试模式下可以正常运行,但在发布模式下却不起作用。我的应用程序中有一个容器,用于显示使用图像选择器加载的用户图像。当我在调试应用中选择图像时,它会显示,但是在发行版中尝试它时,它只会显示一个空白容器,而且对齐方式也会发生变化。我尝试过flutter clean并将Internet permission添加到清单文件但是,没有什么能解决这个问题。

我还尝试了应用程序捆绑和拆分apk,但是问题仍然存在。是否有任何方法可以生成调试apk并将其上传到playstore,而不会遇到任何安全问题?

这是有问题的部分...它可以在调试中正常工作,但不能在发布模式下工作。

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

4 个答案:

答案 0 :(得分:2)

我遇到了这个问题。我用以下解决方案解决了这个问题:

  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
    
  2. 向应用级 build.gradle 中的 buildTypes 添加 proguard

    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. 编辑 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);
      }
    }
    

答案 1 :(得分:1)

根据您共享的内容(并不多),我可以假设您错过了在INTERNET清单上添加main权限的情况。

通常会创建3个清单。打开android/app/src文件夹,您将看到3个子文件夹:

  • 调试
  • 个人资料
  • 主要

很容易被人误解,然后将许可放到错误的清单中,我去过那里几次!

答案 2 :(得分:0)

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

答案 3 :(得分:0)

您好Axen_Ranges对不起,我参加聚会很晚。 今天,我经历了相同的行为。 解决方法是从我的UI代码中删除Expanded()。某些类型的布局似乎有问题。

我以前有一个带有Expanded()的Column()。这可行! :)

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

我将Column()更改为带有ListView()的Scrollbar(),但仍包含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框架不会告诉您有问题。 它在调试模式下没有问题。但是在发布模式下,它仅显示一个空容器。

相关问题