Problème compilation (résolu)

Bonjour,
Je commence à développer en entreprise et cela commence mal car j’obtiens ceci lors de la compilation:
J’ai mis à jour les dépendances, flutter est mis à jour …
J’ai réglé dans le gradle ceci:
/** For apps only. Provides the flutter extension used in app/build.gradle. /
class FlutterExtension {
/
* Sets the compileSdkVersion used by default in Flutter app projects. */
static int compileSdkVersion = 31

/** Sets the minSdkVersion used by default in Flutter app projects. */
static int minSdkVersion = 16

/** Sets the targetSdkVersion used by default in Flutter app projects. */
static int targetSdkVersion = 31

Je vous mets ce que je reçois comme message: J’avoue que je trouve pas la solution.

Target kernel_snapshot failed: Exception

FAILURE: Build failed with an exception.

  • Where:
    Script ‹ C:\src\packages\flutter_tools\gradle\flutter.gradle › line: 1151

  • What went wrong:
    Execution failed for task ‹ :app:compileFlutterBuildDebug ›.

Process ‹ command ‹ C:\src\bin\flutter.bat › › finished with non-zero exit value 1

  • 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.

BUILD FAILED in 35s
Exception: Gradle task assembleDebug failed with exit code 1

Bonjour @felix54

Cette erreur me parait commune. Si je me trompe pas tu essayes de définir les versions min et max du SDK utilisé.

Si c’est bien ça, ce n’est pas comme ça qu’on les déclare.

Dans un premier temps ajoute ces lignes dans ton fichier android/local.properties :

flutter.targetSdkVersion=33
flutter.minSdkVersion=17

Ensuite, dans ton fichier app/build.gradle déclare tes variables et affecte leurs une valeur si jamais lors de la compilation, flutter ne les trouvent pas :

def flutterTargetSdkVersion = localProperties.getProperty('flutter.targetSdkVersion')
if (flutterTargetSdkVersion == null) {
    flutterTargetSdkVersion = '33'
}

def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
    flutterMinSdkVersion = '17'
}

Enfin tu n’a plus qu’à les appeler :

minSdkVersion flutterMinSdkVersion
targetSdkVersion flutterTargetSdkVersion

Question idiote où dois-je mettre ces deux lignes de code ?

Comment puis-je appeler les fonctions :?
minSdkVersion flutterMinSdkVersion
targetSdkVersion flutterTargetSdkVersion

La définition de tes variables se fait en dehors de ton android{}
Logiquement tu as déjà des définition de variable du même style, comme flutterVersionName par exemple.

En suite, minSdkVersion flutterMinSdkVersion & targetSdkVersion flutterTargetSdkVersion ne sont pas des fonctions.
Ca se trouve dans ton defaultConfig{}, tu remplaces :

minSdkVersion 17
targetSdkVersion 33

par

minSdkVersion flutterTargetSdkVersion
targetSdkVersion flutterTargetSdkVersion

flutterTargetSdkVersion & flutterTargetSdkVersion sont les variables que tu as définit plus haut

Voilà cela a un peu changé je me retrouve avec un problème sur la ligne 49:
minSdkVersion flutterTargetSdkVersion >>>>> Probleme de la ligne 49

defaultConfig {
// TODO: Specify your own unique Application ID (Configurar o módulo do app  |  Desenvolvedores Android  |  Android Developers).
applicationId « com.citesmarket.my_app »
minSdkVersion flutterTargetSdkVersion >>>>> Probleme de la ligne 49
targetSdkVersion flutterTargetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true

En dernier lieu j’obtiens cela :* Where:
Build file ‹ C:\CITIES\android\app\build.gradle › line: 50

  • What went wrong:
    A problem occurred evaluating project ‹ :app ›.

Cannot get property ‹ flutterTargetSdkVersion › on null object

En écrivant cela

defaultConfig {
// TODO: Specify your own unique Application ID (Configurar o módulo do app  |  Desenvolvedores Android  |  Android Developers).
applicationId « com.citesmarket.my_app »
minSdkVersion 17 flutterTargetSdkVersion
targetSdkVersion 33 flutterTargetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true

Tu n’as pas mis ça au dessus de ta section android{}

def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
    flutterMinSdkVersion = '17'
}

Sinon il ne trouverait pas null.

J’ai desormais cette erreur : FAILURE: Build failed with an exception.

  • Where:
    Build file ‹ C:\CITIES\android\app\build.gradle › line: 54

  • What went wrong:
    A problem occurred evaluating project ‹ :app ›.

Cannot get property ‹ flutterTargetSdkVersion › on null object

A la ligne 54 j’ai cela :
minSdkVersion 17 flutterTargetSdkVersion

J’ai bien ajouté cela dans la partie android :
android {
compileSdkVersion 33
def flutterMinSdkVersion = localProperties.getProperty(‹ flutter.minSdkVersion ›)
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = ‹ 17 ›
}

Pourquoi tu écris minSdkVersion 17 flutterTargetSdkVersion je t’écris minSdkVersion flutterTargetSdkVersion

Parce que si je fais cela j’obtiens cela dans flutter run:

What went wrong:
A problem occurred evaluating project ‹ :app ›.

Could not get unknown property ‹ flutterTargetSdkVersion › for DefaultConfig$AgpDecorated_Decorated{name=main, dimension=null, minSdkVersion=null, targetSdkVersion=null, renderscriptTargetApi=null, renderscriptSupportModeEnabled=n
ull, renderscriptSupportModeBlasEnabled=null, renderscriptNdkModeEnabled=null, versionCode=null, versionName=null, applicationId=com.citesmarket.my_app, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRu
nnerArguments={}, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=[], buildConfigFields={}, resValues={}, proguardFiles=[], consumerProguardFiles=[], manifestPlaceholders={applicationName=android.app.Application}, wearAppUnbundled=null} of type com.android.build.gradle.internal.dsl.DefaultConfig$AgpDecorated.

Tu as bien ajouté les variables dans ton android/local.properties ?

Oui d’ailleurs je vais te montrer le code.
Par contre l’erreur et la seule qui vient d’apparaître est celle-ci:
Voici la ligne 38 >>>>> def flutterMinSdkVersion = localProperties.getProperty(‹ flutter.minSdkVersion ›)

ET voici le code dans les properties:
sdk.dir=C:\Users\Sunflower\AppData\Local\Android\sdk
flutter.sdk=C:\src
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.targetSdkVersion=33
flutter.minSdkVersion=17

Could not compile build file ‹ C:\CITIES\android\app\build.gradle ›.

startup failed:
build file ‹ C:\CITIES\android\app\build.gradle ›: 38: Unexpected character: ‹ � › @ line 38, column 60.
= localProperties.getProperty(� flutter.

Tout simplement je pense que tu as du faire un copier coller du code et que les ' ne sont pas bien formatées. Flutter te le dit Unexpected character: ‹ � › ici localProperties.getProperty(� flutter. tu vois bien que c’est ce caractère qui pose problème.

Bonjour,
J’ai pallié à l’erreur voici donc ce que j’obtiens désormais.
Mais avant petite question et si je supprimé le dossier Android et que je reconstruisais ? Cela donnerait-il quelque chose ?

/C:/Users/Sunflower/AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/material_with_modal_page_route.dart:4:1: Error: ‹ ModalBottomSheetRoute › is imported from both
‹ package:flutter/src/material/bottom_sheet.dart › and ‹ package:modal_bottom_sheet/src/bottom_sheet_route.dart ›.
import ‹ …/modal_bottom_sheet.dart ›;
^^^^^^^^^^^^^^^^^^^^^
/C:/Users/Sunflower/AppData/Local/Pub/Cache/hosted/pub.dev/firebase_core-1.24.0/lib/src/firebase_app.dart:18:25: Error: Member not found: ‹ FirebaseAppPlatform.verifyExtends ›.
FirebaseAppPlatform.verifyExtends(_delegate);
^^^^^^^^^^^^^
/C:/Users/Sunflower/AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/material_bottom_sheet.dart:28:13: Error: ‹ ModalBottomSheetRoute › is imported from both
‹ package:flutter/src/material/bottom_sheet.dart › and ‹ package:modal_bottom_sheet/src/bottom_sheet_route.dart ›.
.push(ModalBottomSheetRoute(
^^^^^^^^^^^^^^^^^^^^^
/C:/Users/Sunflower/AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/material_bottom_sheet.dart:50:10: Error: A value of type ‹ Object? › can’t be returned from an async function with return type
‹ Future<T?> ›.

  • ‹ Object › is from ‹ dart:core ›.
  • ‹ Future › is from ‹ dart:async ›.
    return result;
    ^
    /C:/Users/Sunflower/AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/bar_bottom_sheet.dart:102:13: Error: ‹ ModalBottomSheetRoute › is imported from both
    ‹ package:flutter/src/material/bottom_sheet.dart › and ‹ package:modal_bottom_sheet/src/bottom_sheet_route.dart ›.
    .push(ModalBottomSheetRoute(
    ^^^^^^^^^^^^^^^^^^^^^
    /C:/Users/Sunflower/AppData/Local/Pub/Cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/bar_bottom_sheet.dart:125:10: Error: A value of type ‹ Object? › can’t be returned from an async function with return type
    ‹ Future<T?> ›.
  • ‹ Object › is from ‹ dart:core ›.
  • ‹ Future › is from ‹ dart:async ›.
    return result;
    ^
    Waiting for connection from debug service on Chrome… 64,5s
    Failed to compile application.

Merci beaucoup Antonin pour ta disponibilité et le temps que tu as mis a m’aider. et ta compétence
En réalité le chef de projet est venu ce matin et il m’a confié avoir fait une erreur dans le projet car c’était une ancienne version . J’ai pu reprendre sur la nouvelle mouture la modification du code entamée précédemment.
Je n’ai plus de problème de gradle de ce fait. J’ai appris pas mal de chose avec ton aide.
Belle journée à toi

1 « J'aime »

Je ne comprend pas bien, Tu étais sur une ancienne version de flutter ? Ou sur un vieux projet ?
Tant mieux si tu as réussis à résoudre ton problème ! :slight_smile: