How to resolve build.gradle errors in flutter. How to resolve this error "A problem occurred evaluating project ':app'. > Malformed \uxxxx encoding."

Viewed 2909

There's an error in build file. I tried everything but nothing worked getting this errorFAILURE: Build failed with an exception.

  • Where: Build file 'D:\Flutter App\covid19\android\app\build.gradle' line: 31

  • What went wrong: A problem occurred evaluating project ':app'.

Malformed \uxxxx encoding.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 6s Running Gradle task 'assembleRelease'... Running Gradle task 'assembleRelease'... Done 7.4s Gradle task assembleRelease failed with exit code 1

build.gradle file in android folder

'''   

buildscript {
        ext.kotlin_version = '1.3.50'
        repositories {
            google()
            jcenter()
        }

dependencies {
            classpath 'com.android.tools:r8:2.1.75'
            classpath 'com.google.gms:google-services:4.3.2'
            classpath 'com.android.tools.build:gradle:4.1.1'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
allprojects {
        repositories {
             google()
             jcenter()
  }
}
        
 rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
    }
    subprojects {
        project.evaluationDependsOn(':app')
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }

'''

build.gradle file in android app folder

tried all possible changes in this file also but didn't worked pls suggest some changes.

''' 
 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 28
        
            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.abhishekbhamare.covid19"
            minSdkVersion 16
            targetSdkVersion 28
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
        }
        
 

 signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }

  
 '''

Thanks in advance

P.S. This is my first ever post on stack overflow so if there are any mistakes in the post format then pls ignore and my apologies for that.

3 Answers

in you key.properties file, instead of storeFile= C:\Users<username>\upload-keystore.jks

use this storeFile= C:/Users/username/upload-keystore.jks

replace \ with / in file path.

this will resolve the error if this is the case.

In key.properties file while completing keystorepath storeFile=path to file use "/" instead of "\" for subdirectories i.e. if path is C:/user/[username]/keystore.jks (path shown in Windows) change it to C:\user\[username]\keystore.jks.

I have just had the same problem on Windows, which may also be the case for you. Since an error with the encoding is mentioned, I wrote the content of the key.properties file from scratch instead of copying and pasting from the flutter website, which probably introduces some string encoding issues. Then I no longer had this error. I still had some issues with the path to the keystore file, which I also solved, but it is another issue than the one that you are having. Here, I simply tried to satisfy Gradle in moving the keystore file and adjusted the keystore file name to what Gradle expected. I then finally got a signed release.

Related