I am running a app in Android Studio. Following is the code:
<resources>
<string name="google_nearby_api_key">XXXXXXXXXXXXXXXXXXXXXXXX</string>
</resources>
<application
<meta-data
android:name="com.google.android.nearby.messages.API_KEY"
android:value="@string/google_nearby_api_key"/>
</application>
def filesAuthorityValue = applicationId + ".files"
manifestPlaceholders = [filesAuthority: filesAuthorityValue]
buildConfigField "String", "FILES_AUTORITY", "\"${filesAuthorityValue}\""
resValue "string", "google_nearby_api_key", getLocalProperties().getProperty("google_nearby_api_key")
I get the error:
Error:(35, 0) Build Config field cannot have a null parameter
Can anyone please help on this?
I checked on my machine this is working for me
local.properties
GOOGLE_NEARBY_API_KEY="XXXXXXXXXX"
build.gradle
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
resValue "string", "google_nearby_api_key", properties.getProperty('GOOGLE_NEARBY_API_KEY')
You will find the generated file with your string in:
app/build/generated/res/resValues/{build-type}/values/generated.xml
Now you can use the string in your app as @string/google_nearby_api_key
.
Also, when I removed the key from local.properties
I am getting the same error:
Error:(17, 1) A problem occurred evaluating project ':app'.
> Build Config field cannot have a null parameter
So, you probably do not have the key in your local.properties
.
And you also seemed to have manually added the string in your strings.xml
resource file, you shouldn't do this if you want to hide your API key. Inject it through your gradle
build (the above approach).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With