Kivy buildozer: how to deploy to specific android device - kivy

I have multiple devices (both AVDs and hardware) connected to my PC, but I want to deploy to a specific device with buildozer. How can I do that if disconnecting other devices is not an option?

Buildozer installs to android via adb. So you have to check the documentation of adb and check how it is modified in the buildozer startup script.
http://www.appsdeveloperblog.com/install-apk-on-device-adb/
and https://pypi.org/project/buildozer/
Think the command will be like
buildozer android deploy adb --s <DEVICE_NAME>

As on JAN 18 2020:
It seems like buildozer 1.0.1-dev0 does not have enough flexibility to accomplish this task. Commands like buildozer android deploy adb -s <DEVICE_ID> just ignore DEVICE_ID and install apk on all available devices.
There is a handy buildozer serve command, but that is slow and requires to manually answer to all security dialogs.
Using adb directly is a fair option, e.g.:
adb -s DEVICE_ID install -r your.apk
But if there are a lot of devices (armv7 and x86), it'd be a chore to type this every time. So I ended up with a script that is placed in the project directory:
import sys
import subprocess
# TODO: edit your custom settings
ADB_EXE = "/home/your_username/Android/Sdk/platform-tools/adb"
APK_X86 = "/path/to/apk/x86/bin/your_project__x86-0.1-x86-debug.apk"
APK_ARMV7 = "/path/to/apk/armv7/bin/your_project__armeabi-v7a-0.1-armeabi-v7a-debug.apk"
DEVICES = {
# DEVICE_PSEUDO_NAME: ("DEVICE_ID", "PATH_TO_APK")
"pixtab": ("emulator-5554", APK_X86),
"pix": ("emulator-5556", APK_X86),
"nexus4": ("004a900e1b268111", APK_ARMV7),
"nomi": ("SSI1216C111031288", APK_ARMV7),
}
def run():
global ADB_EXE
global DEVICES
if len(sys.argv) == 1:
print("Please, specify device.")
return
if sys.argv[1] == "list":
# print all available android devices
res = subprocess.check_output([ADB_EXE, "devices"])
for line in res.splitlines():
print(line)
return
dev_name = sys.argv[1]
print(f"Selected device: {dev_name}")
if dev_name not in DEVICES:
print(f"Device is not in the list, skipping.")
return
dev_id, apk = DEVICES[dev_name]
# "-r" means force install
res = subprocess.check_output([ADB_EXE, "-s", dev_id, "install", "-r", apk])
for line in res.splitlines():
print(line)
print(f"-- Deployment into {dev_id} complete.")
if __name__ == "__main__":
run()
To list all devices:
python3 dp.py list
To deploy specific apk to specific device:
python3 dp.py YOUR_DEVICE_PSEUDO_NAME

Related

Xcode 12.4 React native build failed in IOS Showing All Messages Command PhaseScriptExecution failed with a nonzero exit code

i am new in react native i want to run react native app in IOS after react-native init, app not run in IOS show some error
Showing All Messages
bash: Native/social_login/socialLogin/node_modules/react-native/scripts/../Libraries: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
and build failed please help me
versions
"react": "17.0.1",
"react-native": "0.64.0"
command line tools : Xcode 12.4 (12D4e)
This happened also to me upgrading from 0.63 to 0.64. After trying all solutions I followed a solution moving the folder to a directory where the path contain no spaces and it works and build the app successfully.
Solution to React Native 0.64 build fail
In order for this to work properly follow these steps:
If you previously installed a global react-native-cli package, please
remove it as it may cause unexpected issues (i.e. npm uninstall -g
react-native-cli)
Move the project folder in a path with no spaces (i.e. ~/sub folder
name/ReactNativeApp won't work till you have spaces in the path, so
move in a path like ~/folder/ReactNativeApp)
Then cd into the project folder and upgrade react native to the
latest version with npx react-native upgrade and resolve conflicts if
any
After upgrading remove the node_modules folder and the yarn.lock from
the root and the podfile.lock and Pods folder from ios subfolder
Then cd back to the root and run yarn install && npx pod-install
Now run again your app in Xcode or your IDE and it works
Crazy and absurd that a space in the path-name could cause this issue
This is nothing just an issue with the scheme name for me, in my case my scheme name contains whitespace e.g. "ABC staging", which is not allowed, it got fixed after deleting and creating a new scheme with the name "ABC-staging".
in the case of react-native 0.67^, you may need to apply these changes as well
change line no 7
set -e. ==> set +e
in
node_modules/react-native/scripts/find-node.sh
then use patch-package using the following command :
npx patch-package react-native
this will create a patch file inside the patch folder in root, then you can add in the post-install script in package.json:
"postinstall": "npx patch-package"
This command will run each time a new package is getting added to the project and auto-fix react-native find-node. sh.
Try to run pod install in ios folder
cd ios && pod install
Then when it's done go back to your main folder and run
yarn run ios
If that doesn't work, check out the solutions here
Xcode 10.2.1 Command PhaseScriptExecution failed with a nonzero exit code
There seems to be an issue with coreutils on macOS.
What fixed it for me is:
brew install coreutils
brew install findutils
brew install gnu-sed
Finally change the node_modules/react-native/scripts/generate-specs.sh to:
#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# This script collects the JavaScript spec definitions for core
# native modules and components, then uses react-native-codegen
# to generate native code.
#
# Optionally, set these envvars to override defaults:
# - SRCS_DIR: Path to JavaScript sources
# - CODEGEN_MODULES_LIBRARY_NAME: Defaults to FBReactNativeSpec
# - CODEGEN_MODULES_OUTPUT_DIR: Defaults to React/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_MODULES_LIBRARY_NAME
# - CODEGEN_COMPONENTS_LIBRARY_NAME: Defaults to rncore
# - CODEGEN_COMPONENTS_OUTPUT_DIR: Defaults to ReactCommon/react/renderer/components/$CODEGEN_COMPONENTS_LIBRARY_NAME
#
# Usage:
# ./scripts/generate-specs.sh
# SRCS_DIR=myapp/js CODEGEN_MODULES_LIBRARY_NAME=MySpecs CODEGEN_MODULES_OUTPUT_DIR=myapp/MySpecs ./scripts/generate-specs.sh
#
# shellcheck disable=SC2038
set -e
THIS_DIR=$(cd -P "$(gdirname "$(greadlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
TEMP_DIR=$(gmktemp -d /tmp/react-native-codegen-XXXXXXXX)
RN_DIR=$(cd "$THIS_DIR/.." && pwd)
# find node path
source "$RN_DIR/scripts/find-node.sh"
NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
USE_FABRIC="${USE_FABRIC:-0}"
cleanup () {
set +e
grm -rf "$TEMP_DIR"
set -e
}
describe () {
printf "\\n\\n>>>>> %s\\n\\n\\n" "$1"
}
main() {
SRCS_DIR=${SRCS_DIR:-$(cd "$RN_DIR/Libraries" && pwd)}
CODEGEN_MODULES_LIBRARY_NAME=${CODEGEN_MODULES_LIBRARY_NAME:-FBReactNativeSpec}
CODEGEN_COMPONENTS_LIBRARY_NAME=${CODEGEN_COMPONENTS_LIBRARY_NAME:-rncore}
CODEGEN_MODULES_OUTPUT_DIR=${CODEGEN_MODULES_OUTPUT_DIR:-"$RN_DIR/React/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_MODULES_LIBRARY_NAME"}
# TODO: $CODEGEN_COMPONENTS_PATH should be programmatically specified, and may change with use_frameworks! support.
CODEGEN_COMPONENTS_PATH="ReactCommon/react/renderer/components"
CODEGEN_COMPONENTS_OUTPUT_DIR=${CODEGEN_COMPONENTS_OUTPUT_DIR:-"$RN_DIR/$CODEGEN_COMPONENTS_PATH/$CODEGEN_COMPONENTS_LIBRARY_NAME"}
TEMP_OUTPUT_DIR="$TEMP_DIR/out"
SCHEMA_FILE="$TEMP_DIR/schema.json"
if [ -z "$NODE_BINARY" ]; then
echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2
exit 1
fi
CODEGEN_PATH=$("$NODE_BINARY" -e "console.log(require('path').dirname(require.resolve('react-native-codegen/package.json')))")
# Special case for running CodeGen from source: build it
if [ ! -d "$CODEGEN_PATH/lib" ]; then
describe "Building react-native-codegen package"
bash "$CODEGEN_PATH/scripts/oss/build.sh"
fi
describe "Generating schema from flow types"
"$NODE_BINARY" "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR"
describe "Generating native code from schema (iOS)"
pushd "$RN_DIR" >/dev/null || exit 1
"$NODE_BINARY" scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$CODEGEN_MODULES_LIBRARY_NAME"
popd >/dev/null || exit 1
describe "Copying output to final directory"
gmkdir -p "$CODEGEN_COMPONENTS_OUTPUT_DIR" "$CODEGEN_MODULES_OUTPUT_DIR"
gcp -R "$TEMP_OUTPUT_DIR/$CODEGEN_MODULES_LIBRARY_NAME.h" "$TEMP_OUTPUT_DIR/$CODEGEN_MODULES_LIBRARY_NAME-generated.mm" "$CODEGEN_MODULES_OUTPUT_DIR" || exit 1
gfind "$TEMP_OUTPUT_DIR" -type f | gxargs gsed -i.bak "s/$CODEGEN_MODULES_LIBRARY_NAME/$CODEGEN_COMPONENTS_LIBRARY_NAME/g" || exit 1
gfind "$TEMP_OUTPUT_DIR" -type f -not -iname "$CODEGEN_MODULES_LIBRARY_NAME*" -exec cp '{}' "$CODEGEN_COMPONENTS_OUTPUT_DIR/" ';' || exit 1
echo >&2 'Done.'
}
trap cleanup EXIT
main "$#"
notice that some commands are starting with g like greadlink etc.
if your get invalid identifier error in react-native-xcode.sh then under Build Phases -> Bundle React Native code and images it should be: (notice the double quotes):
set -e
export NODE_BINARY="node ../node_modules/react-native/scripts/react-native-xcode.sh"
use patch-package react-native to patch it (if project is being developed on different machines then they must install the brew packages above)
For me it was just having a space in folder name which was in the path of project folder from root.
I had to delete the contents of my ~/.bash_profile file.
I don't even use bash, but some other script populated the file and that broke my build. Deleting the contents fixed the build, immediately. Might not work for you, but thought I'd share.
I'm running Xcode 13.4.1
Installed cocoapods using brew install cocoapods (https://brew.sh/index_es)
M2 apple chip
React Native 0.70
Actually after spending a whole lot of time trying different solutions none of them worked except for Giuseppe's answer. I had white spaces in my path
"/React Native/exampleProject"
1. Renamed folders/files to remove any white space in the path (creating a fresh project within the fixed path worked with no problems at all)
I didn't even had to execute pod install anymore in the ios folder
In my case, i had to export the right path to node
in your terminal type which node, copy the path and export it in ios/xcode.env
export NODE_BINARY="copied node path"
Ok, worth trying this.
(This usually happens if you had multiple imports or any imports missing)
As soon as we get this error message:
Always scroll up & read the issue if written in that log file. Any issues like syntax error or issue related to your js code.
If yes, you can fix that first & re build it.
In my case I had multiple imports of one of the RN components.
Adding $(ARCHS_STANDARD) to Valid Architectures in Build Settings solved it for me

How to detect hardware type (ESP32 or ESP8266) in MicroPython?

How can I detect if my MicroPython script is running on ESP32 or ESP8266?
I want to make it work on both platforms, but deep sleep requires different implementation depending on the hardware.
You can use uos.uname().sysname to detect the hardware platform.
Here is an example script:
import uos
print(uos.uname())
sysname = uos.uname().sysname
if sysname == 'esp32':
print('detected ESP32')
elif sysname == 'esp8266':
print('detected ESP8266')
else:
print('something else')
Demo script output on ESP8266:
$ ampy run detect.py
(sysname='esp8266', nodename='esp8266', release='2.2.0-dev(9422289)', version='v1.11-8-g48dcbbe60 on 2019-05-29', machine='ESP module with ESP8266')
detected ESP8266
Demo script output on ESP32:
$ ampy run detect.py
(sysname='esp32', nodename='esp32', release='1.11.0', version='v1.11 on 2019-05-29', machine='ESP32 module with ESP32')
detected ESP32

how can made lldb server launching a new process without attaching to the existed one?

I'm using ios-deploy to launch ios app automatically, it works fine but only a probem: it won't restart the app if it's already running.
I have studied its source code and learned it's using the lldb command to launch the app. the lldb script is (part):
def run_command(debugger, command, result, internal_dict):
device_app = internal_dict['fruitstrap_device_app']
args = command.split('--',1)
error = lldb.SBError()
lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec(device_app))
args_arr = []
if len(args) > 1:
args_arr = shlex.split(args[1])
args_arr = args_arr + shlex.split('{args}')
launchInfo = lldb.SBLaunchInfo(args_arr)
global listener
launchInfo.SetListener(listener)
#This env variable makes NSLog, CFLog and os_log messages get mirrored to stderr
#https://stackoverflow.com/a/39581193
launchInfo.SetEnvironmentEntries(['OS_ACTIVITY_DT_MODE=enable'], True)
lldb.target.Launch(launchInfo, error)
lockedstr = ': Locked'
if lockedstr in str(error):
print('\\nDevice Locked\\n')
os._exit(254)
else:
print(str(error))
the start command:
(lldb) command source -s 0
'/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap-lldb-prep-cmds-6a050aabefc708cb7fc6024c4dd1743080d6e20b'
Executing commands in
'/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap-lldb-prep-cmds-6a050aabefc708cb7fc6024c4dd1743080d6e20b'.
(lldb) platform select remote-ios --sysroot
'/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0
(16A366)/Symbols' Platform: remote-ios Connected: no SDK Path:
"/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0
(16A366)/Symbols" (lldb) target create
"/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos/mj.app" Current executable set to
'/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos/mj.app' (arm64). (lldb) script
fruitstrap_device_app="/private/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35/mj.app"
(lldb) script fruitstrap_connect_url="connect://127.0.0.1:62276"
(lldb) target modules search-paths add /usr
"/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0
(16A366)/Symbols/usr" /System
"/Users/wellbye/Library/Developer/Xcode/iOS DeviceSupport/12.0
(16A366)/Symbols/System"
"/private/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35"
"/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos"
"/var/containers/Bundle/Application/1FB0E7E3-6616-4789-8E6F-598C4F5AAC35"
"/Users/wellbye/git-repo/j/mj3d/Product/build/ios/Build/Products/Release-iphoneos"
/Developer "/Users/wellbye/Library/Developer/Xcode/iOS
DeviceSupport/12.0 (16A366)/Symbols/Developer" (lldb) command
script import
"/tmp/BB1ED2A3-3A3E-413A-935D-323D7A7533D1/fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.py"
(lldb) command script add -f
fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.connect_command
connect (lldb) command script add -s asynchronous -f
fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.run_command run
(lldb) command script add -s asynchronous -f
fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.autoexit_command
autoexit (lldb) command script add -s asynchronous -f
fruitstrap_6a050aabefc708cb7fc6024c4dd1743080d6e20b.safequit_command
safequit (lldb) connect (lldb) run
I have searched the lldb's python api reference, but haven't seen anything (args or flags) I could use for my purpose.
so how could we let the lldb server know it should kill the exist process and start a new one?
It depends on whether you are trying to support rerun behavior (i.e. you make a target, launch the process, then use the same target to re-run) or if you just want to kill off some instance of the app that was running - maybe because it was finger-launched on the device or whatever.
In the first case, since you are reusing the SBTarget, you can just check whether your target has a process (call target.process.IsValid()) and if does kill it with target.process.Kill() before launching.
But if lldb is not responsible for launching the extant copy of the app, then it won't know anything about it, and doesn't really have a way to kill it off.

iOS emulator location for UITesting

I am trying to run my UITests on Continuous Integration server (I am using Bitrise). So in one of my UITests I have the following:
let myLocationPin = app.otherElements["My Location"]
self.expectation(for: exists, evaluatedWith: myLocationPin, handler: nil)
self.waitForExpectations(timeout: 20, handler: nil)
expect(myLocationPin.exists).to(beTrue())
expect(myLocationPin.isHittable).to(beTrue())
myLocationPin.tap()
It works well on my local machine but as soon as the tests is being ran on the CI server it fails. I have found out that the reason is for the failure is that the emulator that runs the test doesn't have any selected location. I have tried to add a GPX file, but that didn't work either. Any suggestions ?
Did you select location on your local machine from the dropdown list before run?
If it is the case then you won't be able to use the graphical UI to do it on bitrise, however locations can be selected per scheme.
You can follow this post to set location on your schemes:
Automating Xcode' Debug > Simulate Location command
Update:
If the method above didn't solved the issue, another solution would be:
To change location in the simulator itself, you will need to add a script step before your UITest including the following script:
# download set-simulator-location
brew install lyft/formulae/set-simulator-location
# run simulator
export IOS_SIMULATOR_UDID=`instruments -s devices | grep "iPhone 6 (10.3) \[" | awk -F '[ ]' '{print $4}' | awk -F '[\[]' '{print $2}' | sed 's/.$//'`
echo $IOS_SIMULATOR_UDID
open -a "simulator" --args -CurrentDeviceUDID $IOS_SIMULATOR_UDID
# wait simulator to start fully
sleep 15
# set location
set-simulator-location -q London
Don't forget to change iPhone 6 (10.3) to the simulator you need and London to your own location, with -c flag you can set coordinates as well.
For more info about set-simulator-location visit: set-simulator-location
If you want custom location in your simulator then Select simulator and follor these two steps.
and change location

Simulate iPad using Cordova/PhoneGap emulator command

I would like to use the included ./emulator command with Cordova/PhoneGap to run my app in the iPad simulator from the command line.
The basic instructions are here:
http://docs.phonegap.com/en/2.2.0/guide_command-line_index.md.html
I've installed the iOS simulator from here:
https://github.com/phonegap/ios-sim
The documentation says it supports simulating an iPad from the command line. However, it opens by default to iPhone and changing the device to "iPad" closes the app (and it is not installed on the home screen). I've searched but can't find documentation to launch to simulate an iPad.
How do I run the Cordova ./emulator command to open to iPad?
It may be that you were using an old version of phonegap/cordova, but in version 3.4 the following works for me:
cordova emulate ios --target="iPad"
The Cordova emulate script is just a wrapper for the ios-sim command which you can use directly from the command line. Assuming your current working directory is the one with the emulate script in it, you can launch your build in the emulator in iPad mode with the following:
ios-sim launch ../build/myApp.app --family ipad --stderr console.log --stdout console.log &
The following is undoubtedly naive (I don't know shell-scripting), but I've hacked the emulate script to support a second command-line parameter which allows me to specify the device family. You might not be aware that the script already accepts a first parameter which allows you to specify the path to your project's .app file as it figures out the path if the parameter is not specified.
Update your version of the script with the following (GitHub fork here):
#! /bin/sh
#
# Licensing info removed for brevity
#
set -e
XCODE_VER=$(xcodebuild -version | head -n 1 | sed -e 's/Xcode //')
XCODE_MIN_VERSION="4.5"
if [[ "$XCODE_VER" < "$XCODE_MIN_VERSION" ]]; then
echo "Cordova can only run in Xcode version $XCODE_MIN_VERSION or greater."
exit 1
fi
CORDOVA_PATH=$( cd "$( dirname "$0" )" && pwd -P)
PROJECT_PATH="$(dirname "$CORDOVA_PATH")"
XCODEPROJ=$( ls "$PROJECT_PATH" | grep .xcodeproj )
PROJECT_NAME=$(basename "$XCODEPROJ" .xcodeproj)
APP_PATH=$1
DEVICE_FAMILY=$2
if [ $# -lt 1 ]; then
APP_PATH="$PROJECT_PATH/build/$PROJECT_NAME.app"
DEVICE_FAMILY=iphone
fi
if [ ! -d "$APP_PATH" ]; then
echo "Project '$APP_PATH' is not built. Building."
$CORDOVA_PATH/build || exit $?
fi
if [ ! -d "$APP_PATH" ]; then
echo "$APP_PATH not found to emulate."
exit 1
fi
# launch using ios-sim
if which ios-sim >/dev/null; then
ios-sim launch "$APP_PATH" --family "$DEVICE_FAMILY" --stderr "$CORDOVA_PATH/console.log" --stdout "$CORDOVA_PATH/console.log" &
else
echo -e '\033[31mError: ios-sim was not found. Please download, build and install version 1.4 or greater from https://github.com/phonegap/ios-sim into your path. Or "brew install ios-sim" using homebrew: http://mxcl.github.com/homebrew/\033[m'; exit 1;
fi
You can then run the script like this (assumes your present working directory is the cordova directory containing the scripts):
./emulate ../build/myApp.app ipad
If you're always going to test on the iPad and you prefer not to have to specify the path to your app every time, you could just hardcode your preferred device family into the script like so and launch the emulator as you have been doing previously:
ios-sim launch "$APP_PATH" --family ipad --stderr "$CORDOVA_PATH/console.log" --stdout "$CORDOVA_PATH/console.log" &
For me all the mentioned options here did not work, I had to call it with this command to show the iPad Retina:
``ios-sim launch [DIR_OF_APP]platforms/ios/build/emulator/My-App.app --devicetypeid "com.apple.CoreSimulator.SimDeviceType.iPad-Retina, 8.2"
To retrieve all the devicetypeid's type ios-sim showdevicetypes

Resources