简体   繁体   English

Flutter 版本 APK 不工作,但调试 APK 工作

[英]Flutter release APK is not working but debug APK is working

My debug APK is working fine but release APK is not working after building it from the command flutter build apk .我的调试 APK 工作正常,但发布 APK 在从命令flutter build apk后无法正常工作。 What can be the real issue here?这里真正的问题是什么?

In debug mode, any global variables or methods will work perfectly but in case of release mode, only native code is compiled.在调试模式下,任何全局变量或方法都可以正常工作,但在发布模式下,只编译本机代码。 So let's assume we are getting some unformatted text and we want to format it and return so if you have a global function to format text like below it will work fine in debug mode but might cause problems in release mode.所以让我们假设我们得到一些未格式化的文本,我们想要格式化并返回,所以如果你有一个全局 function 来格式化文本,如下所示,它在调试模式下可以正常工作,但在发布模式下可能会导致问题。

Code with global function.编码为全局 function。

// Global Function
String formatText(String unformattedText){
    // ....
    return formattedText;
}

Widget _showFormattedText(String unformattedText) {
   final fd = formatText(unformattedText);
   return Text(fd);
}

Instead of this we should follow best practices and wrap everything inside a class which is present globally.取而代之的是,我们应该遵循最佳实践并将所有内容包装在全球存在的 class 中。

// Code with class method.
class CustomFunctions{
  static String formatText(String unformattedText){
      // ....
      return formattedText;
  }
}

Widget _showFormattedText(String unformattedText) {
   final fd = CustomFunctions.formatText(unformattedText);
   return Text(fd);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SSLCOMMERZ 致力于调试 apk 但不致力于发布 apk - SSLCOMMERZ working on debug apk but not on release apk 权限在 flutter 版本 apk 中不起作用 - Permissions not working in flutter release apk Flutter - DEBUG 中的 Webview 正在工作,但在 RELEASE apk 上显示为空白,为什么? - Flutter - Webview in DEBUG is working but it's displaying blank on RELEASE apk, why? GetCurrentLocation 在调试中工作,但在 Android 中的发布 apk 中不工作 - GetCurrentLocation working in debug but not working in release apk in Android Google Map在Release APK中不起作用,但在Debug APK中可正常工作 - Google Map not working in Release APK, but working correct in Debug APK Flutter apk 在发布模式和调试模式下运行良好,但内置 apk 不工作? - Flutter apk running fine in release mode and debug mode but built apk not working? 调试 APK 工作正常,发布(签名)不 - Debug APK working fine, Release (signed) not 调试和发布 apk 在 React Native 0.63.3 中不起作用 - Debug and Release apk not working in React Native 0.63.3 Android WorkManager使用调试版本,但不能使用版本APK - Android WorkManager working with debug build but not with release APK Firebase OTP 在调试 apk 上工作正常,但不能发布 apk - Firebase OTP working fine on debug apk but not release apk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM