创建签名的 apk 时构建失败
Posted
技术标签:
【中文标题】创建签名的 apk 时构建失败【英文标题】:Build failed while creating signed apk 【发布时间】:2021-10-07 03:04:06 【问题描述】:我正在尝试以签名模式(即 playstore Google)构建这个项目,以便我在学校宿舍的其他朋友可以下载和测试,我尝试了很多文档,但我没有工作请帮助我,这是gradle(build.gradle)
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 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 29
lintOptions
disable 'InvalidPackage'
defaultConfig
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.thealphamerc.flutter_twitter_clone_dev"
minSdkVersion 20
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
signingConfigs
release
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
buildTypes
release
signingConfig signingConfigs.release
flutter
source '../..'
dependencies
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.android.support:multidex:1.0.3'
apply plugin: 'com.google.gms.google-services'
And here is the error in terminal
FAILURE: Build failed with an exception.
Where:
Build file 'C:\Users\MTGSTCKN\Documents\flutter_twitter_clone\android\app\build.gradle' line: 39
What went wrong:
A problem occurred evaluating project ':app'.
Could not find method lintOptions() for arguments [build_8bee7k9ov9n3733ekoixc4hsh$_run_closure3@7fad45fd] on project ':app' of type org.gradle.api.Project.
Try:
尝试:n 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。
Get more help at https://help.gradle.org
BUILD FAILED in 50s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 60.2s
Gradle task assembleRelease failed with exit code 1
【问题讨论】:
你生成你的密钥库文件了吗? 【参考方案1】:您的 build.gradle 在发布时应如下所示
查看文档:Official documentation
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
def keystorePropertiesFile = rootProject.file("keystore.properties") // change to your keystore file name
def keystoreProperties = new Properties()
if (keystorePropertiesFile.exists())
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
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.thealphamerc.flutter_twitter_clone_dev"
minSdkVersion 20
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfigs
release
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
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
flutter
source '../..'
dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-core:17.0.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
apply plugin: 'com.google.gms.google-services'
【讨论】:
谢谢大家,问题已经解决了以上是关于创建签名的 apk 时构建失败的主要内容,如果未能解决你的问题,请参考以下文章