创建签名的 apk 时构建失败

我正在尝试以签名模式(即 Google Playstore)构建此项目,以便学校宿舍的其他朋友可以下载和测试,我已经尝试了许多文档,但我不起作用,请帮助我,这是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
je8600 回答:创建签名的 apk 时构建失败

你的 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'
本文链接:https://www.f2er.com/2242.html

大家都在问