【问题标题】:Flutter only grey screen is visible in release apk在发布 apk 中只能看到 Flutter 灰屏
【发布时间】:2021-07-15 13:04:52
【问题描述】:

我想为我的应用构建发布 apk,并尝试运行此命令

flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi

然后,我运行了 app-armeabi-v7a-release apk,它只是灰屏而已。

我还启用了清单中的所有权限

<uses-permission android:name="android.permission.INTERNET"/>

日志

WARNING: [Processor] Library 'C:\Users\sanje\.gradle\caches\modules-2\files-2.1\org.robolectric\shadows-framework\4.3\150103d5732c432906f6130b734e7452855dd67b\shadows-framework-4.3.jar' contains references to both AndroidX and old support library. This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
 Example of androidX reference: 'androidx/test/runner/lifecycle/Stage'  
 Example of support library reference: 'android/support/annotation/NonNull'
Running Gradle task 'assembleRelease'...                                
Running Gradle task 'assembleRelease'... Done                     107.2s
√ Built build\app\outputs\flutter-apk\app-armeabi-v7a-release.apk (15.8MB).

android/app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.maslow.learnwithyoutube_flutterapp"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:26.5.0')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

local.properties

sdk.dir=C:\\Users\\sanje\\AppData\\Local\\Android\\Sdk
flutter.sdk=C:\\flutter
flutter.buildMode=release
flutter.versionName=1.0.0
flutter.versionCode=1

忽略这个:Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua。 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat。 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur。 Exceptioneur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum。

Flutter 版本Flutter 1.22.6

提前致谢!

【问题讨论】:

  • 你能分享你的android/app/build.gradleandroid/local.properties吗?错误与 sdk.dir 有关。 sdk.dir=/Users/username/Library/Android/sdk flutter.sdk=/Users/username/Downloads/flutter flutter.buildMode=debug flutter.versionName=1.0.0 flutter.versionCode=1
  • @Akif 添加了他们
  • 尝试在“环境变量”中添加ANDROID_HOME变量为C:\Users\ sanje\AppData\Local\Android\Sdk stackoverflow.com/a/48155800/10659482
  • @Akif 谢谢它的工作。 GG ;)
  • @Akif 但是当我打开 app-armeabi-v7a-release apk 时,只有灰屏可见,(发布中的灰屏==调试中的红屏?)该怎么办

标签: flutter flutter-android flutter-build


【解决方案1】:

找了2个小时后,我找到了解决办法。

在我的情况下是因为 flutter_downloader 包。

像这样在 main 中添加 try catch bloc:

void main() async {
  try {
    WidgetsFlutterBinding.ensureInitialized();
    await FlutterDownloader.initialize(
        debug: true // optional: set false to disable printing logs to console
        );
    await Firebase.initializeApp();

    final Directory directory =
        await path_provider.getApplicationDocumentsDirectory();
    Hive.init(directory.path);
    Hive.registerAdapter(ResponseTokenModelAdapter());
    await Hive.openBox<ResponseTokenModel>(HiveBoxNames.token);
    configureInjection(Environment.prod);
    runApp(AppWidget());
  } catch (e) {
    runApp(MaterialApp(
      home: Center(
        child: Text(e.toString()),
      ),
    ));
  }
}

现在我只需要添加原生集成。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2020-09-24
    相关资源
    最近更新 更多