How can I get user defined Environment variables? - android

I would like to use self defined Environment variables in my source code. I use System.getenv() to do this and the code line looks like this. Log.d("MyTest","== MyEnv " + System.getenv("AP") + " ANDROID_ASSETS:" + System.getenv("ANDROID_ASSETS"));
before I execute my code I define my AP variable with export: export AP="12345" and the this is my output of set command
ANDROID_ASSETS=/system/app
ANDROID_BOOTLOGO=1
ANDROID_DATA=/data
ANDROID_PROPERTY_WORKSPACE=9,32768
ANDROID_ROOT=/system
AP=12345
...
Then I execute my code and I get this line from logcat
D/MyTest( 5363): == MyEnv null ANDROID_ASSETS:/system/app
The value for my defined Environment variable is null. Any suggestions on why it didn't work?

Export command works for one session only, not for a whole system. You can't set environment variables that way. getprop/setprop doesn't work neither.
I had similar problem and found that easiest way to pass some arguments from console is to do something like:
echo "12345" > /sdcard/myapp/args/AP
Then read this file from Java.

Related

How to write in C, "ip -6 route add default dev wlan0"

I would like to write some C code , running in Android(linux) C program to set default route, ip -6 route add default dev wlan0.
Would appreciate if you have any idea, please let me know.
Best Regards
System/execl should work. But remember:
with execl you must put the full path to the executable. Also remember that you must put each parameter in its own string, and that the first parameter must be the binary program itself
you will need to run your program with root privileges to do what you want

How I pass params from Jenkins to build.gradle?

I want to pass value to my build.gradle file through jenkins (build with params).
I have a String and I need to use this String params to make my release ?
Parametrized builds provide those parameters as environmental variables, like $PARAM_NAME. Use your favorites gradle method of getting environmental variables, like System.getenv('PARAM_NAME') or environmentString = "$System.env.PARAM_NAME"
In General configuration set "This project is parameterized" checkbox to true, and set String/stash/choice/int parameter as you wish for , the name field is your variable name. In your dev project , in the gradle file just grab this variable by calling simple getEnv method.
String inputFromJenkins = System.getenv('VARIABLE_NAME')
println('VARIABLE_NAME = ' + inputFromJenkins)
for extra documentation: gradle env variables documentation
You can use the plugin This build is Parameterized and select string Parameter int that. In this you can define parameter name and value. Suppose PARA is your parameter name and value is its default value, then you can pass this value to build.gradle as $PARA. For more details see https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build.

Looking for a way to write to a file the name of the step and the scenario

I’m writing the error/failures of my steps to a file with this function:
def addToErrorFile(errorName)
open('error.txt', 'a') { |f| f.puts"#{errorName}"}
end
This function is located in a lot of places in my test flow.
To make it easier to read it in the end, I would like to add the step name (Then /I go to…) and also the scenario (Scenario: login to..).
Is there a way to copy those into the function?
You could put some code in your before and after scenario hooks that writes to the error log. That should break it up a bit and make it easier to read. Something like this.
Before do |scenario|
your_logging_method(scenario.name)
end
After do |scenario|
your_logging_method(scenario.name)
end
And there is an AfterStep hook too, though I haven't used it.
AfterStep do |step|
another_logging_method(step)
end
You may have to call some methods on the step variable to get it in a useful format.
Here's a link to the cucumber hooks documentatioon - https://github.com/cucumber/cucumber/wiki/Hooks
it wouldn't be better to use ruby (begin rescue ensure ) and put the code in there. You save your test session and you can progress your test to next steps, where you can put line of code to save name of next step to file

Test in init.rc if a property is unset

How can you check if a property is unset in init.rc:
In the following example test.b is not yet set
on property:test.a=1 && test.b=<unset>
# do something
Reading queue_property_triggers1 it seems that you can't. You'll probably need to change your code logic.

how to get environment variable value in Android.mk?

Any possibility to get environment variable value inside Android.mk?
For example
#export MYBASEDIR=/home/whoami/base
And, inside Android.mk How to get MYBASEDIR value ?
Bear with me for very basic question.
All environment variables are imported by make as make macros automatically.
So, just use $(MYBASEDIR) in the makefile.

Categories

Resources