Saturday, August 29, 2015

Creating a HelloWorld Android App for Amazon Fire Phone

I've tried creating a sample project for Amazon Fire Phone and found a few issues and workarounds. I thought it might be helpful to share them here. It might be useful to Android developers getting started with Amazon Fire Phone programming.

I've followed steps on setting up development environment provided by the Amazon site. Once I've got an Amazon Fire Phone SDK Addon installed, I've created a sample app in Android Studio v1.3.2. In this example, I am using buildToolsVersion "23.0.0"

Here are the steps for creating a new project:

Android Studio v1.3.2.
- File > New > New Project
   - Application Name: HelloWorld
   - Company Domain:
   - Next
- Check on Phone and Tablet box
   - Select Minimum SDK: API 17: Android 4.2 (Jelly Bean)
   - Next
- Select a Blank Activity to be added
   - Next
- Finish

The projects has failed to compile and I've got a few errors:

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.

It looks like an Android Studio issue

A workaround is to change or comment out the dependency in build.gradle:


apply plugin: ''

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.mdzyuba.practice.sample1"
        minSdkVersion 17
        targetSdkVersion 17
        versionCode 1
        versionName "1.0"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
//    compile ''
    compile ""

After that, the project build is successful.

Next, I change the gradle version as suggested by the Amazon instructions:

   dependencies {
//        classpath ''
        classpath ''

Now, I've got an error: 

Error:Gradle 2.4 requires Android Gradle plugin 1.2.0 (or newer)  but project is using version 1.1.3.
Please use Android Gradle plugin 1.2.0 or newer.
Fix plugin version and sync project

I've modified Project Structure > Project > Gradle version: 2.2.1. I've got this version from the Amazon examples. After that, I've got a few more errors

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.

So, I've decided to comment out dependency completely:


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
//    compile ''
//    compile ""

Now, I am getting a style error:

Error:(2) Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.

Since there is no appcompat dependency, I've modified AppTheme in styles.xml to have a theme provided by the Android SDK:
Next error:
Error:(5) No resource identifier found for attribute 'showAsAction' in package 'com.mdzyuba.practice.sample1'

I just removed app:showAsAction="never"  attribute from the menu item element:

< item android:id="@+id/action_settings" android:title="@string/action_settings"

        android:orderInCategory="100" >

Next, I've got following errors:
Error:(3, 30) error: package does not exist
Error:(8, 35) error: cannot find symbol class AppCompatActivity
Error:(10, 5) error: method does not override or implement a method from a supertype
Error:(12, 9) error: cannot find symbol variable super
Error:(13, 9) error: cannot find symbol method setContentView(int)
Error:(16, 5) error: method does not override or implement a method from a supertype
Error:(19, 9) error: cannot find symbol method getMenuInflater()

I've removed a dependency on the support lib in MainActivity class:

// import;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends Activity {

Finally, good news: BUILD SUCCESSFUL :)

Running the app:

Hope it might be helpful and save time to anybody else who is creating apps for Amazon Phone with Android Studio.

Saturday, January 3, 2015

cucumber-jvm and Android Studio

During this Winter holidays, I've been exploring a Behavior Driven Development and experimented with a couple of testing frameworks: Calabash and cucumber-jvm.

In this post, I would like to describe setting up cucumber-jvm for Android Studio projects.

I've extended cucumber-jvm examples with a version for Android Studio. Here is a copy in my github branch:

In addition to the example code, here is some details on how it was created.


The cucumber-jvm requires several libraries to be added to a project:

I've found it's easier to add those dependencies with the Android Studio project setup dialog because it takes care of the jar versions for you.

File > Project Structure > Modules > app > Dependencies > + > Library dependency
  > type "cucumber" in the search dialog and submit a search request
  > select

 Make sure to set the scope for the libs as Test compile:

The cucumber-android.jar contains an apklib. Turns out Android Studio does not support it yet. Please see this post for more details.

A workaround is to build the jar yourself or just append @jar to the dependency:

androidTestCompile 'info.cukes:cucumber-android:1.2.0@jar'

Note, the `@jar` suffix is required in order to use the embedded jar file.

If you like to build the jar yourself, make a copy of cucumber-jvm

git clone

Build cucumber-android jar following the steps described here:

Copy the jar:

cp android/target/cucumber-android-1.2.1-SNAPSHOT.jar you_project/app/libs

Add a dependency on a jar file to your project

File > Project Structure > Modules > app > Dependencies > + > File dependency
> select the cucumber-android-1.2.1-SNAPSHOT.jar
> select Test compile scope.

Once this is done, the build.gradle should have something like this:

dependencies {
    androidTestCompile 'info.cukes:cucumber-core:1.2.0'
    androidTestCompile 'info.cukes:cucumber-html:0.2.3'
    androidTestCompile 'info.cukes:cucumber-java:1.2.0'
    androidTestCompile 'info.cukes:cucumber-junit:1.2.0'
    androidTestCompile 'info.cukes:cucumber-jvm-deps:1.0.3'
    androidTestCompile 'info.cukes:cucumber-picocontainer:1.2.0'
    androidTestCompile 'info.cukes:gherkin:2.12.2'
    androidTestCompile 'junit:junit:4.12'
    androidTestCompile files('libs/cucumber-android-1.2.1-SNAPSHOT.jar')


The cucumber tests are stored in a assets/features folder. I placed them under androidTest folder:


Then updated build.gradle with assets.srcDirs for androidTest:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId ""
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

        testApplicationId ""
        testInstrumentationRunner ""
    sourceSets {
        androidTest {
            assets.srcDirs = ['src/androidTest/assets']

At this point the project should build with no errors.

Test Code

The actual tests code is described here:
and in the project examples.

There are two things required by cucumber-jvm: the tests code should be in the same package as the test packageId, and the test runner should be Therefore, I've added these two lines to the defaultConfig part of the build.gradle:

 testApplicationId ""
 testInstrumentationRunner ""

Test Run Configuration

In order to create a new test run configuration for cucumber tests in Android Studio, select

Run > Edit Configurations
Click + and Select Android Tests
- Test name: CalculatorTest
- Module: app
- Specific instrumentation runner:
Click Ok

If you like, you can  run the tests from a command line:

cd your_project_folder
./gradlew connectedCheck

Test Run Results

The test results are displayed in the Android Studio: