\android\build.gradle 行中出现意外标记:14:意外标记:{

97_*_*YUN 6 android gradle flutter

当尝试使用构建项目时

flutter build apk --split-per-abi 但是我收到以下错误:

FAILURE: Build failed with an exception.
Run Code Online (Sandbox Code Playgroud)
  • 其中:构建文件'C:\ proeject \ android \ app \ build.gradle'行:34

  • 出了什么问题:无法编译构建文件“C:\project\android\app\build.gradle”。

启动失败:构建文件 'C:\project\android\app\build.gradle': 34: 意外输入:'{' @ 第 34 行,第 9 列。 android { ^

1 个错误

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。使用 --scan 运行以获得完整的见解。

  • 在https://help.gradle.org获取更多帮助

我的代码:

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"

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'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.company.project"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName 1.0.0
    }

    signingConfigs {
        release {
            storeFile file('../keystore/key.jks')
            storePassword file('../keystore/keystore.password').text.trim()
            keyPassword file('../keystore/keystore.password').text.trim()
            keyAlias 'key'
    }
   }

    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

            minifyEnabled true
            useProguard true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Run Code Online (Sandbox Code Playgroud)

Paw*_*rma 0

不确定它会解决你的问题,但我也面临着同样的问题。但我不知道为什么配置不安全的方式解决了我的问题。我只是替换下面的代码:

   release {
    storeFile file('your_key_name.keystore')
    storePassword System.console().readLine("\nKeystore password:")
    keyAlias System.console().readLine("\nAlias: ")
    keyPassword System.console().readLine("\Alias password: ")
   }
Run Code Online (Sandbox Code Playgroud)

release {
  storeFile file('your_key_name.keystore')
  storePassword 'your_key_store_password'
  keyAlias 'your_key_alias'
  keyPassword 'your_key_file_alias_password'
}
Run Code Online (Sandbox Code Playgroud)

这对我有用。