Sourav Kannantha B
Sourav Kannantha B

Reputation: 3299

BuildConfig.java is not configuring properly in flutter

When I run my flutter project, I get the following error:

C:\Users\Sourav Kannantha B\Documents\AndroidProjects\ecommercestore\build\app\generated\source\buildConfig\debug\com\skbsmk\ecommercestore\BuildConfig.java:14: error: illegal escape character
  public static final String fluttersdk = "C:\Users\Sourav Kannantha B\Documents\Flutter";
                                              ^
.
.
.

I can see why that is error, because BuildConfig.java contains this line:

public static final String fluttersdk = "C:\Users\Sourav Kannantha B\Documents\Flutter";

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.

Upvotes: 4

Views: 1630

Answers (4)

Zofi96
Zofi96

Reputation: 51

I had the same problem. For me, helps flutter's relocation. When my path contains any folder name starts with big letter I had that error. When I relocated flutter to new folder and path changed, problem disappeared.

Before my path looked like: C:\Users\Kate\flutter Users and Kate generates problem

After relocation: C:\tools\flutter

After relocation remember to changed your Flutter SDK path in settings (File -> Settings -> Languages & Frameworks -> Flutter if you use AndroidStudio) and your Dart SDK path. Then restart IDE.

After that I had to use flutter clean and flutter packages get to clean and restore dependencies.

Upvotes: 1

Alooza
Alooza

Reputation: 127

I had more or less same issue. The autogenerated buildConfig file was not correct in where it added some other declaration.

/**
* Automatically generated file. DO NOT MODIFY
*/
public final class BuildConfig {
  public static final boolean DEBUG = false;
  public static final String APPLICATION_ID = "com.package";
  public static final String BUILD_TYPE = "release";
  public static final String FLAVOR = "staging";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0.0";

  // Added this weird declaration
  public static final String  = ;
  public static final String sdkdir = " C :  U s e r s  A d m i n i s t r a t o r  A p p D a t a  L o c a l  A n d r o i d  S d k " ";
}

Removing com.google.android.libraries.mapsplatform.secrets-gradle-plugin fixed the issue

Upvotes: 2

Sourav Kannantha B
Sourav Kannantha B

Reputation: 3299

Currently now, I'm hiding my Maps API key as below:

Storing the api key in local.properties

MAPS_API_KEY=<MY_API_KEY>

Declaring the api key placeholder in AndroidManifest.xml

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="${MAPS_API_KEY}" />

Replacing the api key placeholder in module level build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
localPropertiesFile.withReader('UTF-8') { reader ->
    localProperties.load(reader)
}
def mapsApiKey = localProperties.getProperty('MAPS_API_KEY')
android {
    defaultConfig {
        manifestPlaceholders += [MAPS_API_KEY: mapsApiKey]
    }
}

Upvotes: 0

Valentin MARTINET
Valentin MARTINET

Reputation: 116

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 :

secrets {
    propertiesFileName = "secrets.properties"
}

And in secrets.properties, put your secrets.

Upvotes: 1

Related Questions