Error when building - Could not find property 'MyOpenWeatherMapApiKey' - java

i got this error from gradle when i try to build the project after i put the api key in gradle file
android {
.....
buildTypes.each {
it.buildConfigField 'String', 'cedf6......80c62', MyOpenWeatherMapApiKey
}
}
this error i got when i build the project :-
Error:(22, 0) Could not find property 'MyOpenWeatherMapApiKey' on com.android.build.gradle.AppExtension_Decorated#48bee3b8.
Open File
i think i have to make a file in some folder , but i don't know in which folder ? ,
and what i ishould to type inside the file after i create it ?

Since you are using a String you have to use this syntax:
buildConfigField "String" , "OPEN_WEATHER_MAP_API_KEY" , "\"XXXXX-XXXXX-XXX\""
The last parameter has to be a String
Otherwise you can use something like this:
resValue "string", "OPEN_WEATHER_MAP_API_KEY", "\"XXXXX-XXXXX-XXX\""
The first case generates a constants iin your BuildConfig file.
The second case generates a string resource value that can be accessed using the #string/OPEN_WEATHER_MAP_API_KEY annotation.
Credits: Could not find property 'xxxx' on com.android.build.gradle.AppExtension_Decorated

Alternatively, you can use a combination of double quotes and single quotes to avoid the escape characters (where xxx is your API):
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', '"xxxxxxxxx"'
}

Related

How can I add a "aar" library to the AOSP?

I am building my own ROM and want to use a aar file Library in one system service.
Is there any way this could be achieved?
If you are using Android.bp this can be done via android_library_import module type (link to soong spec).
Also, if you try to grep the AOSP source tree, you will easily find many examples of its use, for example: packages/apps/Settings/Android.bp:
android_library_import {
name: "contextualcards",
aars: ["libs/contextualcards.aar"],
}
android_library {
name: "Settings-core",
....
srcs: ["src/**/*.java"],
static_libs: [
...
"contextualcards",
...
}

Loading JSON data into Elasticsearch and Kibana using logstash configuration [ConfigurationError: translation missing]

I am trying to import some JSON data into my Elasticsearch and Kibana cluster using logstash and its configuration. I am using a JSON file having three fields.
elasticsearch version used: 6.5.3
logstash version used: 6.5.3
Logstash version used: 6.5.3
Sample JSON file: test.json
{"name":"Jonathan","score":"9.9","address":"New Delhi"}
{"name":"Sam","score":"8.9","address":"New York"}
{"name":"Michelle","score":"9.0","address":"California"}
My configuration file: test.config
input{
file{
path => "/Users/amit/elasticsearch/data/test.json"
codec => json
sincedb_path => "/dev/null"
start_position => "beginning"
}
}
filter{
json{
source => "message"
}
mutate{
convert => {
"name" => "text"
"score" => "float"
"address" => "text"
}
}
}
output{
elasticsearch{
hosts => "localhost:9200"
index => "test"
}
stdout { codec => rubydebug }
}
I am trying to import this data into elasticsearch using logstash using the following command:
bin/logstash -f ../../data/test.config
But I get the following error message:
[2018-12-27T20:18:41,439][ERROR][logstash.pipeline] Error registering
plugin {:pipeline_id=>"main",
:plugin=>"#,
#filter={\"name\"=>\"text\",
\"score\"=>\"float\", \"address\"=>\"text\"},
id=>\"4a292b8b637c63de89c36b730212b3c706307f5fd385080369ac0cbeac3c2d53\", enable_metric=>true, periodic_flush=>false>>", :error=>"translation
missing: en.logstash.agent.configuration.invalid_plugin_register",
:thread=>"#"}
[2018-12-27T20:18:41,452][ERROR][logstash.pipeline] Pipeline aborted
due to error {:pipeline_id=>"main",
:exception=>#,
:backtrace=>["/Users/amit/elasticsearch/logstash/logstash-6.5.3/vendor/bundle/jruby/2.3.0/gems/logstash-filter-mutate-3.3.4/lib/logstash/filters/mutate.rb:219:in
block in register'", "org/jruby/RubyHash.java:1343:ineach'",
"/Users/amit/elasticsearch/logstash/logstash-6.5.3/vendor/bundle/jruby/2.3.0/gems/logstash-filter-mutate-3.3.4/lib/logstash/filters/mutate.rb:217:in
register'",
"/Users/amit/elasticsearch/logstash/logstash-6.5.3/logstash-core/lib/logstash/pipeline.rb:242:in
register_plugin'",
"/Users/amit/elasticsearch/logstash/logstash-6.5.3/logstash-core/lib/logstash/pipeline.rb:253:in
block in register_plugins'", "org/jruby/RubyArray.java:1734:in
each'",
"/Users/amit/elasticsearch/logstash/logstash-6.5.3/logstash-core/lib/logstash/pipeline.rb:253:in
register_plugins'",
"/Users/amit/elasticsearch/logstash/logstash-6.5.3/logstash-core/lib/logstash/pipeline.rb:595:in
maybe_setup_out_plugins'",
"/Users/amit/elasticsearch/logstash/logstash-6.5.3/logstash-core/lib/logstash/pipeline.rb:263:in
start_workers'",
"/Users/amit/elasticsearch/logstash/logstash-6.5.3/logstash-core/lib/logstash/pipeline.rb:200:in
run'",
"/Users/amit/elasticsearch/logstash/logstash-6.5.3/logstash-core/lib/logstash/pipeline.rb:160:in
`block in start'"], :thread=>"#"}
[2018-12-27T20:18:41,474][ERROR][logstash.agent] Failed to execute
action {:id=>:main,
:action_type=>LogStash::ConvergeResult::FailedAction, :message=>"Could
not execute action: PipelineAction::Create, action_result:
false", :backtrace=>nil}
[2018-12-27T20:18:41,705][INFO ][logstash.agent] Successfully started
Logstash API endpoint {:port=>9600}
Also, if I remove the mutate filter from the file test.config, it works fine. But, I want to change the type of score variable to float. Is there a problem in trying to mutate the fields during parsing or I am missing something else? Thanks :)
https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-convert
Seems you cant use "text", use "name" => "string"

How does gradle parses a dependency in string notation

As per the documentation http://gradle.org/docs/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html
A string dependency notation looks like "group:name:version:classifier#extension"
How do we specify the type (http://ant.apache.org/ivy/history/latest-milestone/terminology.html#type) here?
You can declare like below:
artifacts {
archives file: '', name: '', type: 'jar'
}
and for more information here.

Default value for a $PROPERTY in Gradle

How can I specify a default value for this simple build.gradle script:
println "Hello $build_version"
So that I don't get the error:
A problem occurred evaluating root project 'hello_gradle'.
> Could not find property '$build_version' on root project 'hello_gradle'.
I tried some of the operators, checking for nulls etc, but I think just the reference to the property makes it fail. I could fix that by always providing the property, but that's less than ideal.
gradle -Pbuild_version=World
if (!project.hasProperty("build_version")) {
ext.build_version = "1.0"
}
This checks if the property exists and assigns a default value if not:
def build_version=project.properties['build_version'] ?: "nokey"
Starting from Gradle 2.13:
ext.buildVersion = project.findProperty('build_version') ?: '1.0'
This worked for me:
def AWS_ACCESS_KEY="nokey"
def AWS_SECRET_KEY="nokey"
if (project.hasProperty("AWS_ACCESS_KEY")) {
AWS_ACCESS_KEY=project.get("AWS_ACCESS_KEY")
}
if (project.hasProperty("AWS_SECRET_KEY")) {
AWS_SECRET_KEY=project.get("AWS_SECRET_KEY")
}
Another way to make it short and nice:
ext.buildVersion = project.getProperties().getOrDefault("build_version", "1.0")
I'm adding this to my build.gradle:
String propValue(String propName, String defValue) {
(project.hasProperty(propName) && project.getProperty(propName)) ? project.getProperty(propName) : defValue
}
then use when needed propValue('build_version', 'nokey').
Have you tried this?:
println "Hello ${project.getProperty('build_version', 'default_string_value')}"
One-liner using ternary operator:
println "Hello ${project.hasProperty('build_version') ? getProperty('build_version') : 'World'}"
gradle <your_task> -Pbuild_version=SomethingElse

Including subprojects using a wildcard in a Gradle settings file

In Gradle you need to define subprojects to be built in a 'settings.gradle' file. To build three child projects, you would do something like this:
include "child1", "child2", "child3"
The problem I'm having is that I have quite a few projects to include. Is there a way to use a wildcard in this definition? I'm looking for something like this:
include "*"
That of course does not work. This would be a lot easier to work with since I have many subprojects to include. Is there a way to automatically include subdirectories as projects?
include rootDir.listFiles().findAll {
it.isDirectory()
&& !( it =~ ".*/\\..*") // don't add directories starting with '.'
&& !( it =~ "^\\..*") // don't add directories starting with '.'
}.collect {
it.getName()
}.toArray(new java.lang.String[0])
Did the trick for me
The following code supports a project hierarchy of arbitrary depth:
rootDir.eachFileRecurse { f ->
if ( f.name == "build.gradle" ) {
String relativePath = f.parentFile.absolutePath - rootDir.absolutePath
String projectName = relativePath.replaceAll("[\\\\\\/]", ":")
include projectName
}
}
Can you do something like:
include (1..10).collect { "Child$it" }
To include "Child1" up to "Child10"?
Obviously, you'd need to change the collect to some sort of folder scan, but it that quick test works then the scan has a good chance

Categories

Resources