首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VS代码/Flutter/Android- Keystore文件未设置为签名配置发行版

VS代码/Flutter/Android- Keystore文件未设置为签名配置发行版
EN

Stack Overflow用户
提问于 2020-05-21 22:02:53
回答 3查看 5.8K关注 0票数 1

我按照这些步骤在VS代码上构建apk:https://flutter.dev/docs/deployment/android

但我总能得到:

失败:生成失败,出现异常。

  • 哪里出了问题:任务执行失败“:app:validateSigningRelease”。
  • 尝试:使用--stacktrace选项运行以获得堆栈跟踪。使用--info或-调试选项运行以获得更多日志输出。用扫描来获得完整的洞察力。
  • https://help.gradle.org获得更多帮助

编译失败在35s运行分级任务‘组装释放’.运行分级任务“组装释放”..。完成36,0s级任务assembleRelease退出代码1失败

我已经尝试过像这样在build.gradle上创建密钥:

代码语言:javascript
复制
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
        }
    }

就像这样:

代码语言:javascript
复制
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.debug
        }
    }

但我在构建apk时也有同样的错误。官方文件似乎错了。如何在VS代码上创建apk?

EN

回答 3

Stack Overflow用户

发布于 2020-05-28 13:14:37

我只是犯了同样的错误。我认为编辑应用/build.gradle的文档有点混乱。

我就是这样解决的。注意重复的buildTypes块。

代码语言:javascript
复制
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }

    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.debug
        }
    }

这是我的完整应用程序/build.gradle(记得改变applicationId)。

代码语言:javascript
复制
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.google.gms.google-services'
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 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "!APP ID HERE!"
        minSdkVersion 16
        targetSdkVersion 28
        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
        }
    }

    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.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
票数 6
EN

Stack Overflow用户

发布于 2020-05-22 22:17:05

答案是Android。我做到了。VS代码似乎启动了一个类似颤振的框架。也许这个问题是一种考验。耐心测试。

票数 0
EN

Stack Overflow用户

发布于 2022-08-08 09:32:35

仅供参考

重复的buildTypes块不是真正的方法。这样,您就可以覆盖buildTypes。虽然您的错误似乎是固定的,但实际上您并没有签署APK。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61944522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档