Tuesday, December 31, 2013

adieu 2013

Personally, I achieved several milestones this year. Hope 2014 techie-r.


Wednesday, November 6, 2013

Fragment subclasses

Here are some memos for Fragment subclasses

From Android

  • DialogFragment
  • android.app.DialogFragment
  • ListFragmnet
  • android.app.ListFragment

From gms

  • MapFragment
  • com.google.android.gms.maps.MapFragment

That's it. Make your own fragment for your convenience.

Wednesday, May 8, 2013

PhoneInfo

Sometimes we have to develope on new / unknown devices. I just created one simple application which extracts almost everything you need; CPU/Hardware, Kernel, Display, Connectivity, Telephony states. It's on Github repository, and target SDK is API 17 (JB MR1). or else, get it on Google play.


Android app on Google Play

Friday, May 3, 2013

Patterns

Active record pattern


In software engineering, the active record pattern is an architectural pattern found in software that stores its data in relational databases. It was named by Martin Fowler in his 2003 book Patterns of Enterprise Application Architecture. The interface of an object conforming to this pattern would include functions such as Insert, Update, and Delete, plus properties that correspond more or less directly to the columns in the underlying database table. For example,

part = new Part()
part.name = "Sample part"
part.price = 123.45
part.save()

is equivalent to SQL command

INSERT INTO parts (name, price) VALUES ('Sample part', 123.45);

Also, below JAVA code:

b = part.find_first("name", "gearbox")

is equivalent to SQL command

SELECT * FROM parts WHERE name = 'gearbox' LIMIT 1;


Convention over configuration


Convention over configuration (also known as coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility.

Don't repeat yourself


In software engineering, don't repeat yourself (DRY) is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures. The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system."

Abstraction principle


software engineering and programming language theory, the abstraction principle (or the principle of abstraction) is a basic dictum that aims to reduce duplication of information in a program (usually with emphasis on code duplication) whenever practical by making use of abstractions provided by the programming language or software libraries. The principle is sometimes stated as a recommendation to the programmer, but sometimes stated as requirement of the programming language, assuming it is self-understood why abstractions are desirable to use. As a recommendation to the programmer, in its formulation by Benjamin C. Pierce in Types and Programming Languages (2002), the abstraction principle reads (emphasis in original): “Each significant piece of functionality in a program should be implemented in just one place in the source code. Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by abstracting out the varying parts."

Model–view–controller a.k.a. MVC


Model–view–controller (MVC) is a software architecture pattern which separates the representation of information from the user's interaction with it. The model consists of application data, business rules, logic, and functions. A view can be any output representation of data, such as a chart or a diagram. Multiple views of the same data are possible, such as a bar chart for management and a tabular view for accountants. The controller mediates input, converting it to commands for the model or view. The central ideas behind MVC are code reusability and separation of concerns.

Singleton pattern


In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects. The term comes from the mathematical concept of a singleton.
  • Eager initialization
  • 
    public class Singleton {
        private static final Singleton instance = new Singleton();
     
        private Singleton() {}
     
        public static Singleton getInstance() {
            return instance;
        }
    }
    
  • Static block initialization
  • 
    public class Singleton {
      private static final Singleton instance;
     
      static {
        try {
          instance = new Singleton();
        } catch (IOException e) {
          throw new RuntimeException("Darn, an error occurred!", e);
        }
      }
     
      public static Singleton getInstance() {
        return instance;
      }
     
      private Singleton() {
        // ...
      }
    }
    
  • The solution of Bill Pugh
  • 
    public class Singleton {
            // Private constructor prevents instantiation from other classes
            private Singleton() { }
     
            /**
            * SingletonHolder is loaded on the first execution of Singleton.getInstance() 
            * or the first access to SingletonHolder.INSTANCE, not before.
            */
            private static class SingletonHolder { 
                    public static final Singleton INSTANCE = new Singleton();
            }
     
            public static Singleton getInstance() {
                    return SingletonHolder.INSTANCE;
            }
    }
    
  • The Enum way
  • 
    public enum Singleton {
            INSTANCE;
            public void execute (String arg) {
                    //... perform operation here ...
            }
    }
    

Wednesday, April 17, 2013

GDK?

Probably some of you already noticed that there is a newly created folder gdk inside ./android since JB (API 16). Based on the fact that gdk is result of efforts to adopt llvm into Android, I'm not sure where to begin with. I'll start with Dalvik, DVM, NDK, and LLVM before jumping into the conclusion. Even though it's not populated until API 17, but the bottom line is supporting gdk can be a good sign that Android is now ready to adopt other than DVM. along with NDK.

Dalvik and DVM


Dalvik is just another yet virtual machine which is suitable for mobile computing environment (which requires lesser memory and cpu than usual). Android uses the Dalvik virtual machine with just-in-time compilation to run Dalvik dex (Dalvik Executable). This converting job is done with the tool called dx as follows:
  • Converts class file into dex (Dalvik Executable) format.
  • Includes every constants into the above dex file.
  • Converts java bytecodes into DVM instruction sets
  • Optimization (however, there are a lot of context of 'optimization' e.g. odex, dexopt

Compilation of dex is usually done in below ways:
  • The VM does it "just in time". The output goes into a special dalvik-cache directory. This works on the desktop and engineering-only device builds where the permissions on the dalvik-cache directory are not restricted. On production devices, this is not allowed.
  • The system installer does it when an application is first added. It has the privileges required to write to dalvik-cache.
  • The build system does it ahead of time. The relevant jar or apk files are present, but the classes.dex is stripped out. The odex is stored next to the original zip archive, not in dalvik-cache, and is part of the system image.

Last not but least, there are derivation of DVM, which is called DTVM (Dalvik turbo virtual machine),and as of JB API 16, it is backward compatible with MIPS architecture. More on DTVM on MIPS.

NDK

However, DVM itself is sometimes not sufficient enough to do native-oriented application; e.g. Graphics, 3D rendering, etc. NDK is a tool that allows Android apps can run native-code. (e.g. C, C++) Main design for NDK is to tackle either computationally expensive operation (while not memory consuming), or kind of system attached operation (for example operation which requires a lot of context switching). Here is summary from NDK overview (./android/ndk/docs/OVERVIEW.html) :
  • The Android VM allows your application's source code to call methods implemented in native code through the JNI.
  • The Android NDK is a complement to the Android SDK.
  • The Android NDK provides a set of cross-toolchains (compilers, linkers, etc..) that can generate native ARM binaries on Linux, OS X and Windows (with Cygwin)
  • The Android NDK provides a set of system headers corresponding to the list of stable native APIs supported by the Android platform. This corresponds to definitions that are guaranteed to be supported in all later releases of the platform.
  • The Android NDK provides
  • The Android NDK is NOT a good way to write generic native code that runs on Android devices. In particular, your applications should still be written in the Java programming language, handle Android system events appropriately to avoid the "Application Not Responding" dialog or deal with the Android application lifecycle.
So in a nutshell, NDK is an efforts of making Android more flexible by supporting certain level of native codes. And sometimes, yes sometimes, it can be much faster.

RenderScript

Renderscript is a component of the Android operating system for mobile devices. It is a low-level API for intensive computation using heterogeneous computing. It allows developers to maximize the performance of their applications at the cost of writing a greater amount of more complex code. Renderscript offers a high performance computation API at the native level that you write in C (C99 standard). Its main goal is mainly three: portability (Applications need to be able to run on a wide range of hardware without changes), performance (guarantee to provide 60fps, utilize advanced vector operations), usability. NDK is currently working as a agent to adopt RenderScript inside Android, however, NDK has somewhat limitation as below:
  • The Android platform provides a very minimal C++ runtime support library (/system/lib/libstdc++) and corresponding headers for it in the NDK.
  • By default, this 'system' runtime does not provide: Standard C++ Library support (except a few trivial headers), C++ exceptions support, RTTI support
  • The only headers provided here are: cassert cctype cerrno cfloat climits cmath csetjmp csignal cstddef cstdint cstdio cstdlib cstring ctime cwchar stl_pair typeinfo utility
And LLVM is another solution to tackle the limitations of NDK.

LLVM

LLVM is not a virtual machine itself anymore; even though its name is VM, it started as a research project from UIUC. LLVM covers whole compiler infrastructures including C, C++, ActionScript, Ada, D, Fortran, GLSL, Haskell, Java bytecode, Objective-C, Python, Ruby, Rust, Scala, C#, and running.
In a nutshell, what LLVM does is optimization. It resides between compiler and IF (intermediate form), and produces optimized IF. This optimized IF can be converted and linked into machine-dependent assembly code. LLVM can also generate relocatable machine code at compile-time or link-time or even binary machine code at run-time. Although optimization of LLVM behaviors during link-time, run-time, compile-time is huge topic, it is beyond the cover of this post. But the bottom line is LLVM & Clang provides portability, usability and performance where above native-oriented operation need them. (as explained in RenderScript)

Clang

When we talks about LLVM, we cannot skip Clang. Clang is an LLVM native C, C++, Objective-C compiler, which aims to deliver fast compiles than classic compiler (e.g. gcc); And depends on architecture, and the nature of the complexity of the code, it can provide much faster speed for compilation. FYI, Apple populated use of Clang since Xcode 3.1 and iOS SDK as iOS is using Objective-C. Compare to gcc, Clang has below benefits:
  • Compatible with gcc
  • Lighter, more compact, and more modularized.
  • Easier to debug
  • Faster (in average)
  • Supports LLVM
  • Uses LLVM BSD license

So what is GDK?

In short, GDK is results of adopting LLVM inside Android platform. It provides faster, lighter, more compatible native-code operation inside Android platform.
You can find more details about GDK on below gerrit. It's not even surprised that llcm is also part of platform.
  • https://android-review.googlesource.com/#/admin/projects/platform/gdk
  • https://android-review.googlesource.com/#/admin/projects/toolchain/llvm

Links and references

Tuesday, March 19, 2013

More on Android building

ENG, USER, DEBUG

Reference from KAndroid
  • eng
  • This is the default flavor. A plain $ make is the same as $ make eng.
    Installs modules tagged with: eng, debug, user, and/or development.
    Installs non-APK modules that have no tags specified.
    Installs APKs according to the product definition files, in addition to tagged APKs.
    ro.secure=0
    ro.debuggable=1
    ro.kernel.android.checkjni=1
    adb is enabled by default.
  • user
  • $ make user This is the flavor intended to be the final release bits.
    Installs modules tagged with user.
    Installs non-APK modules that have no tags specified.
    Installs APKs according to the product definition files; tags are ignored for APK modules.
    ro.secure=1
    ro.debuggable=0
    adb is disabled by default.
  • userdebug
  • $ make userdebug The same as user, except:
    Also installs modules tagged with debug.
    ro.debuggable=1
    adb is enabled by default.

proguard

In Android.mk, you can put below to prevent TOO MUCH optimization with dex-opt.
LOCAL_PROGUARD_ENABLED := disabled

Tuesday, March 12, 2013

/dev/null

/dev/null is one of pseudo-devices from UNIX-like OS.
Quotes from Wikipedia: In Unix-like operating systems, /dev/null or the null device is a special file that discards all data written to it (but reports that the write operation succeeded) and provides no data to any process that reads from it (yielding EOF immediately). In programmer jargon, especially Unix jargon, it may also be called the bit bucket or black hole.
Actually, there are other kinds of pseudo-devices. For example,
  • /dev/null
  • Accepts and discards all input; produces no output.
  • /dev/zero
  • Accepts and discards all input; produces a continuous stream of NULL (zero value) bytes.
  • /dev/full
  • Produces a continuous stream of NULL (zero value) bytes when read, and returns a "disk full" message when written to.
  • /dev/random and /dev/urandom
  • Produces a variable-length stream of pseudo-random or truly random numbers.
Other name convention for Linux based OS:
  • fb: frame buffer
  • fd: (platform) floppy disks, though this same abbreviation is also commonly used to refer to file descriptor
  • hd: (“classic”) IDE driver (previously used for ATA hard disk drive, ATAPI optical disc drives, etc.)
  • hda: the master device on the first ATA channel (usually identified by major number 3 and minor number 0)
  • hdb: the slave device on the first ATA channel
  • hdc: the master device on the second ATA channel
  • hdc1: first partition on this disk (example)
  • hdc5: first logical drive in the extended partition (example)
  • hdd: the slave device on the second ATA channel
  • lp: line printers (compare lp)
  • parport, pp: parallel ports
  • pt: pseudo-terminals (virtual terminals) SCSI driver, also used by libATA (modern PATA/SATA driver), USB, IEEE 1394, etc.
  • sd: mass-storage driver
  • sda: first registered device
  • sda4: last partition on this disk (example)
  • sda6: second logical drive in the extended partition (example)
  • ses: Enclosure driver
  • sg: generic SCSI layer
  • sr: “ROM” driver (data-oriented optical disc drives; scd is just a secondary alias)
  • st: magnetic tape driver
  • tty: terminals
  • ttyS: (platform) serial port driver
  • ttyUSB: USB serial converters, modems, etc.

Wednesday, March 6, 2013

Chrome's SPDY

SPDY (which is just a abbreviation for SPEEDY) was supported from Chromium 11+, and finally it has been included in Android version of Chrome.
Basic idea for SPDY is to compress bunch of redundant protocols inside HTTP (using gzip), and to remove unnecessary HTTP headers. Consequently, it reduces time while loading the page. And yes, It's much faster.
Updated March 7th, 2013: For more tweaks you might wanna type below URL.
chrome://flags
After Chrome 27.0.1453.xx (@148877), you can check how much data was reduced after applying SPDY. (For only Android version)
Settings - Bandwidth management - Reduce data usage
Here are some links:

Monday, February 25, 2013

How ContentProvider works in Android

Why Android uses Content Provider? ContentProvider is just a Android version of passing database between multiple processes. It provides encapsulated data passing, while giving IPC between multiple processes.
Some backgrounds:
  • ContentProvider
  • A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object. Together, providers and provider clients offer a consistent, standard interface to data that also handles inter-process communication and secure data access. Quotes from Android Developer.
    Communication between ContentProvider and ContentResolver can act as encapsulated interface, as well as providing IPC between processes (Client which is using ContentProvider, and process that owns ContentProvider). Accessing ContentProvider sometimes requires special permission, and it should be addressed in the Manifest. Note: If provider does not specify any permission, NO other applications are able to access to the provider.
  • ContentResolver
  • When you want to access data in a content provider, you use the ContentResolver object in your application's Context to communicate with the provider as a client. Quotes from Android Developer.
  • Accessing ContentProvider
  • ContentProvider can be accessed by using ContentResolver, from below method.

    public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
    API Level 1.
    uri: The URI, using the content://scheme, for the content to retrieve.
    projection: A list of which columns to return. Passing null will return all columns, which is inefficient.
    selection: A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.
    selectionArgs: You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings.
    sortOrder: How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.

    public final Cursor query (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal)
    API Level 16. Same as above method except 1 parameter cancellationSignal
    cancellationSignal: A signal to cancel the operation in progress, or null if none. If the operation is canceled, then OperationCanceledException will be thrown when the query is executed.
  • URI
  • TODO
  • ContentUri
  • TODO
  • Parcel
  • TODO
  • Cursor
  • TODO
  • Contract
  • TODO
  • MIME
  • MediaStore
  • TODO
  • ContactProvider
  • TODO
  • CalendarProvider
  • TODO
  • CustomProvider
  • TODO

Wednesday, January 30, 2013

Android Notification

Starting with API level 11, all notification can be created by Notification.Builder()

Notification.Builder()
extends Object

Instead of create Notification directly, Notification.Builder() provides all necessary flags and features for Notification Here is example usage with all the settings:

new Notification.Builder(this.getApplicationContext())
        .setAutoCancel(boolean autoCancel)
        .setContent(RemoteViews views)
        .setContentInfo(CharSequence info)
        .setContentIntent(PendingIntent intent)
        .setContentText(CharSequence text)
        .setContentTitle(CharSequence title)
        .setDefaults(int defaults)
        .setDeleteIntent(PendingIntent intent))
        .setFullScreenIntent(PendingIntent intent, boolean highPriority)
        .setLargeIcon(Bitmap icon)
        .setLights(int argb, int onMs, int offMs)
        .setNumber(int number)
        .setOngoing(boolean ongoing)
        .setOnlyAlertOnce(boolean onlyAlertOnce)
        .setPriority(int pri)
        .setProgress(int max, int progress, boolean indeterminate)
        .setShowWhen(boolean show)
        .setSmallIcon(int icon, int level)
        .setSmallIcon(int icon)
        .setSound(Uri sound)
        .setSound(Uri sound, int streamType)
        .setStyle(Notification.Style style)
        .setSubText(CharSequence text)
        .setTicker(CharSequence tickerText, RemoteViews views)
        .setTicker(CharSequence tickerText)
        .setUsesChronometer(boolean b)
        .setVibrate(long[] pattern)
        .setWhen(long when)
        .addAction(int icon, CharSequence title, PendingIntent intent)
        .build()

Of course, you do not have to use every settings, as most of them have defaults value, however, you have to specify below elements at least to build Notification object. A small icon, set by setSmallIcon(), A title, set by setContentTitle()Detail text, set by setContentText()

Notification
extends Object
implements Parcelable

After API level 11, there are not much to discuss with Notification object as we can build it with new Notificaion.Build.build(). However, since this object is implementing Parcelable, it provides below 2 method:
  • void writeToParcel(Parcel parcel, int flags)
  • Flatten this notification from a parcel.
  • int describeContents()
  • Describe the kinds of special objects contained in this Parcelable's marshalled representation.

NotificationManager
extends Object

This object usually takes care of all the notifications, as its name states. In Android, there are 3 different type of notifications based on their UI; 1.A persistent icon that goes in the status bar and is accessible through the launcher, (when the user selects it, a designated Intent can be launched) 2.Turning on or flashing LEDs on the device, or 3.Alerting the user by flashing the backlight, playing a sound, or vibrating.
Here is general usage of NotificationManager

Notification mNotification = new Notification.Builder(this.getApplicationContext())
        .setBLAH()
        .setBLAH()
        .setBLAH()
        .build()
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mNotification);

mNotificationManager.cancel(mId); will dismiss based on mId or you can use .cancelAll() to simply kill all the notifications.

From the API level 16, Notification supports these styles, which can provides better UI experience; Style, BigPictureStyle, InboxStyle, BigTextStyle. Each style can take Notification.Builder(), and it will generate Notification with build() method.

This can be done simply taking Notification.Builder as a parameter with each Style, and you can find more details in Android Developer .

Wednesday, January 23, 2013

Android build trouble shooting

Assume that building system is either Ubuntu 12.04 LTS or 12.10
  • Sun JDK 6 installation
  • AOSP needs Sun JDK 6 compiler, however, The Sun JDK is no longer in Ubuntu's main package repository.
    Here is solution:
    
    $ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
    $ sudo apt-get update
    $ sudo apt-get install sun-java6-jdk
    
  • Sun JDK 6 installation 2
  • You can find the latest release of Sun (Oracle) JDK6 here:
    Oracle JDK download
  • Sun JDK 6 installation 3
  • Gaggle has well-documented installation process: Here
  • When compilation fails from /external/guava with SortedMap<K, V> onlyOnLeft = Maps.newTreeMap(comparator);
  • Google Group for android-porting has patch for the SortedMap<K, V> compilation error. To be specific, you can just modify Line number 228-229 with this:
     
    228-  public static <C, K extends C, V> TreeMap<K, V> newTreeMap(
    229-      @Nullable Comparator<C> comparator) {
    228+  public static <K, V> TreeMap<K, V> newTreeMap(
    229+      @Nullable Comparator<? super K> comparator) {
    
    

Useful links for Tizen

Wednesday, January 9, 2013

Chromium project

This only gives basic development setup for Chromium project, not Chromium OS.

For the latest version of Chrome Project, you might wanna use: Chrome Canary (a.k.a. Nightly build)

Chromium Project

  • Sync tools - depot tools
  • Here contains bunch of information for depot_tools; such as:
    gclient, gcl, git-cl, hammer, svn, drover, ccplint.py, presubmit_support.py, repo, trychange.py, git-try, wtf, weekly, git-gs, zsh-goodies
  • Sync tools - gyp
  • is a acronym for Generate Your Project. For more details: You can refer to gyp on Google Code or gyp Google Groups
  • Getting the codes - Here
  • ninja build
  • ninja build is build system focused on speed. Here are github page for ninja build, usage for Chromium project, and Google groups for ninja build.

Android.mk

For more details, refer to:Android NDK Documentation

Common used keywords from Android NDK, Revision 8d (December 2012)

Pre-reserved variable names:

  • names that begin with LOCAL_ (e.g. LOCAL_MODULE)
  • names that begin with PRIVATE_, NDK_ or APP_ (used internally)
  • lower-case names (used internally, e.g. 'my-dir')

Module-description variables:

  • LOCAL_PATH
  • This variable is used to give the path of the current file.
  • LOCAL_MODULE
  • This is the name of your module. It must be unique among all module names, and shall not contain any space. You MUST define it before including any $(BUILD_XXXX) script.
  • LOCAL_MODULE_FILENAME
  • This variable is optional, and allows you to redefine the name of generated files. By default, module <foo> will always generate a static library named lib<foo>.a or a shared library named lib<foo>.so, which are standard Unix conventions.
    NOTE: You should not put a path or file extension in your LOCAL_MODULE_FILENAME, these will be handled automatically by the build system.
  • LOCAL_SRC_FILES
  • This is a list of source files that will be built for your module. Only list the files that will be passed to a compiler, since the build system automatically computes dependencies for you. Note that source files names are all relative to LOCAL_PATH and you can use path components.
    NOTE: Always use Unix-style forward slashes (/) in build files. Windows-style back-slashes will not be handled properly.
  • LOCAL_CPP_EXTENSION
  • This is an optional variable that can be defined to indicate the file extension of C++ source files. The default is '.cpp' but you can change it.
  • LOCAL_C_INCLUDES
  • An optional list of paths, relative to the NDK *root* directory, which will be appended to the include search path when compiling all sources (C, C++ and Assembly).
  • LOCAL_CFLAGS
  • An optional set of compiler flags that will be passed when building C *and* C++ source files.
  • LOCAL_CXXFLAGS
  • An alias for LOCAL_CPPFLAGS. Note that use of this flag is obsolete as it may disappear in future releases of the NDK.
  • LOCAL_CPPFLAGS
  • An optional set of compiler flags that will be passed when building C++ source files *only*. They will appear after the LOCAL_CFLAGS on the compiler's command-line.
  • LOCAL_STATIC_LIBRARIES
  • The list of static libraries modules (built with BUILD_STATIC_LIBRARY) that should be linked to this module. This only makes sense in shared library modules.
  • LOCAL_SHARED_LIBRARIES
  • The list of shared libraries *modules* this module depends on at runtime. This is necessary at link time and to embed the corresponding information in the generated file.
  • LOCAL_WHOLE_STATIC_LIBRARIES
  • A variant of LOCAL_STATIC_LIBRARIES used to express that the corresponding library module should be used as "whole archives" to the linker. See the GNU linker's documentation for the --whole-archive flag. This is generally useful when there are circular dependencies between several static libraries. Note that when used to build a shared library, this will force all object files from your whole static libraries to be added to the final binary. This is not true when generating executables though.
  • LOCAL_LDLIBS
  • The list of additional linker flags to be used when building your module. This is useful to pass the name of specific system libraries with the "-l" prefix.
  • LOCAL_ALLOW_UNDEFINED_SYMBOLS
  • By default, any undefined reference encountered when trying to build a shared library will result in an "undefined symbol" error. This is a great help to catch bugs in your source code.
  • LOCAL_ARM_MODE
  • By default, ARM target binaries will be generated in 'thumb' mode, where each instruction are 16-bit wide. You can define this variable to 'arm' if you want to force the generation of the module's object files in 'arm' (32-bit instructions) mode.
  • LOCAL_ARM_NEON
  • Defining this variable to 'true' allows the use of ARM Advanced SIMD (a.k.a. NEON) GCC intrinsics in your C and C++ sources, as well as NEON instructions in Assembly files.
  • LOCAL_DISABLE_NO_EXECUTE
  • Android NDK r4 added support for the "NX bit" security feature. It is enabled by default, but you can disable it if you *really* need to by setting this variable to 'true'.
  • LOCAL_EXPORT_CFLAGS
  • Define this variable to record a set of C/C++ compiler flags that will be added to the LOCAL_CFLAGS definition of any other module that uses this one with LOCAL_STATIC_LIBRARIES or LOCAL_SHARED_LIBRARIES.
  • LOCAL_EXPORT_CPPFLAGS
  • Same as LOCAL_EXPORT_CFLAGS, but for C++ flags only.
  • LOCAL_EXPORT_C_INCLUDES
  • Same as LOCAL_EXPORT_CFLAGS, but for C include paths. This can be useful if 'bar.c' wants to include headers that are provided by module 'foo'.
  • LOCAL_EXPORT_LDLIBS
  • Same as LOCAL_EXPORT_CFLAGS, but for linker flags. Note that the imported linker flags will be appended to your module's LOCAL_LDLIBS though, due to the way Unix linkers work.
  • LOCAL_FILTER_ASM
  • Define this variable to a shell command that will be used to filter the assembly files from, or generated from, your LOCAL_SRC_FILES.

NDK-provided variables:

  • $CLEAR_VARS
  • Points to a build script that undefines nearly all LOCAL_XXX variables listed in the "Module-description" section below. You must include the script before starting a new module.
  • $BUILD_SHARED_LIBRARY
  • Points to a build script that collects all the information about the module you provided in LOCAL_XXX variables and determines how to build a target shared library from the sources you listed. Note that you must have LOCAL_MODULE and LOCAL_SRC_FILES defined, at a minimum before including this file.
    this will generate a file named lib$(LOCAL_MODULE).so
  • $BUILD_STATIC_LIBRARY
  • This is the same as PREBUILT_SHARED_LIBRARY, but for a static library file instead.
  • $PREBUILT_SHARED_LIBRARY
  • Points to a build script used to specify a prebuilt shared library. Unlike BUILD_SHARED_LIBRARY and BUILD_STATIC_LIBRARY, the value of LOCAL_SRC_FILES must be a single path to a prebuilt shared library (e.g. foo/libfoo.so), instead of a source file.
  • $PREBUILT_STATIC_LIBRARY
  • This is the same as PREBUILT_SHARED_LIBRARY, but for a static library file instead.
  • $TARGET_ARCH
  • Name of the target CPU architecture as it is specified by the full Android open-source build. This is 'arm' for any ARM-compatible build, independent of the CPU architecture revision.
  • $TARGET_PLATFORM
  • Name of the target Android platform when this Android.mk is parsed. For example, 'android-3' correspond to Android 1.5 system images.
  • $TARGET_ARCH_ABI
  • Name of the target CPU+ABI when this Android.mk is parsed. Two values are supported at the moment: armeabi, armeabi-v7a
  • $TARGET_ABI
  • The concatenation of target platform and ABI, it really is defined as $(TARGET_PLATFORM)-$(TARGET_ARCH_ABI) and is useful when you want to test against a specific target system image for a real device. By default, this will be 'android-3-armeabi'

NDK-provided function macros:

  • my-dir
  • Returns the path of the last included Makefile, which typically is the current Android.mk's directory.
  • all-subdir-makefiles
  • Returns a list of Android.mk located in all sub-directories of the current 'my-dir' path.
  • this-makefile
  • Returns the path of the current Makefile (i.e. where the function is called).
  • parent-makefile
  • Returns the path of the parent Makefile in the inclusion tree, i.e. the path of the Makefile that included the current one.
  • grand-parent-makefile
  • Returns the path of the grand-parent Makefile in the inclusion tree.
  • import-module
  • A function that allows you to find and include the Android.mk of another module by name.

Tuesday, January 8, 2013

Machine Learning

Stanford UFLDL Google Tensorflow

RoR: get started

Prerequisite


Ruby

Here is interesting quote from the chief designer of Ruby, Yukihiro Matsumoto
Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves.
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. It was also influenced by Eiffel and Lisp. Ruby supports multiple programming paradigms, including functional, object oriented and imperative. It also has a dynamic type system and automatic memory management; it is therefore similar in varying respects to Smalltalk, Python, Perl, Lisp, Dylan, and CLU.

Ruby on Rails a.k.a Rails

Ruby on Rails, often simply Rails, is an open source web application framework which runs on the Ruby programming language. It is a full-stack framework: it allows creating pages and applications that gather information from the web server, talk to or query the database, and render templates out of the box. As a result, Rails features a routing system that is independent of the web server. Ruby on Rails emphasizes the use of well-known software engineering patterns and principles, such as active record pattern, convention over configuration, don't repeat yourself, and model-view-controller.

jRuby

JRuby is an implementation of the Ruby programming language atop the Java Virtual Machine, written largely in Java. It is free software released under a three-way CPL/GPL/LGPL license. JRuby is tightly integrated with Java to allow the embedding of the interpreter into any Java application with full two-way access between the Java and the Ruby code (similar to Jython for the Python language).

RubyGems

RubyGems is just a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem"), a tool designed to easily manage the installation of gems, and a server for distributing them.

Ruby on Rails installation: For Ubuntu (12.10 especially),

$ sudo add-apt install ruby1.9.3
$ sudo gem install rails
$ rails new $PATH
$ cd $PATH
$ rails server
For Mac OS X (Mountain Lion especially), Install homebrew, then

$ brew install ruby
$ gem install rails
$ rails new $PATH
$ cd $PATH
$ rails server
and that's it! You can check the http://localhost:3000 (by default)

If you face any errors with
/var/lib/gems/1.8/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime.
, try to install nodejs.

Monday, January 7, 2013

HTML5 on Mobile

HTML5 on Android


Titanium


PhoneGap


Ansca Mobile


Appcelerator


Useful links


envsetup.sh

Refer to: Building the System from Android and Android Build System from KAndroid

envsetup.sh
- lunch: lunch -
- tapas: tapas [ ...] [arm|x86|mips] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.

Tizen build setup

Tizen released SDK 2.0 Alpha
Build environment setup for Ubuntu 12.10