Flutter Android SDK version 28 Error but I am using 30

4,309

Try this,

minSdkVersion 16
compileSdkVersion 28
targetSdkVersion 29
Share:
4,309
trix
Author by

trix

Updated on December 24, 2022

Comments

  • trix
    trix over 1 year

    When I create a new flutter app, It starts android sdk version 28 but I use android sdk 30. Flutter doctor also shows Platform android-30, build-tools 30.0.2. When I tried to install a package like url_launcher or shared_preferences I am getting error It looks for Android sdk 30. Also every time I am changing android sdk verison from build.gradle.

    Here is My flutter doctor output:

    flutter doctor -v
    [✓] Flutter (Channel stable, 1.22.0, on Linux, locale en_US.UTF-8)
        • Flutter version 1.22.0 at /home/felix/snap/flutter/common/flutter
        • Framework revision d408d302e2 (7 days ago), 2020-09-29 11:49:17 -0700
        • Engine revision 5babba6c4d
        • Dart version 2.10.0
    
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
        • Android SDK at /home/felix/Android/Sdk
        • Platform android-30, build-tools 30.0.2
        • Java binary at: /home/felix/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6626763/jre/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    
    [!] Android Studio (version 4.0)
        • Android Studio at /home/felix/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6626763
        ✗ Flutter plugin not installed; this adds Flutter specific functionality.
        ✗ Dart plugin not installed; this adds Dart specific functionality.
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593
    

    )

    Url launcher package error :

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':url_launcher:parseDebugLibraryResources'.
    > Could not resolve all files for configuration ':url_launcher:androidApis'.
       > Failed to transform file 'android.jar' to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}
          > Execution failed for PlatformAttrTransform: /home/computer/Android/Sdk/platforms/android-28/android.jar.
             > /home/computer/Android/Sdk/platforms/android-28/android.jar (No such file or directory)
    
    * 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 2s
    

    Exception: Gradle task assembleDebug failed with exit code 1

    My build.gradle file

        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: '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.example.appdeals"
            minSdkVersion 16
            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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    }
    

    shared_preferences error :

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':shared_preferences:parseDebugLibraryResources'.
    > Could not resolve all files for configuration ':shared_preferences:androidApis'.
       > Failed to transform file 'android.jar' to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}
          > Execution failed for PlatformAttrTransform: /home/computer/Android/Sdk/platforms/android-28/android.jar.
             > /home/computer/Android/Sdk/platforms/android-28/android.jar (No such file or directory)
    
    * 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 8s
    Exception: Gradle task assembleDebug failed with exit code 1
    Exited (sigterm)
    
  • Osama Gamal
    Osama Gamal almost 3 years
    should be compileSdkVersion not "compiledSdkVersion", but worked for me