![](/img/trans.png)
[英]Unexpected token in \android\build.gradle line: 12 : unexpected token: }
[英]Unexpected token in \android\build.gradle line: 14 : unexpected token: {
嘗試使用構建項目時
flutter build apk --split-per-abi 但是我收到以下錯誤:
FAILURE: Build failed with an exception.
其中:構建文件 'C:\proeject\android\app\build.gradle' 行:34
出了什么問題:無法編譯構建文件“C:\proeject\android\app\build.gradle”。
啟動失敗:構建文件 'C:\project\android\app\build.gradle': 34: 意外輸入:'{' @ 第 34 行,第 9 列。android { ^
1 個錯誤
嘗試:使用 --stacktrace 選項運行以獲取堆棧跟蹤。 使用 --info 或 --debug 選項運行以獲取更多日志 output。使用 --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"
}
不確定它會解決您的問題,但我也面臨同樣的問題。 但我不知道為什么配置不安全的方式解決了我的問題。 我只是替換下面的代碼:
release {
storeFile file('your_key_name.keystore')
storePassword System.console().readLine("\nKeystore password:")
keyAlias System.console().readLine("\nAlias: ")
keyPassword System.console().readLine("\Alias password: ")
}
和
release {
storeFile file('your_key_name.keystore')
storePassword 'your_key_store_password'
keyAlias 'your_key_alias'
keyPassword 'your_key_file_alias_password'
}
它對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.