When I run my flutter project, I get the following error:
C:UsersSourav Kannantha BDocumentsAndroidProjectsecommercestorebuildappgeneratedsourcebuildConfigdebugcomskbsmkecommercestoreBuildConfig.java:14: error: illegal escape character
public static final String fluttersdk = "C:UsersSourav Kannantha BDocumentsFlutter";
^
.
.
.
I can see why that is error, because BuildConfig.java
contains this line:
public static final String fluttersdk = "C:UsersSourav Kannantha BDocumentsFlutter";
But my local.properties
file contains the path in correct format:
flutter.sdk=C:\Users\Sourav Kannantha B\Documents\Flutter
I don’t know why, while building it is skipping one backslash. I even tried to edit local.properties
to this:
flutter.sdk=C:\\Users\\Sourav Kannantha B\\Documents\\Flutter
and this:
flutter.sdk=C:/Users/Sourav Kannantha B/Documents/Flutter
But as soon as I run the project, android studio is automatically changing these to as it was before.
EDIT: Project was running properly before. This all started when I added com.google.android.libraries.mapsplatform.secrets-gradle-plugin
to my android gradle file. But I’m not sure if this has to do anything with this error.
EDIT: My bad, error was indeed related to com.google.android.libraries.mapsplatform.secrets-gradle-plugin
. After removing that, error got resolved. Can someone explain this behaviour.
3
Answers
Currently now, I'm hiding my Maps API key as below:
Storing the api key in
local.properties
Declaring the api key placeholder in
AndroidManifest.xml
Replacing the api key placeholder in module level
build.gradle
I stumbled upon the same issue on Windows since I added the secrets plugin. I found in the documentation that you can move your secrets into a specific properties file which the plugin can use. That way, you can leave the local.properties file unmodified.
See point 8 in the documentation. In a nutshell, you need to add the following code in your app’s build.gradle :
And in secrets.properties, put your secrets.
I had more or less same issue. The autogenerated
buildConfig
file was not correct in where it added some other declaration.Removing
com.google.android.libraries.mapsplatform.secrets-gradle-plugin
fixed the issue