From: Antonio Ospite Date: Sun, 24 Feb 2013 12:52:34 +0000 (+0100) Subject: Initial import X-Git-Url: https://git.ao2.it/android/android-app-development-getting-started.git/commitdiff_plain/b9c60624b1049409f0a000b6375fe3f65803ff74?ds=inline Initial import --- b9c60624b1049409f0a000b6375fe3f65803ff74 diff --git a/android-app-development-getting-started.sh b/android-app-development-getting-started.sh new file mode 100755 index 0000000..971aa72 --- /dev/null +++ b/android-app-development-getting-started.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env less +# +# Tutorial about getting started with android App development from the command +# line shell. +# +# Similar to +# http://vishalraj.in/blogs/hello-world-writing-my-first-android-app-on-linux +# + +# The base working dir is assumed to be $HOME/Android +mkdir $HOME/Android +cd $HOME/Android + +# Download and unpack the SDK from +# http://developer.android.com/sdk/index.html +wget http://dl.google.com/android/android-sdk_r21.1-linux.tgz +tar xzvf android-sdk_r21.1-linux.tgz + +# Add "platform-tools" and "tools" to the PATH +export ANDROID_HOME=$HOME/Android/android-sdk-linux +export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools + +# List packages +android list sdk --extended + +# Install packages. Use this same command line to update the packages +android update sdk --no-ui --filter platform-tools,android-17,sys-img-17,extra-android-support + +# Check what targets are available +android list targets + +# Create an Android Virtual Device (AVD) +android create avd --target android-17 --name android-17-x86 --abi x86 + +# Install "ant" to build packages +sudo aptitude install ant + +# Create a Hello World application +# http://developer.android.com/tools/projects/projects-cmdline.html +mkdir $HOME/Android/Apps +android create project \ + --target android-17 \ + --name MyFirstApp \ + --path $HOME/Android/Apps/MyFirstApp \ + --activity MainActivity \ + --package com.example.myfirstapp + +# And maybe you want to use git for your App? +cd $HOME/Android/Apps/MyFirstApp +ant clean +git init +git add . +git rm local.properties +git commit -m $'Initial import\n\nhttp://developer.android.com/training/basics/firstapp/creating-project.html' +echo "bin/" > .gitignore +echo "gen/" > .gitignore +echo "local.properties" > .gitignore +git add .gitignore +git commit -m "Add a .gitignore file" + +# Learn how to write Android Apps: +http://developer.android.com/training/basics/firstapp/building-ui.html + +# Build the App +# http://developer.android.com/tools/building/building-cmdline.html +cd $HOME/Android/Apps/MyFirstApp +ant debug + +# Start the emulator, hardware accelerated: +# http://developer.android.com/tools/devices/emulator.html#vm-linux +emulator -verbose -avd android-17-x86 -scale 0.9 -gpu on -qemu -m 512 -enable-kvm + +# Install the App into an Android [Virtual] Device +adb devices -l +adb -s emulator-5554 install bin/MyFirstApp-debug.apk + +# Launch your application from the HOST +adb -s emulator-5554 -e shell am start -a android.intent.action.MAIN -n com.example.myfirstapp/com.example.myfirstapp.MainActivity + +# See logs, e.g. only errors +adb -s emulator-5554 logcat *:E + +# Connect to the emulator via telnet if needed +telnet localhost 5554 + diff --git a/compile_and_run_app.sh b/compile_and_run_app.sh new file mode 100755 index 0000000..306d535 --- /dev/null +++ b/compile_and_run_app.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +if command -v xmllint >/dev/null 2>&1; +then + # Try xmllint from the "xmllint" package + XPATH="xmllint --xpath " +elif command -v xpath >/dev/null 2>&1; +then + # xpath is from the perl XML::XPath module: libxml-xpath-perl package + XPATH="xpath -e" +else + { echo "Install either xmllint or the XML::XPath perl module" 1>&2; exit 1; } +fi + +APP_NAME=$($XPATH "string(//project/@name)" build.xml) +PACKAGE=$($XPATH "string(//manifest/@package)" AndroidManifest.xml) +MAIN_ACTIVITY=$($XPATH "string(//activity[1]/@*[local-name() = 'name'])" AndroidManifest.xml) + +ant debug +adb -s emulator-5554 install -r bin/${APP_NAME}-debug.apk +adb -s emulator-5554 -e shell am start -a android.intent.action.MAIN -n ${PACKAGE}/${PACKAGE}.${MAIN_ACTIVITY} diff --git a/ic_launcher_template/README.txt b/ic_launcher_template/README.txt new file mode 100644 index 0000000..83e7f9a --- /dev/null +++ b/ic_launcher_template/README.txt @@ -0,0 +1,10 @@ +The template provided here is 48x48 px with a border of 1/12 of the size. +http://tekeye.biz/2012/android-launcher-icons-using-inkscape + +The exporter script will generate icons at 36x36, 48x48, 72x72, 96x96 pixels + +The androink.py export script is an evolution of: +https://gist.github.com/fedepaol/4127778 + +And alternative is to use the android4inkscape extension: +https://github.com/kengoodridge/android4inkscape diff --git a/ic_launcher_template/androink.py b/ic_launcher_template/androink.py new file mode 100755 index 0000000..c8a83bd --- /dev/null +++ b/ic_launcher_template/androink.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python +# +# androink - Generate android resources for multiple resolutions +# +# Copyright (C) 2012 Federico Paolinelli +# Copyright (C) 2013 Antonio Ospite +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Based on: +# https://gist.github.com/fedepaol/4127778 +# +# Following the directions of: +# https://developer.android.com/guide/practices/screens_support.html + +import argparse +import sys +import os + +__description = """This script expects the svg to use Inkscape DPIs. + +This means that the resolution given in the drawing will be used for +MDPI resolution and scaled to generate the other resolutions. + +""" +__version = "0.1" +__author_info = "Federico Paolinelli, Antonio Ospite" + + +BASE_OPTIONS = ' --export-area-page --export-png ' + +# Inkscape default DPI is 90, we use this for the MDPI resource +BASELINE_DPI = 90 + +LDPI = ('drawable-ldpi', BASELINE_DPI * 0.75) +MDPI = ('drawable-mdpi', BASELINE_DPI * 1.0) +HDPI = ('drawable-hdpi', BASELINE_DPI * 1.5) +XHDPI = ('drawable-xhdpi', BASELINE_DPI * 2.0) + +resolutions = [LDPI, MDPI, HDPI, XHDPI] + + +def export_file(file_name): + print 'exporting file', file_name + name_without_ext = os.path.splitext(file_name)[0] + + for rel in resolutions: + dpispec, dpi = rel + res_path = os.path.join(args.res_folder, dpispec) + + if not os.path.exists(res_path): + os.makedirs(res_path) + + source_file = os.path.join(args.svg_folder, file_name) + target = os.path.join(res_path, name_without_ext + '.png') + + command_list = [args.ink_path, '--export-area-page', + '-f', source_file, + '--export-png', target, + '--export-dpi', str(dpi)] + + command = " ".join(command_list) + + print 'executing', command + if not args.dry: + os.popen(command) + + +def option_parser(): + usage = "usage: %(prog)s [options]" + + parser = argparse.ArgumentParser(usage=usage, + description=__description, + epilog=__author_info, + version='%(prog)s ' + __version,) + + parser.add_argument('-R', '--res_folder', metavar="", + dest='res_folder', required=True, + help='path to the project res folder') + + parser.add_argument('-S', '--svg_folder', metavar="", + dest='svg_folder', default='.', + help='folder that contains all the svg files to be converted') + + parser.add_argument('-I', '--inkscape_path', metavar="", + dest='ink_path', default='inkscape', + help='path of Inkscape executable') + + parser.add_argument('-D', '--dry_run', + dest='dry', action='store_const', const=True, + help='performs a dry run') + + parser.add_argument('-F', '--single_file', metavar="", + dest='file_name', + help='name of the file, if you want to convert only one file') + + return parser + + +if __name__ == "__main__": + parser = option_parser() + args = parser.parse_args() + + if args.file_name: + export_file(args.file_name) + else: + files = os.listdir(args.svg_folder) + svg_files = filter(lambda x: x.lower().endswith('.svg'), files) + + map(export_file, svg_files) diff --git a/ic_launcher_template/ic_launcher.svg b/ic_launcher_template/ic_launcher.svg new file mode 100644 index 0000000..a25c3ed --- /dev/null +++ b/ic_launcher_template/ic_launcher.svg @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/setenv b/setenv new file mode 100644 index 0000000..5b85830 --- /dev/null +++ b/setenv @@ -0,0 +1,4 @@ +#!/bin/sh +# This file is meant to be sourced, not executed. +export ANDROID_HOME=$HOME/Android/android-sdk-linux +export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools