I can't create an apk with visual studio code and flutter.

2,187 views
Skip to first unread message

Russ Brewer

unread,
Jun 1, 2020, 1:52:54 PM6/1/20
to Flutter Development (flutter-dev)
Hello,

Last week I created my project's app bundle and built a set of apk files 
without issue. This week after adding a new screen and some links to cloud 
firestore I go to rebuild my apk (and recreate the appbundle) and *I get 
thrown this error.*

FAILURE: Build failed with an exception.
* Where:
Build file 'C:\development\flutter\cbl_beta\android\app\build.gradle' line: 
29
* What went wrong:
Could not compile build file 
'C:\development\flutter\cbl_beta\android\app\build.gradle'.
> startup failed:
  build file 'C:\development\flutter\cbl_beta\android\app\build.gradle': 
29: unexpected char: '\' @ line 29, column 50.
     iesFile = rootProject.file('C:\developme
                                   ^
  1 error

* 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 1s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                       2.5s
Gradle task assembleRelease failed with exit code 1

I have worked through the instructions here twice: 

*I've remade my signing key in windows two times. My current 
android/key.properties file looks like this:*

storePassword=******
keyPassword=c******
keyAlias=key
storeFile=C:\development\flutter\*******\key.jks


*And this is my android/app/build.gradle looks like this:*

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'
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    defaultConfig {
        // TODO: Specify your own unique Application ID 
(https://developer.android.com/studio/build/application-id.html).
        applicationId "*********"
        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']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
            
       }
   }
}

flutter {
    source '../..'
}
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'


Can you see what I am doing wrong, or what I should check for?

Vijay Tailor

unread,
Jun 1, 2020, 4:16:22 PM6/1/20
to Flutter Development (flutter-dev)
Dear Russ, 

It's difficult for me to trace the error in the build.gradle file, but it is probably due to your Firebase app settings. 

My suggestion to you is to simply create a new Flutter project, add the firebase app settings in it and see if it builds properly. 
If it does, copy the build files to the existing project. If it doesn't, you are doing something wrong with the build instructions. 

Please keep us updated about this. I will do my best to help out. 

Kind regards,
Tailor

בתאריך יום שני, 1 ביוני 2020 בשעה 19:52:54 UTC+2, מאת Russ Brewer:

Igor Karelin

unread,
Jun 1, 2020, 5:20:19 PM6/1/20
to Flutter Development (flutter-dev)
Seems that you have a syntax error in build.gradle:

unexpected char: '\' @ line 29, column 50.

You can also try to build from command line with verbose enabled 'flutter build -v appbundle'

Russ Brewer

unread,
Jun 1, 2020, 5:28:25 PM6/1/20
to Flutter Development (flutter-dev)
That is a great idea. I'll give it a try with a fresh project.

Russ Brewer

unread,
Jun 1, 2020, 5:30:04 PM6/1/20
to Flutter Development (flutter-dev)
Thank you! I gave your suggestion a try and included the full file path to the key.properties file (assuming there was a issue with the original pointer). No dice. I am working on building a fresh project to add my firebase settings to and see if that works.

Than you for your suggestion!

Russ Brewer

unread,
Jun 2, 2020, 3:29:25 PM6/2/20
to Flutter Development (flutter-dev)
Alright, I figured it out. other's have had issues linking cloud firestore to their flutter projects completely. The solution can be found here:https://github.com/FirebaseExtended/flutterfire/issues/2599. That issue is fixed. However I still get this error:

FAILURE: Build failed with an exception.
FAILURE: Build failed with an exception.
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:validateSigningRelease'.
> Keystore file 'C:\development\flutter\cbl_beta\android\app\C:developmentluttercbl_betakey.jks' not found for signing config 'release'.
                                                                          luttercbl_betakey.jks' not found for signing config 'release'.

* 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 1m 20s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done                      81.7s
Gradle task assembleRelease failed with exit code 1

On Monday, June 1, 2020 at 1:16:22 PM UTC-7, Vijay Tailor wrote:

Russ Brewer

unread,
Jun 2, 2020, 3:30:46 PM6/2/20
to Flutter Development (flutter-dev)
I fixed the syntax error as you pointed out but still my project fails to create and apk, only "flutter create appbundle" yields a successful result.


On Monday, June 1, 2020 at 2:20:19 PM UTC-7, Igor Karelin wrote:

Russ Brewer

unread,
Jun 3, 2020, 2:00:39 PM6/3/20
to Flutter Development (flutter-dev)
I have resolved the issue! in my key.properties file flutter did not like me using the full path for the key.jks. instead I used key.jks for the value for the location and placed in into the android/app directory. Problem solved. Thank you all for contributing and helping to work through the problem!
Reply all
Reply to author
Forward
0 new messages