首页 > 解决方案 > 构建 Flutter 应用的 RELEASE 版本会返回此错误

问题描述

我正在准备在 Playstore 中发布我的颤振应用程序,它给了我这个错误:

错误:

* Where:
Build file 'C:\Users\svesp\Desktop\Vlad Esplana\syncshop_webview\android\app\build.gradle' line: 60

* What went wrong:
A problem occurred evaluating project ':app'.
> path may not be null or empty string. path='null'

我的key.properties

storePassword=hidden
keyPassword=hidden
keyAlias=random
storeFile=C:/Users/svesp/key.jks

我的应用级别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'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    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.hivemanila.syncshop_webview"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

   signingConfigs {
       release {
           keyAlias keystoreProperties['hidden']
           keyPassword keystoreProperties['hidden']
           storeFile file(keystoreProperties['C:/Users/svesp/key.jks'])
           storePassword keystoreProperties['hidden']
       }
   }

    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'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

标签: androidflutterflutter-layoutflutter-dependencies

解决方案


只需将您的签名配置更改为以下,

signingConfigs {
       release {
            keyAlias keystoreProperies["keyAlias"]  
            keyPassword keystoreProperies["keyPassword"]  
            storeFile file(keystoreProperies["storeFile"])  
            storePassword keystoreProperies["storePassword"]  
       }
   }

只需替换您的代码

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperiesFile = rootProject.file("key.properties")  
def keystoreProperies = new Properties()  
keystoreProperies.load(new FileInputStream(keystoreProperiesFile)) 
        

推荐阅读