首页 > 解决方案 > Android Studio adding gradle repository gives "Invalid variable name. Must start with a letter"

问题描述

I am trying to add Charboost maven repository to my build.gradle. I am following their docs which say to do

repositories​ {
      maven​ { ​url​ ​"https://chartboostmobile.bintray.com/Chartboost"​ }
}

I already have and it works:

repositories {
  jcenter()
  google()
  flatDir {
    dirs 'libs'
  }
}

But when I add maven​ { ​url​ ​"https://chartboostmobile.bintray.com/Chartboost"​ } I get

Could not compile build file '.../build.gradle'.
> startup failed:
  build file '.../build.gradle': _: Invalid variable name. Must start with a letter but was: ​
  . At line _, column _.
         maven​ { ​url​ ​'https://chartboostmobile.bintray.com/Chartboost'​ }
                        ^

I've tried doing this with com.android.tools.build:gradle:3.1.3 and 4.+ and I also tried apply plugin: 'maven' and plugin { id 'maven' }

标签: androidmavenandroid-studiogradlebuild

解决方案


Turns out, that the syntax

maven​ { ​url​ ​"https://chartboostmobile.bintray.com/Chartboost"​ }

is for some reason not supported. I have fixed it by adding () around the url:

maven​ { ​url​(​"https://chartboostmobile.bintray.com/Chartboost"​) }

推荐阅读