0

GetRoutePolyline("https://roads.googleapis.com/v1/snapToRoadspath=$pointstostring&interpolate=true&key=MYAPIKEY").execute()

I have something like that coded into my app. How can I hide it when I publish it on my github? I want people to be able to clone my repo and this app should work.

dodododo97
  • 165
  • 1
  • 10
  • 3
    save your api key on gradle.properties like on this question https://stackoverflow.com/q/35722904/10797722 – Ade Dyas Apr 05 '20 at 18:26
  • 3
    Duplicate of [Saving the API Key in gradle.properties](https://stackoverflow.com/questions/35722904/saving-the-api-key-in-gradle-properties) – MrUpsidown Apr 05 '20 at 18:27
  • 1
    @AdeDyas But it will be visible in gradle.properties now? – dodododo97 Apr 05 '20 at 18:29
  • 2
    **gradle.properties is a local file and should not be stored under the version control, and BuildConfig is a generated class, so it will only be created at build time.** that's in the accepted answer. – MrUpsidown Apr 05 '20 at 18:31
  • @MrUpsidown But the person that will clone my app can't use my api then? So if someone want to launch this app he have to put his Api key in this file? – dodododo97 Apr 05 '20 at 18:33
  • Obviously the answer is yes. – MrUpsidown Apr 05 '20 at 18:34
  • 1
    @MrUpsidown That really depends on what a project is using the project-level `gradle.properties` file for. For instance, maybe the project stores dependency versions and other such information in that file, in which case the file absolutely should be committed to version control. I suppose one could put the API key in the properties file in the GRADLE_USER_HOME directory or Gradle installation directory, but those files apply to every project. – Slaw Apr 05 '20 at 18:38
  • There are other ways. – MrUpsidown Apr 05 '20 at 18:56

1 Answers1

2

You can't hide it. Better to write in the README that who is going to compile your app will need an API key.

E_net4
  • 27,810
  • 13
  • 101
  • 139
gcantoni
  • 727
  • 6
  • 13