Flutter only grey screen is visible in release apk

709 Views Asked by At

I wanted to build release apk for my app and I tried running this command

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

Then, I ran the app-armeabi-v7a-release apk, it was nothing but grey screen only.

I also have enabled all permission in manifest

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

Grey Screen

Log

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

IGNORE THIS: 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. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Flutter version Flutter 1.22.6

Thanks in advance!

1

There are 1 best solutions below

0
On BEST ANSWER

After looking for 2 hours I found the solution.

It is because of flutter_downloader package in my case.

add try catch bloc in main like this:

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

Error

Now I just need to add native integration.