I want to use "hplip" for printing from android device. Please tell me how can I build "hplip" and use in android.
Is there are any wrapper available for android?
See hplip documentation here
You can static build "hpijs" that is part of "hplib" and Ghostscript, it can run on Android.
print command like this:
gs -sDEVICE=ijs -sIjsServer=hpijs -dIjsUseOutputFD -sDeviceManufacturer="HEWLETT-PACKARD" -sDeviceModel="deskjet 5550" -r300x300 -dNOPAUSE -dSAFER -sOutputFile="/dev/usb/lp0" ruler.pdf -c quit
PS: long long ago "hpijs" is single, so you can get old version. here is a shell to build hpijs.(The comments of shell is Mother tongue, you can use Google Translate :) )
#!/bin/sh
# 说明:本脚本是交叉(ARM)编译hpijs-2.1.4
DESTDIR=${PWD}/_install
# 1.下载源码 项目地址:http://sourceforge.net/projects/hpinkjet/files/
wget http://superb-dca2.dl.sourceforge.net/project/hpinkjet/hpijs/2.1.4/hpijs-2.1.4.tar.gz &&
# 2.解压源码
tar xvzf hpijs-2.1.4.tar.gz && cd hpijs-2.1.4 &&
# 3.配置 说明:CXXFLAGS默认是"-g -O2",这里添加-static以静态编译hpijs
./configure --host=arm-linux --target=arm-linux --build=i686-linux CC=arm-linux-gcc CXX=arm-linux-g++ LD=arm-linux-ld RANLIB=arm-linux-ranlib AR=arm-linux-ar CXXFLAGS="-static -g -O2" --prefix=/ LDFLAGS=-L../jpeg-8b/.libs &&
# 4.修正语法错误 dj3320.cpp第403行和registry.cpp第249行 开头的char改为const char
sed -i '249s/\tchar\t/\tconst char\t/' registry.cpp &&
sed -i '403s/ char/ const char/' dj3320.cpp &&
# 5.编译并安装
make && make install DESTDIR=$DESTDIR
# 6.hpijs支持的打印机型号:hpijs-2.1.4/ppd查看.
# MDL MFG名字都在ppd文件中.
Related
I'm struggling to compile the Linux kernel for usage in AOSP with KASAN & KCOV enabled. I then intend to flash it to a Pixel 2 XL (taimen) and use Syzkaller to fuzz it.
This is what I did:
1. Build unmodified kernel (works)
My reference: https://source.android.com/setup/build/building-kernels
Determine branch... android-msm-wahoo-4.4-pie-qpr2
$ repo init -u https://android.googlesource.com/kernel/manifest -b android-msm-wahoo-4.4-pie-qpr2
$ repo sync -j8 -c
$ build/build.sh -j8
Connect phone via USB
$ adb reboot bootloader
$ fastboot boot out/android-msm-wahoo-4.4/dist/Image.lz4-dtb
(Works fine)
2. Build kernel with KASAN & KCOV (fails)
To change kernel config symbols, edit POST_DEFCONFIG_CMDS in build/build.config
Copy from https://source.android.com/setup/build/building-kernels#customize-config
Modify as needed, use -d to disable, -e to enable a config option
Result:
POST_DEFCONFIG_CMDS="check_defconfig && update_debug_config"
function update_debug_config() {
${KERNEL_DIR}/scripts/config --file ${OUT_DIR}/.config \
-d CONFIG_KERNEL_LZ4 \
-e CONFIG_KASAN \
-e CONFIG_KASAN_INLINE \
-e CONFIG_KCOV \
-e CONFIG_SLUB \
-e CONFIG_SLUB_DEBUG \
--set-val FRAME_WARN 0
(cd ${OUT_DIR} && \
make O=${OUT_DIR} $archsubarch CC=${CC} CROSS_COMPILE=${CROSS_COMPILE} olddefconfig)
}
$ build/build.sh -j8
But after
CHK include/generated/compile.h
I get many undefined reference errors to various asan-symbols, e.g.
undefined reference to __asan_alloca_poison.
I did some research and read about adding -fsantitize=address and -shared-libasan (or -shared-libsan) to CFLAGS AND LDFLAGS. I did that (for which I had to hard-code it into build/build.sh, isn't there a more convenient way?), but to no avail:
I ended up with
aarch64-linux-android-ld: -f may not be used without -shared.
So I tried reading up on ld's -shared flag and adding it to LDFLAGS (more like a guess really). Resulted in
aarch64-linux-android-ld: -r and -shared may not be used together.
Really don't know where to go from here and what's going wrong in general?
Any help really appreciated!
Update: At first it seemed that using gcc instead of clang seemed to resolve the issue. The phone boots up fine, buttons work, but the touchscreen does not respond. I am looking into the reasons...
Regarding the touchscreen you need to manually copy required drivers to the AOSP folder. You can obtain fresh drivers from the kernel source code.
cd ${CONTAINER_GIT_REPO} && \
cp arch/arm64/boot/Image.lz4-dtb \$AOSP/device/google/wahoo-kernel/Image.lz4-dtb && \
cp arch/arm64/boot/dtbo.img $AOSP/device/google/wahoo-kernel/dtbo.img && \
cp drivers/input/touchscreen/stm/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/power/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/synaptics_dsx_htc/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/lge/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/lge/lgsic/*.ko $AOSP/device/google/wahoo-kernel && \
# Building final image for Pixel 2
cd \$AOSP && . build/envsetup.sh && lunch aosp_walleye-userdebug && make bootimage -j4
&& mkdir -p ${CONTAINER_GIT_REPO}/builded_images && \
cp out/target/product/walleye/*.img ${CONTAINER_GIT_REPO}/builded_images"
To obtain kernel source code:
git clone -b android-msm-wahoo-4.4-oreo-m2 --single-branch https://android.googlesource.com/kernel/msm
I have only Pixel 2 to check, but this should be applicable for both of them.
Update: You can check this repo for additional details https://gitlab.com/textor/build-pixel-2-in-docker
Maybe you can try to use the config file: ./private/msm-google/build.config.kasan
I used to use this config file and succeeded.
But the touchscreen didn't work, too.
I'm trying to create a Cordova project. I have a problem when I try this command from shell: "sudo cordova build". Return error message is:
francesco#francesco:~/hello$ sudo cordova build
Running command: /home/francesco/hello/platforms/android/cordova/build
[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /home/francesco/hello/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /home/francesco/hello/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:131:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
My .bashrc file is this:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u#\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user#host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u#\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export HOME="/home/francesco"
export ANDROID_HOME="$HOME/android-sdk-linux"
export PATH="$HOME/android-sdk-linux/tools:$ANDROID_HOME/platforms:$PATH"
How can I set ANDROID_HOME and "android" command?
My android-sdk is located in "home/francesco/android-sdk-linux"
I'm using Ubuntu 14.04
It's not related with your .bashrc file.
Solution? Create .bash_profile inside you home directory.
export PATH=${PATH}:/home/francesco/android-sdk-linux/platform-tools
export PATH=${PATH}:/home/francesco/android-sdk-linux/tools
you must to set the root path of android sdk into an environment variable.
In your case:
export ANDROID_HOME=/home/francesco/android-sdk-linux
Use NANO editor to save your path in .bash or .profile or .bash_profile depending on your OS.
I have a mac and face similar issue.
Check below URL on how to use NANO to edit and save file
http://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/
http://www.nano-editor.org/dist/v2.2/nano.html
http://www.nano-editor.org/dist/v2.2/nano.html
Put your path in desired file and it will work and you will not required to export path every time you open terminal.
How can I reduce the length of the path printed before the prompt of the shell opened by adb shell? My problem is that it is so long that I can no longer see my commands because the doesn't break the line automatically. I would prefer something like the name of the current directory or an abstract code example.
sh -v on Android phone gives me
# Copyright (c) 2010
# Thorsten Glaser <t.glaser#tarent.de>
# This file is provided under the same terms as mksh.
#-
# Minimal /system/etc/mkshrc for Android
: ${TERM:=vt100} ${HOME:=/data} ${MKSH:=/system/bin/sh} ${HOSTNAME:=android}
: ${SHELL:=$MKSH} ${USER:=$(typeset x=$(id); x=${x#*\(}; print -r -- ${x%%\)*})}
if (( USER_ID )); then PS1='$'; else PS1='#'; fi
function precmd {
typeset e=$?
(( e )) && print -n "$e|"
}
PS1='$(precmd)$USER#$HOSTNAME:${PWD:-?} '"$PS1 "
export HOME HOSTNAME MKSH PS1 SHELL TERM USER
alias l='ls'
alias la='l -a'
alias ll='l -l'
alias lo='l -a -l'
for p in ~/.bin; do
[[ -d $p/. ]] || continue
[[ :$PATH: = *:$p:* ]] || PATH=$p:$PATH
done
unset p
: place customisations above this line
You could change your PS1 prompt to be something smaller with the line:
PS1="> "
but it'd probably be better to instead increase the width of your window with something like:
COLUMNS=150
Hello I'm trying to build valgrind for android-arm. On Linux Mint 13 it fails with:
$ make
echo "# This is a generated file, composed of the following suppression rules:" > default.supp
echo "# " exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
cat exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
make all-recursive
make[1]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1'
Making all in include
make[2]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/include'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/include'
Making all in VEX
make[2]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make all-am
make[3]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../include -I../VEX/pub -DVGA_arm=1 -DVGO_linux=1 -DVGP_arm_linux=1 -DVGPV_arm_linux_vanilla=1 -Ipriv -m32 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wno-format-zero-length -fno-strict-aliasing -fno-builtin -marm -mcpu=cortex-a8 -Wbad-function-cast -Wcast-qual -Wcast-align -fstrict-aliasing -Wno-long-long -Wno-pointer-sign -fno-stack-protector -MT libvex_arm_linux_a-main_globals.o -MD -MP -MF .deps/libvex_arm_linux_a-main_globals.Tpo -c -o libvex_arm_linux_a-main_globals.o `test -f 'priv/main_globals.c' || echo './'`priv/main_globals.c
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead
cc1: error: unrecognised command line option ‘-marm’
priv/main_globals.c:1:0: error: bad value (cortex-a8) for -mtune= switch
make[3]: *** [libvex_arm_linux_a-main_globals.o] Error 1
make[3]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1'
make: *** [all] Error 2
I am using ndk-r8e and valgrind 3.8.1. The configure ends with:
Maximum build arch: arm
Primary build arch: arm
Secondary build arch:
Build OS: linux
Primary build target: ARM_LINUX
Secondary build target:
Platform variant: vanilla
Primary -DVGPV string: -DVGPV_arm_linux_vanilla=1
Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp
What can I do to fix this? Alternatively, are there any pre-built android-arm valgrind binaries that I can use?
For building and installing Valgrind for Android use the bash script below, which I prefer to call build_valgrind.sh
To run with RUN_HELLO_JNI_THROUGH_VALGRIND=true you need two additional scripts (bootstrap_valgrind.sh, start_valgrind.sh) in the directory you run the script below from.
Running the script with the RUN_HELLO_JNI_THROUGH_VALGRIND=true flag will build the hello-jni application from the samples directory inside the Android NDK HOME, deploy it to the phone and run it through Valgrind, using either callgrind or memcheck tool, which you can specify in the start_valgrind.sh script.
The other two scripts are described here: https://stackoverflow.com/a/19235439/313113
Here's my directory structure:
|-- build_valgrind.sh (the script below)
|-- bootstrap_valgrind.sh (second script from https://stackoverflow.com/a/19235439/313113)
|-- start_valgrind.sh (first script from https://stackoverflow.com/a/19235439/313113)
|-- valgrind-3.10.0 (will be extracted by build_valgrind.sh)
`-- valgrind-3.10.0.tar.bz2 (will be downloaded by build_valgrind.sh)
I've tested that its working (memcheck and callgrind tools) on a Samsung Galaxy Nexus device with CyanogenMod 10.2.1 and Android 4.3.1 and CyanogenMod 11 20140804 snapshot, Android 4.4.4
You can see the file size of the generated output with: adb shell ls -lR "/sdcard/*grind*"
The build_valgrind.sh script:
#!/usr/bin/env bash
#set -x
function extract()
{
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "$1 cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
RUN_HELLO_JNI_THROUGH_VALGRIND=true
VALGRIND_VERSION="3.10.0"
VALGRIND_EXTENSION=".tar.bz2"
VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}"
VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}"
# Only download Valgrind tarball again if not already downloaded
if [[ ! -f "${VALGRIND_TARBALL}" ]]; then
wget -v -nc "http://valgrind.org/downloads/${VALGRIND_TARBALL}"
fi
# Only extract Valgrind tarball again if not already extracted
if [[ ! -d "$VALGRIND_DIRECTORY" ]]; then
extract "$VALGRIND_TARBALL"
fi
# Ensure ANDROID_NDK_HOME is set
if [[ ! -z "$ANDROID_NDK_HOME" ]]; then
export ANDROID_NDK_HOME="$HOME/Software/Android/android-ndk-r10c"
fi
# Ensure ANDOID_SDK_HOME is set
if [[ ! -z "$ANDROID_SDK_HOME" ]]; then
export ANDROID_SDK_HOME="$HOME/Software/Android/android-sdk/"
fi
if [[ ! -d "$VALGRIND_DIRECTORY" ]];
then
echo "Problem with extracting Valgrind from $VALGRIND_TARBALL into $VALGRIND_DIRECTORY!!!"
exit -1
fi
# Move to extracted directory
cd "$VALGRIND_DIRECTORY"
# ARM Toolchain
ARCH_ABI="arm-linux-androideabi-4.9"
export AR="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
export LD="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld"
export CC="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
export CXX="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++"
[[ ! -d "$ANDROID_NDK_HOME" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure ANDROID_NDK_HOME is defined also" && exit -1
# Configure build
export HWKIND="nexus_s"
ANDROID_PLATFORM=android-18
export CPPFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm"
# BUG: For some reason file command is unable to detect if the file does not exist with ! -f , it says it doesn't exist even when it does!!!
BUILD=false
if [[ "${VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/valgrind" = *"No such file or directory"* ]]; then
BUILD=true
fi
if [[ "$BUILD" = true ]];
then
./configure --prefix="/data/local/Inst" \
--host="armv7-unknown-linux" \
--target="armv7-unknown-linux" \
--with-tmpdir="/sdcard "
[[ $? -ne 0 ]] && echo "Can't configure!" && exit -1
# Determine the number of jobs (commands) to be run simultaneously by GNU Make
NO_CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
if [ $NO_CPU_CORES -le 8 ]; then
JOBS=$(($NO_CPU_CORES+1))
else
JOBS=${NO_CPU_CORES}
fi
# Compile Valgrind
make -j "${JOBS}"
[[ $? -ne 0 ]] && echo "Can't compile!" && exit -1
# Install Valgrind locally
make -j "${JOBS}" install DESTDIR="$(pwd)/Inst"
[[ $? -ne 0 ]] && echo "Can't install!" && exit -1
fi
# Push local Valgrind installtion to the phone
if [[ $(adb shell ls -ld /data/local/Inst/bin/valgrind) = *"No such file or directory"* ]];
then
adb root
adb remount
adb shell "[ ! -d /data/local/Inst ] && mkdir /data/local/Inst"
adb push Inst /
adb shell "ls -l /data/local/Inst"
# Ensure Valgrind on the phone is running
adb shell "/data/local/Inst/bin/valgrind --version"
# Add Valgrind executable to PATH (this might fail)
adb shell "export PATH=$PATH:/data/local/Inst/bin/"
fi
if [ $RUN_HELLO_JNI_THROUGH_VALGRIND = true ]; then
PACKAGE="com.example.hellojni"
# The location of the Hello JNI sample application
HELLO_JNI_PATH="$ANDROID_NDK_HOME/samples/hello-jni"
pushd "$HELLO_JNI_PATH"
# Update build target to the desired Android SDK version
ANDROID_PROJECT_TARGET="android-18"
android update project --target "$ANDROID_PROJECT_TARGET" --path . --name hello-jni --subprojects
# Enable Android NDK build with Ant
echo '<?xml version="1.0" encoding="utf-8"?>
<project name="HelloJni" basedir="." default="debug">
<target name="-pre-build">
<exec executable="${ndk.dir}/ndk-build" failonerror="true"/>
</target>
<target name="clean" depends="android_rules.clean">
<exec executable="${ndk.dir}/ndk-build" failonerror="true">
<arg value="clean"/>
</exec>
</target>
</project>
' > "custom_rules.xml"
# Set NDK HOME for Ant (only if not already set)
if ! grep -P -q "ndk.dir=.+" "local.properties" ; then
echo -e "\nndk.dir=$ANDROID_NDK_HOME" >> "local.properties"
fi
# Fix for Java 8 warning (warning: [options] source value 1.5 is obsolete and will be removed in a future release)
echo "java.compilerargs=-Xlint:-options" >> "ant.properties"
# Workaround INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES error
adb uninstall "$PACKAGE"
# Build Hello JNI project in debug mode and install it on the device
ant clean && ant debug && ant installd
popd
cd ..
# Start HelloJNI app
adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni
# Make the script executable
chmod a+x bootstrap_valgrind.sh
# Run application through Valgrind on the phone
/usr/bin/env bash bootstrap_valgrind.sh
adb shell ls -lR "/sdcard/*grind*"
adb shell ls -lR "/storage/sdcard0/*grind*"
adb shell ls -lR "/storage/sdcard1/*grind*"
fi
exit 0
This gets valgrind to compile for me on linux. (using android-ndk-r8e and valgrind-3.8.1)
There was no need to run autogen.sh since I downloaded the tar ball from the website.
Also make sure the TOOLCHAIN= line points to a valid toolchain.
export NDK_HOME=$HOME/Downloads/android-ndk-r8e
export HWKIND=generic
export TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi
export AR=$TOOLCHAIN-ar
export LD=$TOOLCHAIN-ld
export CC=$TOOLCHAIN-gcc
CPPFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm -DANDROID_HARDWARE_$HWKIND" \
CFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm" \
./configure --prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
make
It eventually came up with a compile error saying
$NDK_HOME/platforms/android-14/arch-arm/usr/include/elf.h:58:3: error: unknown type name 'uint32_t'
It seem like someone forgot to add #include <stdint.h> somewhere. To fix this I edited $NDK_HOME/platforms/android-14/arch-arm/usr/include/elf.h and added #include <stdint.h> to the include section of this header. NOTE: This is probably not the best fix but it is the one that I came up with that fixed the compilation errors.
On mac I was able to get it to compile up until the unknown type uint32_t part by changing how the configure script checks the kernel version.
Inside the configure script search of a line kernel=`uname -r` and change it to kernel=3.9.2. (There are two kernel=`uname -r` lines replace the first one or both if you feel like it)
This stops the configure script from looking at the host kernel when deciding how it should build valgrind. (uname -r grabs the host kernel)
I believe adding the #include <stdint.h> to elf.h should work on mac to but I have not tested it.
in android tutorial one option is missed
RANLIB, after I set it - I finally compiled valgrind-3.11.0 on osx for android
#/bin/sh
echo "NKDROOT: " $NDKROOT
export ANRDOID_TOOLCHAIN="arm-linux-androideabi-4.9"
# Set up toolchain paths.
#
# For ARM
export AR=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ar
export LD=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ld
export CC=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
export CXX=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++
export RANLIB=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ranlib
echo "AR: " $AR
echo "LD: " $LD
echo "CC: " $CC
echo "CXX: " $CXX
[[ ! -d "$NDKROOT" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure NDKROOT is defined also" && exit -1
./autogen.sh
#if [ $? -ne 0 ]
#then
# exit 1
#else
# echo "autogen success!"
#fi
# for ARM
ANDROID_PLATFORM=android-3
ANDROID_SYSROOT="$NDKROOT/platforms/${ANDROID_PLATFORM}/arch-arm"
echo "SYSROOT: " $ANDROID_SYSROOT
export HWKIND=generic
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export LDFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export ARFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
./configure \
--prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
if [ $? -ne 0 ]
then
exit 1
else
echo "configure success!"
fi
# note: on android emulator, android-14 platform was also tested and works.
# It is not clear what this platform nr really is.
make -j7
if [ $? -ne 0 ]
then
exit 1
else
echo "build success!"
fi
make -j7 install DESTDIR=`pwd`/Inst
The problem I had was that the configure script was ignoring the environment variables. To configure the make file I instead did this:
sudo ./configure --prefix=/data/local/Inst --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/sdcard0 CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" CC=$CC LD=$LD AR=$AR
This ensures the variables are set properly and works with Linux Mint 13. It does not work on OSX Mountain Lion however. I'd advise anyone using OSX without access to a linux installation to try using linux on a virtual machine.
I am trying to compile Frotz to run in a terminal emulator so it will execute on my Android Ice Cream Sandwich smartphone. Frotz is an open source Z-Machine interpreter for playing interactive fiction and is basically just a command-line application. I have done the following:
Downloaded Android NDK (android-ndk-r8d) and extracted it on my Windows 7 laptop. (Extracted to c:\android\android-ndk-r8d)
Downloaded and installed Cygwin, including all development packages. (So make is installed)
Using Cygwin, navigate to the folder containing the extracted Frotz makefile and source folder and try to execute make.
When I try run make, I encounter issues relating to curses.h not being found (but this issue is not the focus of this question; maybe a point for a followup question). When I do make dumb (which compiles a simplified version of Frotz), the compile succeeds and I am able to run it within Cygwin. But if I copy the compiled command-line application to the phone and try execute it, I get the following error:
not executable: magic 4D5A
I suspect the problem here is that the executable is now not compiled for the Arm architecture. The make file has the following line in it:
CC = gcc
which I have tried changing to:
CC = /cygdrive/c/android/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe
But now when I execute make, I get the following error message:
fatal error: signal.h: No such file or directory
I am very new to C development (and Android) and struggling to figure out how to change the makefile so that it will compile correctly for Android. I will include the complete makefile below and will appreciate whatever help anyone can offer in getting this to correctly compile for Android.
The complete Frotz makefile:
# Define your C compiler. I recommend gcc if you have it.
# MacOS users should use "cc" even though it's really "gcc".
#
CC = gcc
#CC = cc
# Define your optimization flags. Most compilers understand -O and -O2,
# Standard (note: Solaris on UltraSparc using gcc 2.8.x might not like this.)
#
OPTS = -O2
# Pentium with gcc 2.7.0 or better
#OPTS = -O2 -fomit-frame-pointer -malign-functions=2 -malign-loops=2 \
#-malign-jumps=2
# Define where you want Frotz installed. Usually this is /usr/local
PREFIX = /usr/local
MAN_PREFIX = $(PREFIX)
#MAN_PREFIX = /usr/local/share
CONFIG_DIR = $(PREFIX)/etc
#CONFIG_DIR = /etc
# Define where you want Frotz to look for frotz.conf.
#
CONFIG_DIR = /usr/local/etc
#CONFIG_DIR = /etc
#CONFIG_DIR = /usr/pkg/etc
#CONFIG_DIR =
# Uncomment this if you want color support. Most, but not all curses
# libraries that work with Frotz will support color.
#
COLOR_DEFS = -DCOLOR_SUPPORT
# Uncomment this if you have an OSS soundcard driver and want classical
# Infocom sound support.
#
#SOUND_DEFS = -DOSS_SOUND
# Uncomment this too if you're running BSD of some sort and are using
# the OSS sound driver.
#
#SOUND_LIB = -lossaudio
# Define your sound device
# This should probably be a command-line/config-file option.
#
#SOUND_DEV = /dev/dsp
#SOUND_DEV = /dev/sound
#SOUND_DEV = /dev/audio
# If your vendor-supplied curses library won't work, uncomment the
# location where ncurses.h is.
#
#INCL = -I/usr/local/include
#INCL = -I/usr/pkg/include
#INCL = -I/usr/freeware/include
#INCL = -I/5usr/include
#INCL = -I/path/to/ncurses.h
# If your vendor-supplied curses library won't work, uncomment the
# location where the ncurses library is.
#
#LIB = -L/usr/local/lib
#LIB = -L/usr/pkg/lib
#LIB = -L/usr/freeware/lib
#LIB = -L/5usr/lib
#LIB = -L/path/to/libncurses.so
# One of these must always be uncommented. If your vendor-supplied
# curses library won't work, comment out the first option and uncomment
# the second.
#
CURSES = -lcurses
#CURSES = -lncurses
# Uncomment this if your need to use ncurses instead of the
# vendor-supplied curses library. This just tells the compile process
# which header to include, so don't worry if ncurses is all you have
# (like on Linux). You'll be fine.
#
#CURSES_DEF = -DUSE_NCURSES_H
# Uncomment this if you're compiling Unix Frotz on a machine that lacks
# the memmove(3) system call. If you don't know what this means, leave it
# alone.
#
#MEMMOVE_DEF = -DNO_MEMMOVE
# Uncomment this if for some wacky reason you want to compile Unix Frotz
# under Cygwin under Windoze. This sort of thing is not reccomended.
#
#EXTENSION = .exe
#####################################################
# Nothing under this line should need to be changed.
#####################################################
SRCDIR = src
VERSION = 2.43d
NAME = frotz
BINNAME = $(NAME)
DISTFILES = bugtest
DISTNAME = $(BINNAME)-$(VERSION)
distdir = $(DISTNAME)
COMMON_DIR = $(SRCDIR)/common
COMMON_TARGET = $(SRCDIR)/frotz_common.a
COMMON_OBJECT = $(COMMON_DIR)/buffer.o \
$(COMMON_DIR)/err.o \
$(COMMON_DIR)/fastmem.o \
$(COMMON_DIR)/files.o \
$(COMMON_DIR)/hotkey.o \
$(COMMON_DIR)/input.o \
$(COMMON_DIR)/main.o \
$(COMMON_DIR)/math.o \
$(COMMON_DIR)/object.o \
$(COMMON_DIR)/process.o \
$(COMMON_DIR)/quetzal.o \
$(COMMON_DIR)/random.o \
$(COMMON_DIR)/redirect.o \
$(COMMON_DIR)/screen.o \
$(COMMON_DIR)/sound.o \
$(COMMON_DIR)/stream.o \
$(COMMON_DIR)/table.o \
$(COMMON_DIR)/text.o \
$(COMMON_DIR)/variable.o
CURSES_DIR = $(SRCDIR)/curses
CURSES_TARGET = $(SRCDIR)/frotz_curses.a
CURSES_OBJECT = $(CURSES_DIR)/ux_init.o \
$(CURSES_DIR)/ux_input.o \
$(CURSES_DIR)/ux_pic.o \
$(CURSES_DIR)/ux_screen.o \
$(CURSES_DIR)/ux_text.o \
$(CURSES_DIR)/ux_audio_none.o \
$(CURSES_DIR)/ux_audio_oss.o
DUMB_DIR = $(SRCDIR)/dumb
DUMB_TARGET = $(SRCDIR)/frotz_dumb.a
DUMB_OBJECT = $(DUMB_DIR)/dumb_init.o \
$(DUMB_DIR)/dumb_input.o \
$(DUMB_DIR)/dumb_output.o \
$(DUMB_DIR)/dumb_pic.o
TARGETS = $(COMMON_TARGET) $(CURSES_TARGET)
OPT_DEFS = -DCONFIG_DIR="\"$(CONFIG_DIR)\"" $(CURSES_DEF) \
-DVERSION="\"$(VERSION)\"" -DSOUND_DEV="\"$(SOUND_DEV)\""
COMP_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \
$(MEMMOVE_DEF)
FLAGS = $(OPTS) $(COMP_DEFS) $(INCL)
$(NAME): $(NAME)-curses
$(NAME)-curses: soundcard.h $(COMMON_TARGET) $(CURSES_TARGET)
$(CC) -o $(BINNAME)$(EXTENSION) $(TARGETS) $(LIB) $(CURSES) \
$(SOUND_LIB)
all: $(NAME) d$(NAME)
dumb: $(NAME)-dumb
d$(NAME): $(NAME)-dumb
$(NAME)-dumb: $(COMMON_TARGET) $(DUMB_TARGET)
$(CC) -o d$(BINNAME)$(EXTENSION) $(COMMON_TARGET) \
$(DUMB_TARGET) $(LIB)
.SUFFIXES:
.SUFFIXES: .c .o .h
.c.o:
$(CC) $(FLAGS) $(CFLAGS) -o $# -c $<
# If you're going to make this target manually, you'd better know which
# config target to make first.
#
common_lib: $(COMMON_TARGET)
$(COMMON_TARGET): $(COMMON_OBJECT)
#echo
#echo "Archiving common code..."
ar rc $(COMMON_TARGET) $(COMMON_OBJECT)
ranlib $(COMMON_TARGET)
#echo
curses_lib: config_curses $(CURSES_TARGET)
$(CURSES_TARGET): $(CURSES_OBJECT)
#echo
#echo "Archiving curses interface code..."
ar rc $(CURSES_TARGET) $(CURSES_OBJECT)
ranlib $(CURSES_TARGET)
#echo
dumb_lib: $(DUMB_TARGET)
$(DUMB_TARGET): $(DUMB_OBJECT)
#echo
#echo "Archiving dumb interface code..."
ar rc $(DUMB_TARGET) $(DUMB_OBJECT)
ranlib $(DUMB_TARGET)
#echo
soundcard.h:
#if [ ! -f $(SRCDIR)/soundcard.h ] ; then \
sh $(SRCDIR)/misc/findsound.sh $(SRCDIR); \
fi
install: $(NAME)
strip $(BINNAME)$(EXTENSION)
install -d $(PREFIX)/bin
install -d $(MAN_PREFIX)/man/man6
install -c -m 755 $(BINNAME)$(EXTENSION) $(PREFIX)/bin
install -c -m 644 doc/$(NAME).6 $(MAN_PREFIX)/man/man6
uninstall:
rm -f $(PREFIX)/bin/$(NAME)
rm -f $(MAN_PREFIX)/man/man6/$(NAME).6
deinstall: uninstall
install_dumb: d$(NAME)
strip d$(BINNAME)$(EXTENSION)
install -d $(PREFIX)/bin
install -d $(MAN_PREFIX)/man/man6
install -c -m 755 d$(BINNAME)$(EXTENSION) $(PREFIX)/bin
install -c -m 644 doc/d$(NAME).6 $(MAN_PREFIX)/man/man6
uninstall_dumb:
rm -f $(PREFIX)/bin/d$(NAME)
rm -f $(MAN_PREFIX)/man/man6/d$(NAME).6
deinstall_dumb: uninstall_dumb
distro: dist
dist: distclean
mkdir $(distdir)
#for file in `ls`; do \
if test $$file != $(distdir); then \
cp -Rp $$file $(distdir)/$$file; \
fi; \
done
find $(distdir) -type l -exec rm -f {} \;
tar chof $(distdir).tar $(distdir)
gzip -f --best $(distdir).tar
rm -rf $(distdir)
#echo
#echo "$(distdir).tar.gz created"
#echo
clean:
rm -f $(SRCDIR)/*.h $(SRCDIR)/*.a
rm -f $(COMMON_DIR)/*.o $(CURSES_DIR)/*.o $(DUMB_DIR)/*.o
distclean: clean
rm -f $(BINNAME)$(EXTENSION) d$(BINNAME)$(EXTENSION)
rm -f $(BINNAME).exe $(BINNAME).bak $(BINNAME).lib
rm -f *core $(SRCDIR)/*core
-rm -rf $(distdir)
-rm -f $(distdir).tar $(distdir).tar.gz
realclean: distclean
clobber: distclean
help:
#echo
#echo "Targets:"
#echo " frotz"
#echo " dfrotz"
#echo " install"
#echo " uninstall"
#echo " clean"
#echo " distclean"
#echo
With android-ndk-r8d, you don't need cygwin: make can be found in c:\android\android-ndk-r8d\prebuilt\windows32\bin.
Anyways, to use a makefile, you should follow the instructions in c:\android\android-ndk-r8d\STANDALONE-TOOLCHAIN.html