Get --dart-define environment variables in native iOS and Android - android

I am trying to find a way to access the environment variables provided by --dart-define inside native iOS and Android code.
Is there any way to do this?
I have tried the guide explained in https://binary-studio.com/2020/06/23/flutter-3/ but that doesn't work as what gets written to the generated .xcconfig is not separated by = but instead by %3D. And I get the error
error: .../ios/Flutter/DEFINEEnvironment.xcconfig:2: expected a ‘=’, but found % (in target 'Runner' from project 'Runner')
The file DEFINEEnvironment.xcconfig gets generated with the following content MY_VAR%3DMY_VALUE instead of MY_VAR=MY_VALUE
UPDATE
This seems to be happening because when reading from the args passed to --dart-define it must be encoding = into %3D. And I don't know how prevent that from happening

It seems that the script has been changed and now includes the necessary code to decode the strings.
The post-action script that needs to be added to Scheme is:
function urldecode() { : "${*//+/ }"; echo "${_//%/\\x}"; }
IFS=',' read -r -a define_items <<< "$DART_DEFINES"
for index in "${!define_items[#]}"
do
define_items[$index]=$(urldecode "${define_items[$index]}");
done
printf "%s\n" "${define_items[#]}" > ${SRCROOT}/Flutter/DEFINEEnvironment.xcconfig

Related

How to get an ENV var available in project which uses Android.mk

I have an Android project which uses Android.mk files for the setup. I would like to introduce Build Variants to the project and based on a build var such as BUILD_BRAND to perform some UI changes.
My case is:
I have BUILD_BRAND exported on my Ubuntu in the .bashrc.
If I echo $BUILD_BRAND I would get the value printed in the terminal.
I also do $(warning $(BUILD_BRAND)) and I can see during the build the value is printed so it is available.
But when I try to do System.getEnv("BUILD_BRAND"); in an activity, a null is returned.
The question is how to make this value under BUILD_BRAND to become globally available to the project.
Thanks!
In my case the solution was to use SystemProperties.get("the.property.name").
The "the.property.name" was set in the Makefile.mk located in the core.
I also find out that I can export ENV vars to the project during build time using the same Makefile.mk.
N.B - You can't access an env var during runtime directly using System.getEnv() !

Delphi 11: Find correct toolsversion for MSBuild programmatically

We're upgrading to Delphi 11.1 from 10.4.
We have a few scripts which build and deploy Android projects. They assemble an msbuild command that looked like this:
msbuild someproject.dproj /v:q /p:Platform=Android /t:Build;Deploy /p:Config=Release /p:BT_BuildType=AppStore
With 11.1, this throws an error message:
C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\CodeGear.Common.Targets(940,7): error MSB4036: The "XmlPeek" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Windows\Microsoft.NET\Framework\v2.0.50727" directory. [someproject.dproj]
Now, C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\rsvars.bat, which is used by all of our build scripts, explicitly sets the .NET framework as below:
#SET FrameworkDir=C:\Windows\Microsoft.NET\Framework\v4.0.30319
#SET FrameworkVersion=v4.5
After some research, I hit on the idea of adding a toolsversion parameter to the msbuild command as below, and this worked:
msbuild someproject.dproj /v:q /p:Platform=Android /t:Build;Deploy /p:Config=Release /p:BT_BuildType=AppStore /toolsversion:4.0
This is all well and good, but I would prefer not to hard-code the toolsversion number in the script(s).
Is there a way I can programmatically obtain the correct value of the toolsversion that Delphi itself is using when it generates builds, etc.?
I assume that just finding the highest .NET version installed will not suffice (and even then, one has to "translate" that to a toolsversion). It has to marry up with whatever Delphi is doing (e.g., in the CodeGear.Common.Targets file referenced in the original error message).
This is a bug in Delphi 11.1 that has at least 3 bug reports: RSP-37855, RSP-38466, and RSP-38467.
You can add /tv:4.0 to your MSBuild command line, or modify the first line in the .dproj file to:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Build">
Assuming that rsvars.bat has been run,
FOR %%v IN ("%frameworkdir%") DO SET "toolsversion=%%~nv"
ECHO msbuild ...blah... /toolsversion:%toolsversion:~1%
The variable frameworkdir will be set by rsvars.bat. The for command parses its value (eg. C:\Windows\Microsoft.NET\Framework\v4.0.30319 as though it is a filename, and picks v4.0 as the "filename" (~n modifier [filename] of the metavariable %%v)
Then use the value assigned to toolsversion, starting at character 1 (where the first character is "character 0")
--- Given more info in comment
FOR %%v IN ("%frameworkdir%") DO ECHO %%~nxv|FINDSTR /R ".*\..*\.">nul&IF ERRORLEVEL 1 (SET "toolsversion=%%~nxv") ELSE SET "toolsversion=%%~nv"
Oh ye of little faith :)

Kivy application does not work on Android

I want write simple application in Python for Android using kivy. Sadly when I start example code I see only splash screen and few second later application finish work. There is a huge problem with debugging because adb on Linux Mint does not detect my device.
Can someone look at my code and tell my why?
To build application I use buildozer. You can also see create_env script to check all dependencies are there.
Best regards.
Draqun
EDIT:
I started debugging my application. Conclusion:
buildozer + python3 + kivy is a bad idea
if I use kivy.uix.button.Button when text attribute is str than I got exception "AttributeError: 'str' object has no attribute 'decode'"
if I use kivy.uix.button.Button when text attribute is bytes than I got exception "ValueError: Button.text accept only str"
It looks like loop with no solution. Some idea when I should report it?
Exception is in .buildozer/android/platform/build/build/python-installs/pad/android/init.py" file so it does not look like kivy and/or buildozer exception.
I've used python-for android tool and faced with the same errors. But in my case, app didn't run at all - crashed from splash screen. Finally, I've found a solution. You can try the same way.
So my pipeline was python3 + python-for-android (p4a tool, python-for-android, from master branch) + kivy (1.10.1)
There is a file "_android.pyx" for android building recipe (full list of avaliable p4a recipes you can see by command p4a recipes). This file is, possibly, used by Buildozer, and exactly used by P4A during APK building procedure. You need to fix it.
You may find it's location in Ubuntu (for example) via:
sudo updatedb
locate _android.pyx
It's path should be something like:
~/.local/lib/python3.6/site-packages/pythonforandroid/recipes/android/src/android/_android.pyx
There should be a string:
python_act = autoclass(JAVA_NAMESPACE.decode('utf-8') + u'.PythonActivity')
so you should change it - something like this:
python_act = autoclass(str(JAVA_NAMESPACE) + u'.PythonActivity'),
or just use some hardcode:
python_act = autoclass("org/kivy/android/PythonActivity")
Or there might be the other decode() usage in sources.
The reason: differences between Python2 and Python3 - the decode() method is usable on the equivalent binary data type in either Python 2 or 3, but it can’t be used by the textual data type consistently between Python 2 and 3 because str in Python 3 doesn’t have the method decode function has different realisation in Python3. More details are here:
pyporting features
issues p4a's github
Hope, it will help you somehow.

"Error: Unexpected close tag" Cordova/PhoneGap

When running the command cordova platform add android, I get a bunch of errors popping up in the terminal.
Caelans-MBP:HiltonExtraordinaryFB Caelan$ cordova platform add android
Creating android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.phonegap.hiltonsimplyfb
Name: Hilton F&B
Android target: android-19
Copying template files...
Project successfully created.
Error: Unexpected close tag
Line: 8
Column: 12
Char: >
at error (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/elementtree/node_modules/sax/lib/sax.js:347:8)
at strictFail (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/elementtree/node_modules/sax/lib/sax.js:364:22)
at closeTag (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/elementtree/node_modules/sax/lib/sax.js:523:7)
at Object.write (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/elementtree/node_modules/sax/lib/sax.js:948:29)
at XMLParser.feed (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/elementtree/lib/parsers/sax.js:48:15)
at ElementTree.parse (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/elementtree/lib/elementtree.js:263:10)
at Object.exports.XML (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/elementtree/lib/elementtree.js:593:13)
at Object.module.exports.parseElementtreeSync (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/util/xml-helpers.js:126:38)
at android_parser.update_from_config (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/metadata/android_parser.js:221:23)
at android_parser.update_project (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/metadata/android_parser.js:349:14)
Caelans-MBP:HiltonExtraordinaryFB Caelan$
Is there any way I can resolve these errors so I can continue.
Without seeing your config.xml file it's hard to troubleshoot, but I'll bet it's the name of your app:
Name: Hilton F&B
Since config.xml must be valid XML, make sure you're using the & ampersand entity and not a raw ampersand, which has meaning in XML syntax.
I also had the same issue and wanted to share my experience. The problem was Unexpected close tag, in your config.xml file you forgot to close one or two tags, if you look at the line which is shown as error, there is not error even, but somewhre in your config.xml file there is tag not closed. Please, make sure all tags have closed correctly.
In my case, I was missing one closing tag in the string that I was parsing to XML. It had a starting tag not closing tag.
Make sure to check all the Tags have starting and closing tags.
If you have XML on runtime and cannot be checked manually, You can use an amazing npm package which provide validate method to check if XML is valid.
npm link: https://www.npmjs.com/package/fast-xml-parser
example:
const { XMLValidator } = require('fast-xml-parser');
const result = XMLValidator.validate(
"<root>Run the , ...' >/etc/hosts.allow where each <net>/<mask> combination (for example, '192.168.1.0/255.255.255.0') represents one network block in use by your organization that requires access to this system</root>",
{
allowBooleanAttributes: true,
}
);
Just sharing, might be helpful for someone.

Google App Engine Python Upload Error

I am not sure why I am getting this error when trying to deploy my Python API via the Google App Engine Launcher.
Any Ideas what it is that I have going on here? Below is the error and my associated App.yaml file.
appcfg.py: error: Error parsing C:\Users\MYNAME\Desktop\Workspace\Imhotep\Imhotep\app.yaml: while parsing a block mapping
in "C:\Users\MYNAME\Desktop\Workspace\Imhotep\Imhotep\app.yaml", line 1, column 1
expected <block end>, but found '<block sequence start>'
in "C:\Users\MYNAME\Desktop\Workspace\Imhotep\Imhotep\app.yaml", line 14, column 2.
2013-11-17 20:37:33 (Process exited with code 2)
application: <IHAVEMYAPPIDHERE - PROVIDED BY GAE>
version: 1
runtime: python27
threadsafe: true
api_version: 1
handlers:
# Static assets
- url: /images
static_dir: static/images
# Endpoints handler
- url: /_ah/spi/.*
script: imhotep_api.APPLICATION
Whitespace is important in yaml files.
It looks like there's an extra space in front of the 2nd url line.
I'm not sure if the extra blank lines cause problems.
Oh, and if you're having problems deploying, it probably means you should have tested locally first.
I just noticed that in all of my app.yaml files threadsafe is set to 'yes' and not 'true'. Also, possibly more importantly, I have never seen the '.APPLICATION' extension in a .yaml file. In all of mine, and all the .yaml's I have seen it is '.app'.
Ex: script: imhotep_api.app
sorry if that's of no help.

Categories

Resources