Error in build configuration in Android Studio

I am running the application in Android Studio. Below is the code:

strings.xml

<resources> <string name="google_nearby_api_key">XXXXXXXXXXXXXXXXXXXXXXXX</string> </resources> 

Manifest file

 <application <meta-data android:name="com.google.android.nearby.messages.API_KEY" android:value="@string/google_nearby_api_key"/> </application> 

build.gradle

 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 an error message:

 Error:(35, 0) Build Config field cannot have a null parameter 

Can anyone help with this?

+5
source share
1 answer

I checked on my machine that this works 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 line in:

app/build/generated/res/resValues/{build-type}/values/generated.xml

Now you can use the string in your application as @string/google_nearby_api_key .

Also, when I removed the key from local.properties , I get the same error:

 Error:(17, 1) A problem occurred evaluating project ':app'. > Build Config field cannot have a null parameter 

So you probably don't have a key in local.properties .

And you also seem to have manually added a line to your strings.xml resource strings.xml , you shouldn't do this if you want to hide your API key. Add it using the gradle assembly (the approach described above).

+2
source

Source: https://habr.com/ru/post/1274423/


All Articles