Friday, June 3, 2016

Android Studio important points


1. To Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
            File --> Other Settings --> Default settings --> Build, Execution, Deployment --> Compiler

            Command-line option takes -stacktrace option to get the stack trace.
            Run with --info or --debug option to get more log output.

2. Suggestion: add 'tools:replace="android:icon"' to <application> element in AndroidManifestAdd xmlns:tools="http://schemas.android.com/tools" to manifest tag and tools:replace="android:icon,android:theme,android:label" to application tag.

3. For the error unmappable character for encoding UTF-8.......... Add the following line to build.gradle
android {
 ...
compileOptions.encoding = 'ISO-8859-1'
 }

4. Add support library to Android Studio project

5. Open File -> Project Structure... menu.
6. Select Modules in the left pane, choose your project's main module in the middle pane and openDependencies tab in the right pane.
7. Click the plus sign in the right panel and select "Maven dependency" from the list. A Maven dependency dialog will pop up.
8. Enter "support-v4" into the search field and click the icon with magnifying glass.
9. Run the below command in terminal to detect which image file is causing the merge to fail. After running the command check for buildLog.txt file in Project window, search for Error which will point to the exact file causing the issue.
gradlew :app:mergeDebugResources --debug > buildLog.txt
10. All com.android.support libraries must use the exact same version specification
Solution : https://stackoverflow.com/a/42374426 

Saturday, May 21, 2016

Compiling POCO libraries for Android



Create a standard toolchain

http://developer.android.com/ndk/guides/standalone_toolchain.html


$NDK_ROOT/build/tools/make-standalone-toolchain.sh \
--arch=arm --platform=android-18 --toolchain=arm-linux-androideabi-4.8 --install-dir=/Users/saba/azhar/work/android/POCO/poco-android-toolchain

————————————————————————
On El-Captain Install the openssl (openssl should be already present on a linux system)

brew install openssl
brew link openssl --force


————————————————————————

POCO build complete edition with NetSSL_OpenSSL and Crypto(without ODBC and MySQL)

cd /Users/ss/aa/work/android/POCO/poco-1.6.1-all_Shared

export PATH=$PATH:/Users/ss/aa/work/android/POCO/poco-android-toolchain/bin

./configure --config=Android --no-samples --no-tests --omit=Data/ODBC,Data/MySQL --include-path=/usr/local/Cellar/openssl/1.0.2d_1/include --library-path=/usr/local/Cellar/openssl/1.0.2d_1/lib

make -s -j4
————————————————————————

POCO build basic edition 

cd /Users/ss/aa/work/android/poco-1.6.1

export PATH=$PATH:/Users/ss/aa/work/android/POCO/poco-android-toolchain/bin

./configure --config=Android --no-samples --no-tests

make -s -j4

————————————————————————

By default POCO will compile static libs (.a) files but yet I haven't been able to successfully create a JNI wrapper to use functions available in static libs. So I compiled the shared libs and used them.

To generate shared libs open the below make file
/Users/ss/aa/work/android/POCO/poco-1.6.1-all_Shared/build/config/Android 

and change from

LINKMODE           ?= STATIC

to

LINKMODE           ?= SHARED


After the complete POCO libs are built they should be available in lib folder present under Root of POCO  (poco-1.6.1-all_Shared and poco-1.6.1 in my case)

Although I could generate all static libs, I could not generate the libPocoNetSSL.so lib.
I guess it was because the openssl lib that the POCO code referes to was using a static lib on MAC and creating a shared lib using static lib was causing some problem.

I speculate that the problem should not exist on a linux machine. Will try out soon and post the results.

————————————————————————

Do a clean up of POCO

make clean
rm -f -R lib
popd

rm -f -R Platform/Android/lib

rm -f -R Platform/iOS/lib

rm -f -R Platform/MacOS/lib

rm -f -R Build/iOS

rm -f -R Build/Android

rm -f -R Build/Darwin

————————————————————————
System 

OS X El Capitan
————————————————————————


Reference : -

http://pocoproject.org/docs/99300-AndroidPlatformNotes.html 



Monday, July 20, 2015

Fetching application data

Device must be rooted

  Open cmd
  Type 'adb shell'
  su
  Press 'Allow' on device
  chmod 777 /data
  chmod 777 /data/data
  chmod 777 /data/data/com.application.package
  chmod 777 /data/data/com.application.package/*

Open DDMS view in Eclipse and from there open 'FileExplorer' to get your desired file

After this you should be able to browse the files on the device.

Thursday, June 25, 2015

Wifi debugging on eclipse for Android

Wifi debugging on eclipse for Android
Connect your phone via usb and let it detect.
Execute following commands from platform-tools/adb.
> adb tcpip 5555
this will ping your android phone
> adb connect <ipaddress_of_phone>
this will connect with your phone

On successful completion, remove usb cable and njoy debugging without usb cable.

If you wanna reconnect again your phone for debugging, just execute the second command without connecting it with usb wire.

finally
> adb disconnect

Monday, June 22, 2015

Play youtube using the iFrame API on Android

  •  The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Unlike the Flash and JavaScript player APIs, which both involve embedding a Flash object on your web page, the IFrame API posts content to an <iframe> tag on your page. This approach provides more flexibility than the previously available APIs since it allows YouTube to serve an HTML5 player rather than a Flash player for mobile devices that do not support Flash.
  • Using the API's JavaScript functions, you can queue videos for playback; play, pause, or stop those videos; adjust the player volume; or retrieve information about the video being played. You can also add event listeners that will execute in response to certain player events, such as a player state change or a video playback quality change.
  • It briefs the different JavaScript functions that you can call to control the video player as well as the player parameters you can use to further customize the player.

Any web page that uses the IFrame API must implement the following JavaScript function:
  • onYouTubeIframeAPIReady – The API will call this function when the page has finished downloading the JavaScript for the player API, which enables you to then use the API on your page. Thus, this function might create the player objects that you want to display when the page loads.
     
Loading a video player 

After the API's JavaScript code loads, the API will call the onYouTubeIframeAPIReady function, at which point you can construct a YT.Player object to insert a video player on your page. The HTML excerpt below shows the onYouTubeIframeAPIReady function from the example above:
var player;
var pVars = {
             controls : 0,
             playsinline : 1,
      autohide : 1,
             showinfo : 0,
      modestbranding : 1,
      height : '100%',
      width : '100%'
            }; 
var vID = 'M7lc1UVf-VE'; 
function onYouTubeIframeAPIReady() 
{  
   player = new YT.Player('player', {
   playerVars : pVars,
   videoId: vID,
   events: { 
     'onReady': onPlayerReady,
     'onStateChange': onPlayerStateChange 
   }  
 });
}

To call the player API methods, first get a reference to the player object you wish to control. You obtain the reference by creating a YT.Player object as discussed above.

Playback controls and player settings

Playing a video

player.playVideo():Void
Plays the currently loaded video. The final player state after this function executes will be playing (1).

Note: A playback only counts toward a video's official view count if it is initiated via a native play button in the player.
player.pauseVideo():Void
Pauses the currently playing video. The final player state after this function executes will be paused (2) unless the player is in the ended (0) state when the function is called, in which case the player state will not change.
player.seekTo(seconds:Number, allowSeekAhead:Boolean):Void
Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing, video cued, etc.), the player will play the video.
  • The seconds parameter identifies the time to which the player should advance.
    The player will advance to the closest keyframe before that time unless the player has already downloaded the portion of the video to which the user is seeking. In that case, the player will advance to the closest keyframe before or after the specified time as dictated by the seek() method of the Flash player's NetStream object. (See Adobe's documentation for more information.)
  • The allowSeekAhead parameter determines whether the player will make a new request to the server if the seconds parameter specifies a time outside of the currently buffered video data.
Here is a working Android demo https://github.com/zenith22/YoutubeIFrameAPIDemo

For more details please refer  YouTube IFrame Player API

 

Compile OpenH264 for Android

OpenH264
OpenH264 is a codec library which supports H.264 encoding and decoding.
The source code repository is hosted on github at https://github.com/cisco/openh264.
See http://www.openh264.org/ for more details.

Compile OpenH264 for Android (using Windows)
  • In order to compile the openh264 the GNU Make (http://www.gnu.org/software/make/)utilityis required. Hence to provide make tool available on Windows, MSYS needs to be installed.

  • To compile openh264 for Android (using Windows) the following are required –
  1. MSYS (http://www.mingw.org/wiki/MSYS)
  2. Android NDK (https://developer.android.com/tools/sdk/ndk/index.html
  3. The openh264 source from github (https://github.com/cisco/openh264)

  • Post installations, ensure that everything is installed correctly, try building sample projects available with Android NDK.



  • After installing MSYS you should have a cyan "M" link on the Desktop. When you double-click on it, a terminal should be launched.
  1. Navigate to project directory (using UNIX style commands)
  2. Finally to compile use the following command make OS=android NDKROOT=/unix/path/to/ndk TARGET=9 libopenh264.so
  3. NDKROOT=/d/Softwares/android-ndk-r10 (in my case)
  4. All the libraries should be compiled post this command.

  • Once all the libs are compiled, then these can be used to run the sample apps for encoding and decoding.

Thursday, May 28, 2015

Using libyuv prebuilt shared library in Android

In my previous post I explained how to build libyuv shared library  now I would like to explain how to write a JNI wrapper and access the libyuv functions available.

Please go  through the above post before proceeding, as I'll be frequently referring to it.

From the post above, If you have successfully built the libyuv shared library then you should see the .so's generated at the location :-
LRD/libs/armeabi/libyuv_shared.so
LRD/libs/armeabi-v7a/libyuv_shared.so
LRD/libs/mips/libyuv_shared.so
LRD/libs/x86/libyuv_shared.so

We'll be needing the .so's, for the JNI wrapper will be accessing the functions present in it.



Create the following directory structures in your workspace:-


LibYUVDemo/prebuilt/
LibYUVDemo/include/
LibYUVDemo/jni/



Under the LibYUVDemo/prebuilt/ directoy paste the libyuv_shared.so files in the respective order :-

LibYUVDemo/prebuilt/armeabi/libyuv_shared.so
LibYUVDemo/prebuilt/armeabi-v7a/libyuv_shared.so
LibYUVDemo/prebuilt/mips/libyuv_shared.so
LibYUVDemo/prebuilt/x86/libyuv_shared.so

Copy the contents of include folder from libyuv source and paste it under
LibYUVDemo/include/ 

Now the actual JNI wrapper, create LibYUVDemo.cpp under
LibYUVDemo/jni/ and write a jni function as follows :-

#include <jni.h>
#include <string.h>
#include <stdlib.h>
#include "libyuv.h"
#include <android/log.h>

#define LOG_TAG "YUVDemo"
#define LOGI(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define printf(...) LOGI(__VA_ARGS__)

using namespace libyuv;

extern "C" {
JNIEXPORT void Java_com_demo_libyuvdemo_MainActivity_callLibYUV(JNIEnv* env, jobject thiz) {

libyuv::RotationMode mode = libyuv::kRotate180;

/*libyuv::ConvertToI420(const unsigned char *, unsigned int, unsigned char *, int, unsigned char *, int, unsigned char *, int, int, int, int, int, int, int, enum libyuv::RotationMode, unsigned int);
 */
    printf("rotation mode selected = %d",mode);
}

Create an Android.mk file under LibYUVDemo/jni/
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := yuv_shared
LOCAL_SRC_FILES := ../prebuilt/$(TARGET_ARCH_ABI)/libyuv_shared.so
ifneq (,$(wildcard $(LOCAL_PATH)/$(LOCAL_SRC_FILES)))
include $(PREBUILT_SHARED_LIBRARY)
endif


include $(CLEAR_VARS)

LOCAL_MODULE    := YUVDemo
LOCAL_SRC_FILES := LibYUVDemo.cpp
#LOCAL_SRC_FILES := LibYUVDemo.c


#
# Header Includes
#
LOCAL_C_INCLUDES := \
            $(LOCAL_PATH)/../include
#
# Compile Flags and Link Libraries
#
LOCAL_CFLAGS := -DANDROID_NDK

LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := yuv_shared

include $(BUILD_SHARED_LIBRARY)
Finally create an Application.mk file under LibYUVDemo/jni/

APP_ABI := all
APP_PLATFORM := android-9
APP_STL := stlport_shared

Now navigate to LibYUVDemo/jni/ from command prompt and trigger ndk-build, the JNI should get compiled and you must have the new .so geneated at LibYUVDemo/libs/ for the all the architectures.


A complete working app is available at github.