tools:

emualtori:

SDK:

risorse:

Resolution problems:

ADB

creare un progetto di base da CLI

    android create project \
    --package com.devsmt --activity main \ 
    --target 1 --name android_0 \ 
    --path ./android_0

creare una librerira:

    android create lib-project --name <your_project_name> \
    --target <target_ID> \
    --path path/to/your/project \
    --package <your_library_package_namespace>
 
    # associare la lib al progetto
    android update project \
    --target <target_ID> \
    --path path/to/your/project
    --library path/to/library_projectA

building:

    chmod +x gradlew
    ./gradlew assembleDebug

OS version and info

    adb shell getprop
    adb shell getprop ro.product.model
    #
    adb shell getprop ro.build.version.release
    adb shell getprop ro.build.version.sdk
 
    android update adb

log della macchina virtuale/device

    adb logcat
    #filtering
    adb logcat CordovaLog:D *:S

filter by app pid

    #!/bin/sh
    # applog.sh com.example.my.package
    PACKAGE=$1
    APPPID=`adb -d shell ps | grep "${PACKAGE}" | awk '{print $2}'`
    # cut -c10-15 | sed -e 's/ //g'
    adb -d logcat -v long \
     | tr -d '\r' | sed -e '/^\[.*\]/ {N; s/\n/ /}' | grep -v '^$' \
     | grep " ${APPPID}:"

better filtered logcat

    pidcat it.ev.appname

installare una app:

    adb install -r /path/to/yourpgm.apk
    adb -s emulator-5554 install yourpgm.apk

take screenshot:

#!/usr/bin/env php
    <?php
    $date 
date('dHis');
    `
adb shell screencap -p /sdcard/screen_$date.png`;
    `
adb pull /sdcard/screen_$date.png`;
    `
adb shell rm /sdcard/screen_$date.png`;

video record:

    #!/usr/bin/env php
    <?php
    $date = date('dHis');
    `adb shell screenrecord  /sdcard/screenrecord_$date.mp4 --bit-rate 8000000`;
    `adb pull /sdcard/screenrecord_$date.mp4`;
    `adb shell rm /sdcard/screenrecord_$date.mp4`;

transfer files:

    adb push my_app/www/img/x/*.jpg /mnt/sdcard/my_app
    adb pull /mnt/sdcard/my_app/file.log

device connection

connessione USB http://developer.android.com/tools/device.html

lista device:

    sudo lsusb
    $ Bus 001 Device 003: ID 04e8:681c Samsung Electronics Co., Ltd
    $ Bus 003 Device 016: ID 18d1:4ee7 Google Inc.
    04e8:6866

in questo esempio vendor ID è 04e8 e 18d1

    sudo nano /etc/udev/rules.d/51-android.rules
 
    # samsung ID
    SUBSYSTEM=="usb|usb_device", SYSFS{idVendor}=="04e8", SYMLINK+="android_adb", MODE="0666"
    # Google ID
    SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"
 
    sudo chmod a+r /etc/udev/rules.d/51-android.rules
 
    # restart udev
    sudo service udev restart
    killall adb
    adb devices
    * daemon not running. starting it now on port 5037 *
    * daemon started successfully *
    List of devices attached
    R22X222XXX    device

controllare anche i permessi assegnati all'eseguibile adb

    sudo chown root:user_group /usr/local/bin/adb

activate USB Debugging Mode

  1. From a Home screen, navigate Apps icon Apps icon > Settings.
  2. From the System section, tap Developer options.
  3. Note If Developer Options is unavailable, navigate: Apps > Settings > About device then tap Build number 7 times.
  4. Ensure the Developer options switch (located in the upper-right) is turned on On indicator.
  5. Tap USB debugging to turn On indicator or off Off indicator.

da Chrome: chrome://inspect/#devices NOTA: USB deve essere settato come PTP, non MTP

start emulation

    emulator -cpu-delay 0 -no-boot-anim -cache ./cache -avd avd_name

enable telnet Connect the device to your wifi, in android pTerminal

cd /system/bin
telnetd
netstat
#get the local ip of the phone
#login and you will be Root

where applications are stored:

  • /data/app
  • /data/app-private
  • /system/app/
  • /sdcard/.android_secure (shows .asec files, not .apks)

On Samsung phones: /sdcard/external_sd/.android_secure You need to be rooted to view the first three.

Native Binaries

native bin copy

you cannot make files executable in /sdcard

using SSHDroid

    # use any dir you have rw access to
    scp -P 2222 $FILE root@$PHONEIP:/data/data/berserker.android.apps.sshdroid/$DIR
    # give exec permissions if it is ARM executable bin
    chmod +x $FILE

using assets folder

  1. Use getAssets().open("$YOURBINARY") to get an InputStream.
  2. Write it to /data/data/app.package.name where your application has access to write files
  3. and make it executable: "/system/bin/chmod 744 /data/data/app.package.name/$YOURBINARY" via Runtime.getRuntime().exec()
  4. Run your bin, via Runtime.getRuntime().exec()

using ADB:

    adb push $YOURBINARY /data/local/tmp/$YOURBINARY
    adb shell
    cd /data/local/tmp
    chmod 755 $YOURBINARY
    ./$YOURBINARY

native ARM build

using GCC static linking

    # install the cross compiler
    sudo apt-get install gcc-arm-linux-gnueabi
    # usa un progetto C
    wget http://rsync.samba.org/ftp/rsync/rsync-3.x.tar.gz
    tar -zxv -f rsync-3.x.tar.gz
    cd rsync-3.x
    # using static linking
    ./configure --host=arm-linux-gnueabi CFLAGS="-static"
    make

controlla formato binario:

    file yourbin
    yourbin: ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.14, statically linked, not stripped

for better performance, use NDK+JNI

Go golang ARM static compile:

    export GOARCH=arm
    export GOOS=linux
    export GOARM=7
    go build
    # out pops an ARM executable that you can actually run on Android

native ARM bin execute

Copy myexectuable under your Android project's ./libs/armeabi/ folder. the bin has the same restrictions that your main Android app has (if you don't have internet access, neither does it. It has the same file system limits).

    adb push myexecutable /data/local/tmp/myexecutable
    adb shell
    cd /data/local/tmp
    chmod 755 myexecutable
    ./myexecutable

get app bin dir:

    String dir = getApplicationInfo().nativeLibraryDir();
    Process p = Runtime.getRuntime().exec(dir+ "/libmyexecutable.so");
public String exec() {
  try {
      Process process = Runtime.getRuntime().exec("/system/bin/ls /sdcard");
      // Reads stdout.
      // NOTE: You can write to stdin of the command using process.getOutputStream()
      BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream()) );
      int read;
      char[] buffer = new char[4096];
      StringBuffer output = new StringBuffer();
      while ((read = reader.read(buffer)) > 0) {
          output.append(buffer, 0, read);
      }
      reader.close();
      // Waits for the command to finish
      process.waitFor();
      return output.toString();
  } catch (IOException e) {
      throw new RuntimeException(e);
  } catch (InterruptedException e) {
      throw new RuntimeException(e);
  }
}

SL4A

impossibilità di eseguire script direttamente sul dispositivo. SL4A non implementa un server RPC in Java che mette a disposizione dei metodi per accedere alle risorse. scripting sul dispositivo mobile. utile a sviluppare rapidamente task automatizzati senza GUI.

    adb install sl4a_*.apk
    adb install phpforandroid_r*.apk

"insufficient permissions for device" questo causa l'OS di richiedere la dialog per autorizzare la connessione dell'applicazione

controllare che il dispositivo sia riconosciuto

    # lista device USB
    lsusb
    >Bus 002 Device 014: ID 18d1:4ee7 Google Inc.
    ...Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 
    # lista device android
    sudo ./adb devices
    # verifica versione di adb ed installa la più aggiornata possibile
    adb version
    android update adb
    #
    sudo adb kill-server
    sudo adb start-server
    # set udev rules
    sudo gedit /etc/udev/rules.d/51-android.rules
    chmod a+r  /etc/udev/rules.d/51-android.rules
    sudo /etc/init.d/udev restart
    # test
    sudo adb push  ./platforms/android/ant-build/prj-debug.apk /mnt/sdcard

Sqlite Datatbase

Inspect the database of your device installation

    PKG=it.ev.mobile
    DB=testdb
    #
    adb shell "run-as $PKG chmod 755 /data/data/$PKG/databases"
    adb shell "run-as $PKG chmod 666 /data/data/$PKG/databases/$DB"
    adb shell "rm /sdcard/$DB"
    adb shell "cp /data/data/$PKG/databases/$DB /sdcard/$DB"
    #
    rm -f /tmp/${DB}
    # copia dal dispositivo il db su fs locale
    adb pull /sdcard/${DB} /tmp/${DB}
 
    sqlitebrowser /tmp/${DB}