Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

build.gradle -- add note for MyOpenWeatherMapApiKey #69

Open
Cattalins opened this issue Oct 19, 2015 · 66 comments
Open

build.gradle -- add note for MyOpenWeatherMapApiKey #69

Cattalins opened this issue Oct 19, 2015 · 66 comments

Comments

@Cattalins
Copy link

I am a pretty new user to Android Studio, Gradle and everything else.
I have been having some trouble to get the project starting with the build.gradle file.

ON:

    buildTypes.each {
        it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
    }

It would be nice to have a note stating that your API Key should be inside single quotes AND double quotes.

LIKE:

    buildTypes.each {
        // Replace MyOpenWeatherMapApiKey with your API Key in the format '"abcdefgh012345"' 
        // Use both single quotes followed by double quotes.
        it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
    }
@jasjasbinks
Copy link

Thank you Cattalins, I also encountered this hiccup :)

@a1g0rithm
Copy link

I agree Cattalins. Part of being a good coder is using comments to help clarify what the previous code means.

@morfioce
Copy link

That was starting to bother me and then I read this, so thank you Cattalins

@zmckenney
Copy link

Wow, thank you for this post! This was something I also ran into that bothered me. Thanks for the information!

@dragon9001
Copy link

I get stuck at the same situation. Thanks so much!!! cattallins

@DClayton12
Copy link

@Cattalins Good catch and Thank you! I was searching errors using gradle as the error was not obvious.

@asheshb
Copy link

asheshb commented Nov 13, 2015

Thanks a lot Cattalins. That was very helpful and time saving.

@JerryZaz
Copy link

On the bright side, getting this fixed was also a learning experience and YOU get to say that you did it without this post! You're awesome!

@Cattalins
Copy link
Author

Yes, I know, but sadly when this get fixed, I will return to my anonymity.
Hahaha

@bavly
Copy link

bavly commented Dec 1, 2015

thank you Cattalins very much this helped me

@nammshub
Copy link

nammshub commented Dec 3, 2015

Thank you so much for your help :)

@tkinetik1
Copy link

AMEN!

@dbwest
Copy link

dbwest commented Dec 14, 2015

that helped so much. Should've guessed to have done that when I saw the code it generated...

@thaibt
Copy link

thaibt commented Dec 24, 2015

Hi I have this problem with buildTypes.each

Error:(21, 0) Gradle DSL method not found: 'buildConfigField()'
Possible causes:

  • The project 'Sunshine' may be using a version of Gradle that does not contain the method.
    Gradle settings
  • The build file may be missing a Gradle plugin.
    Apply Gradle plugin
  • And no, I am not missing a comma.

@shrenuj
Copy link

shrenuj commented Dec 27, 2015

Earlier,I quit the tutorial coz android studio wont let me run the app coz of this gradle quotes issue.
Thanks a lot!

@thaibt
Copy link

thaibt commented Dec 27, 2015

For some reason, my gradle built only works when I simulate through a virtual phone, not my galaxy.... Which was weird because it was compatible.

On Dec 26, 2015, at 11:01 PM, shrenuj notifications@github.com wrote:

I quit the tutorial coz android studio wont let me run the app coz of this gradle quotes issue.


Reply to this email directly or view it on GitHub.

@peterqz
Copy link

peterqz commented Jan 2, 2016

Also this works:
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', ""abcdefg0123456""

@sachinrkeche
Copy link

Good Catch..

@javiexpo
Copy link

javiexpo commented Jan 7, 2016

You can also use the gradle.properties file tu define the constant MyOpenWeatherMapApiKey like this:

MyOpenWeatherMapApiKey = "abcdefg0123456"

And the project will sync without problem

@lucasassalti
Copy link

Thank u =)

@lishuopitt
Copy link

@ratulbside
Copy link

This helps me a lot .. :)

@javadKarbasian
Copy link

Thanks a lot

@Polyterative
Copy link

This helped me a lot, thanks!!!

@tusharbanne
Copy link

I should have seen this before figuring out what the problem is. It would have saved a lot of time.

@ghost
Copy link

ghost commented Feb 21, 2016

Thank you so much for this post, i have spent last 2 hrs fixing this issue.

@ghost
Copy link

ghost commented Feb 21, 2016

Thanks a lot Cattalins

@ghost
Copy link

ghost commented Feb 22, 2016

buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', ""c882c94be45fff9d16a1cf845fc16ec5""
}
//me a funcionado!!!

@tal32123
Copy link

How does one use this code:

MyOpenWeatherMapApiKey = "abcdefg0123456"

it doesn't seem to work for me.

@ghost
Copy link

ghost commented Feb 24, 2016 via email

@Heleni
Copy link

Heleni commented Apr 4, 2016

Thanks a lot!

@baishali-ghosh
Copy link

Thanks a lot. Got stuck here, kept applying " " and it still wouldn't render correctly in the build config. You saved me a lot of time.

@technoplato
Copy link

There's going to be a change coming that will make this process much more clear! Sorry for the current confusion. I agree, single quotes surrounding double quotes is very confusing.

@alketola
Copy link

alketola commented May 3, 2016

Thank you, you saved my day! Started pondering about this a fed days ago...

  • However, I consider this a very educative catch. ;-)

@sidvenu
Copy link

sidvenu commented May 5, 2016

@tal32123 and others who are looking why defining MyOpenWeatherMapApiKey in gradle.properties doesn't work. The people at Udacity tells us to create gradle.properties in .gradle directory. But there is already in the normal project folder.(C/Users/.../Sunshine/gradle.properties). Put MyOpenWeatherMapApiKey="{YOURKEYHERE}" there and replace {YOURKEYHERE} with your key. and then leave the build.gradle file as it is as they gave here at github. It will work

@technoplato
Copy link

@SiddharthVenu The reason why you shouldn't put your API key in your project's (C/Users/.../Sunshine/gradle.properties) is because gradle recommends that file being checked in to version control. If you have your API key in that file, you shouldn't check it into version control. If you put your API key in your GLOBAL gradle.properties (~/.gradle/gradle.properties), it will be recognized by your project's build.gradle, but won't be checked into version control, which is really the goal here.

Does that make sense?

@sidvenu
Copy link

sidvenu commented May 6, 2016

@halfjew22 But it does not recognize the variable if I put it in ~/.gradle

@technoplato
Copy link

@SiddharthVenu Uh oh! Shoot me an email (mlustig@google.com) and I'll help you fix that!

@ahewlett
Copy link

I just encountered this, thank you for posting the solution.

@poph2
Copy link

poph2 commented Jul 3, 2016

@Cattalins Your name has been engraved electronic stones of android history. You will not be forgotten.

@smsubham
Copy link

thanks for this solution , saved me hours of frustration.

@jmkuruvilla
Copy link

Thank you! That saved some headache.

@Josephaguele
Copy link

Why does it (OPEN_WEATHER_MAP_API_KEY) have to be written like this?
And what is the effect of having to code in the build area?

Please I need an answer to this questions

@AliHG
Copy link

AliHG commented Jul 31, 2016

@Josephaguele : naming OPEN_WEATHER_MAP_API_KEY like this will make no difference you can name it as you like but when you call it in your code "FetchWeatherTask" class BuildConfig.OPEN_WEATHER_MAP_API_KEY; make sure to change the name here too

@AliHG
Copy link

AliHG commented Jul 31, 2016

@Cattalins i'm pretty sure this is not how it's done

buildTypes.each { it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey }

and MyOpenWeatherMapApiKey is like calling a variable you declared in gradle.propertie

MyOpenWeatherMapApiKey="3194b70c58f9e0bc45dfd2279c1696c587"
in gradle.properties file your .gradle folder in your home directory

when adding your api key in your build.gradle file you risk when using github t

@Josephaguele
Copy link

Josephaguele commented Aug 1, 2016

I tried coding it like everyone has said, but it hasn't worked for me yet because when I try to run the sunshine app, it still shows the run time error.
Is this not the correct code?

buildTypes.each{
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', ""MyOpenWeatherMapApiKey""
}

Please can anyone help me out with this. And please must we have a correct and working API key before the Sunshine app will work?

@AliHG
Copy link

AliHG commented Aug 1, 2016

@Josephaguele this is the working code you add these lines exactly as it is in build.gradle file inside the android { } and this is my code
`apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.android.sunshine.app"
    minSdkVersion 10
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

buildTypes.each {
    it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY' , MyOpenWeatherMapApiKey
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
}
`

you only add

buildTypes.each { it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY' , MyOpenWeatherMapApiKey }
in the correct place inside the android { } scope and don't change any thing else in this file and click sync now

and you must have a working api Key for the sunshine app to work and this is my key " 3194b70c58f9e0bc45d2279c1696c587 " if you wish to use it

and to must add your api key to the gradle.properties file located in C:\Users\your username.gradle in windows and in your Home directory in mac and here is the code in my gradle.properties file

org.gradle.daemon=true MyOpenWeatherMapApiKey="3194b70c58f9e0bc45d2279c1696c587"

if you need any help i'm here

@Josephaguele
Copy link

Thanks,
I really appreciate. The key you gave to me worked. Please can I just use
it for the practical sessions. Please

On Mon, Aug 1, 2016 at 10:14 PM, Ali Makhion notifications@github.com
wrote:

@Josephaguele https://github.com/Josephaguele this is the working code
you add these lines exactly as it is in build.gradle file inside the
android { } and this is my code
`apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "com.example.android.sunshine.app"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY' , MyOpenWeatherMapApiKey
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
}
`

and you must have a working api Key for the sunshine app to work and this
is my key " 3194b70c58f9e0bc45d2279c1696c587 " if you wish to use it

and to must add your api key to the gradle.properties file located in
C:\Users\your username.gradle in windows and in your Home directory in mac
and here is the code in my gradle.properties file

org.gradle.daemon=true
MyOpenWeatherMapApiKey="3194b70c58f9e0bc45d2279c1696c587"

if you need any help i'm here


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#69 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATrEqSFZ5i5TaiKygsdNDwz37qdkbuyFks5qbmGlgaJpZM4GRqq-
.

@AliHG
Copy link

AliHG commented Aug 3, 2016

@Josephaguele it's yours 👍

@Uiyama
Copy link

Uiyama commented Aug 6, 2016

Thanks a lot. I really appreciate.

@Josephaguele
Copy link

Hi,

Please Is there any way I can get an updated explanation of Postal Code
Param. I really do not understand it .
I would be very grateful.
Thanks in anticipation.

On Sat, Aug 6, 2016 at 3:19 PM, Codenal notifications@github.com wrote:

Thanks a lot. I really appreciate.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#69 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATrEqTXqJ8wdvDtC2M-8aWBtYG4Xko5pks5qdJgKgaJpZM4GRqq-
.

@Josephaguele
Copy link

Josephaguele commented Aug 13, 2016

Please my android monitor screen is not showing the information as shown in the tutorial.
When I click the refresh button, this is what shows up on my screen.
capture
I hope this will do well.
The last two lines, which is the InputManager is what shows up on my android studio monitor screen when I click the refresh button

@kavoos
Copy link

kavoos commented Sep 22, 2016

If you create (global) gradle.properties yourself, you should make a PROPERTIES FILE and not TEXT DOCUMENT (via notepad or something like that!)
Your gradle.properties should be like this:
after
and it must be in C:\Users[user name].gradle
It contains: MyOpenWeatherMapApiKey="xxxx1111xxxx"
Your build.gradle should be like this:
...
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
}
...

@seiya021
Copy link

seiya021 commented Oct 8, 2016

Thank's Cattalins

@Josephaguele
Copy link

Thank you

On Sat, Oct 8, 2016 at 5:55 AM, seiya021 notifications@github.com wrote:

Thank's Cattalins


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#69 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATrEqe2qmkzYrY8xQnZA0DldBniDbm2Fks5qxyJfgaJpZM4GRqq-
.

@omerboyraz
Copy link

Thank you for help.

@rag-lab
Copy link

rag-lab commented Mar 10, 2017

ok, when changing the build.gradle file double check you inserted the code in the correct one. there's 2 here (Project and app), the code should be on the build.grade (app)

@sachinrkeche
Copy link

sachinrkeche commented Mar 11, 2017 via email

@AMT16
Copy link

AMT16 commented May 9, 2017

Thank you , that was helpful

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests