'Flutter Release APK for playstore
I am trying to generate a build apk, but getting following error. this is compatible with flutter version 2.8.1
Getting following error while run flutter build apk
/home/dell/snap/flutter/common/flutter/bin/flutter --no-color build apk
Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety
Running Gradle task 'assembleRelease'...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Note: /home/dell/.pub-cache/hosted/pub.dartlang.org/geocoding-2.0.2/android/src/main/java/com/baseflow/geocoding/GeocodingPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /home/dell/.pub-cache/hosted/pub.dartlang.org/google_maps_flutter-2.1.1/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /home/dell/.pub-cache/hosted/pub.dartlang.org/path_provider_android-2.0.11/android/src/main/java/io/flutter/plugins/pathprovider/PathProviderPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
e: /var/projects/app/freshooo/android/app/src/main/kotlin/com/u6amtech/flutter_grocery/Application.kt: (11, 51): Unresolved reference: setPluginRegistrant
e: /var/projects/app/freshooo/android/app/src/main/kotlin/com/u6amtech/flutter_grocery/FirebaseCloudMessagingPluginRegistrant.kt: (15, 44): Unresolved reference: registerWith
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileReleaseKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2m 6s
Running Gradle task 'assembleRelease'... 126.8s
Gradle task assembleRelease failed with exit code 1
pubspec.yaml
name: flutter_grocery
description: A new Flutter application.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.1.0+2
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^1.0.2
get_it: ^6.0.0
provider: ^5.0.0
http: ^0.13.1
freezed: ^0.14.1
shared_preferences: ^2.0.5
photo_view: ^0.12.0
dio: ^4.0.0-prev2
image_picker: ^0.7.3
pin_code_fields: ^7.0.0
google_maps_flutter_web: ^0.3.0
google_maps_flutter: ^2.0.3
flutter_google_places: ^0.3.0
geocoding: ^2.0.0
geolocator: ^7.0.1
shimmer_animation: ^2.0.0
url_launcher: ^6.0.2
webview_flutter: ^2.0.2
firebase_core: ^1.7.0
firebase_messaging: ^10.0.8
flutter_local_notifications: ^8.2.0
path_provider: ^2.0.1
flutter_html: ^2.0.0-nullsafety.0
connectivity: ^3.0.2
carousel_slider: ^4.0.0-nullsafety.0
fluro: ^2.0.3
url_strategy: ^0.2.0
universal_html: ^2.0.8
universal_ui: ^0.0.8
flutter_widget_from_html_core: ^0.6.1
phone_number: ^0.11.0+2
country_code_picker: ^2.0.2
flutter_typeahead: ^3.1.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/image/
- assets/language/
fonts:
- family: Poppins
fonts:
- asset: assets/font/Poppins-Light.ttf
weight: 300
- asset: assets/font/Poppins-Regular.ttf
weight: 400
- asset: assets/font/Poppins-Medium.ttf
weight: 500
- asset: assets/font/Poppins-SemiBold.ttf
weight: 600
- asset: assets/font/Poppins-Bold.ttf
weight: 700
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 FileNotFoundException("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: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
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.fresh.grocery"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.google.firebase:firebase-messaging:21.0.1"
implementation 'com.android.support:multidex:1.0.3'
}
android/build.gradle
buildscript {
ext.kotlin_version = '1.5.20'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
}
}
allprojects {
repositories {
google()
jcenter()
}
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:-options'
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-all.zip
key.properties
storePassword=123456
keyPassword=123456
keyAlias=upload
storeFile=~/home/dell/upload-keystore.jks
Solution 1:[1]
Please don't show confidential code like your package name, key.properties file kindly edit and remove those to protect your app from malicious itentions.
Since your flutter
version is 2.8.1 but your dart sdk in pubspec.yaml
is sdk: ">=2.7.0 <3.0.0"
it requires to enable null-safety for your project just change the 2.7.0
to 2.12.0
or above, and also do require changes for flutter null safety for more details check out this https://dart.dev/null-safety/unsound-null-safety
You maybe getting this error as some of the packages you used in your project use null-safety so migrate your app to null-safety.
You can check this for more details about generating production apps https://docs.flutter.dev/deployment/android
you can also use this code to generate a obfuscated apk
flutter build apk --release --obfuscate --split-debug-info={directory}
similarly for appbundle:
flutter build appbundle --release --obfuscate --split-debug-info={directory}
Solution 2:[2]
For release playstore build change
this in app/build.gradle
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
}
}
to
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.release
}
}
Solution 3:[3]
Did you register your Application
class in the Manifest
file?
like this :
<application
android:name=".Application"
android:label="app_name"
android:icon="@mipmap/ic_launcher"/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Harsh Kothari |
Solution 2 | Sahil Hariyani |
Solution 3 | Hardik Mehta |