You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android项目build.gradle报Unexpected tokens错误,求排查解决

排查build.gradle语法错误:Unexpected tokens问题

你的build.gradle文件存在三处语法问题,导致构建报错:

  • 字符串被非法拆分:proguardFiles中的'proguard- rules.pro'被换行拆分,Groovy不允许字符串这样断行,需合并为完整的'proguard-rules.pro'。
  • 括号层级不匹配:defaultConfig块末尾缺少闭合},且android块的闭合}位置错误,导致buildTypes、compileOptions等模块不在android的作用域内,引发语法混乱。
  • 多余的闭合括号:kotlinOptions块之后多了一个冗余的},破坏了代码结构。

以下是修正后的完整代码:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 33

    defaultConfig {
        applicationId "com.example.nfcencryptionapp"
        minSdk 23
        targetSdk 33
        versionCode 1
        versionName "1.0"

        // Required to use BiometricPrompt
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.core:core-ktx:1.12.0'
    implementation 'androidx.biometric:biometric:1.2.0-alpha04'
    implementation 'com.google.android.gms:play-services-nfc:18.0.0'
    implementation 'com.google.android.material:material:1.9.0'
}

内容的提问来源于stack exchange,提问作者DaveCastiaux

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 09:43:11