Igor F
Igor F

Reputation: 21

Gradle settings: Invalid variable name. Must start with a letter but was:

Had a issue during settings of my android project:

startup failed:
settings file '/home/user/StudioProjects/project/android/settings.gradle': 1: Invalid variable name. Must start with a letter but was: rootProject
. At [1:1]  @ line 1, column 1.
   rootProject.name = 'project'
   ^

1 error

Open File

But the thing is I don't have any symbols before 'rootProject' variable name. Any thoughts about it?

Upvotes: 2

Views: 3088

Answers (2)

Suriya
Suriya

Reputation: 115

I got the same error when i moved my project into a different path. I tried to do Invalidate Cache/Restart but, it did not work for me.

I finally deleted build.gradle (project level) and opened Android Studio. It errored out saying 'This is not a gradle based project'.

Then i created the build.gradle, put the contents back and clicked on 'Make Project'. It seemed to work fine then.

Not sure, if this will work for you. But you can give it a shot.

Upvotes: 0

rupps
rupps

Reputation: 9887

If you're trying to setup some global variables in your root gradle files then reuse them in your modules' build.gradle, how I got it working was:

  • in ROOT build.gradle :

    buildscript {
        ... blah blah 
    }
    
    // put HERE all your variables, they will automatically
    // be available as rootProject.xxx in the rest of build.gradles
    ext {
        name = "project"
        compileSdkVersion = 27
        targetSdkVersion = 27
        supportLibraryVersion = "27.0.2"
        buildToolsVersion = "26.0.1"
        googleServicesVersion = "11.8.0"
    }
    
    allprojects {
        ... blah blah
    }
    .
    .
    
  • And then in your APP (or modules) build.gradle, you can use them:

    apply plugin: 'com.android.application'
    
    android {
    
        compileSdkVersion rootProject.compileSdkVersion
        buildToolsVersion rootProject.buildToolsVersion
    
        defaultConfig {
            applicationId "xxxx"
            targetSdkVersion rootProject.targetSdkVersion
            .
            .   
        }
    

Upvotes: 1

Related Questions