1

Let's create a clean new project:

$ mkdir ApiTest
$ android create project --target android-22 --name ApiTest \
 --path ./ApiTest --activity MyActivity --package com.example.apitest

Only add RecyclerView to layout so res/layout/main.xml looks:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recycler_view"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

Copy support libraries from ${ANDROID_SDK_PATH}/extras/android/support/v7/:

$ ls ApiTest/libs/
android-support-v4.jar            android-support-v7-cardview.jar
android-support-v7-appcompat.jar  android-support-v7-recyclerview.jar

Build & install:

$ ant debug
$ adb install -r bin/ApiTest-debug.apk

And when I open the Activity exception is raised:

09-28 20:02:02.346: E/AndroidRuntime(28688): FATAL EXCEPTION: main
09-28 20:02:02.346: E/AndroidRuntime(28688): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.apitest/com.example.apitest.MyActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
09-28 20:02:02.346: E/AndroidRuntime(28688):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2357)
09-28 20:02:02.346: E/AndroidRuntime(28688):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2419)
...

What is wrong here?

I compile on 64bit Fedora 21 using openjdk java compiler:

$ java -version
openjdk version "1.8.0_60"
OpenJDK Runtime Environment (build 1.8.0_60-b27)
OpenJDK 64-Bit Server VM (build 25.60-b23, mixed mode)
och
  • 83
  • 9

1 Answers1

2

I overlooked that there are two types of Android Support Libraries. Libraries without resources (e.g. android-support-v4) and libraries with resources (e.g. appcompat and recyclerview). See Adding Support Libraries.

To add recyclerview library (with resources) using command line and ant build tool first copy whole recyclerview directory from Android SDK directory to your project directory and update ant build files

$ cd ${ANDROID_PROJECT_DIR}
$ cp -r ${ANDROID_SDK_DIR}/extras/android/support/v7/recyclerview/ .
$ android update lib-project --path recyclerview --target android-22
$ android update project --path . -l recyclerview

The third command should add line android.library=true to recyclerview/project.properties which in my case didn't so I added it manually. When I tried it with appcompat library it work as expected.

Another thing is that in the recyclerview/src directory was missing. So simply create

$ mkdir recyclerview/src

And that is it. Now it compiles and runs.

$ ant clean && ant debug && adb install -r bin/ApiTest-debug.apk

These links helped me:

och
  • 83
  • 9
  • Fixed my issue with your guide. thanks! I have tried many ways: update support library, and copy library from extras to project libs dir. None works. The solution is copy recyclerview to project and create dependency, and copy only android-support-v4.jar to libs/ – pengguang001 Feb 23 '16 at 09:01