path_provider 編譯錯誤指導

杨文利發表於2024-12-07

增加依賴:flutter pub add path_provider

使用命令: flutter run -v 提示錯誤

解決方案:

  1. 開啟 .\android\settings.gradle 檔案,版本號更新為最新。
plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.7.3" apply false
    id "org.jetbrains.kotlin.android" version "2.0.20" apply false
}
  1. 開啟 .\android\gradle\wrapper\gradle-wrapper.properties 檔案,更新bradle。
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
  1. 如果線上下載不了,可以離線下載解壓到 C:\Users\Jack-PC.gradle\wrapper\dists\gradle-8.11.1-all\2qik7nd48slq1ooc2496ixf4i 資料夾下即可.

  2. 開啟 .\android\app\build.gradle 檔案,更新NDK版本。

android {
    namespace = "com.example.flutter_app1"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = rootProject.ext["flutter.ndkVersion"] ?: 'default'

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.flutter_app1"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }
  1. 開啟 .\android\gradle.properties 檔案,配置DNK版本。
flutter.ndkVersion=27.2.12479018

相關文章