Question

My app is dependent on the Android Support Library V7 AppCompat (support repository version 2) for the Action Bar. That library project in Eclipse includes the Android Support Library V4 (version 18) as a dependency in its libs/ directory. My app's project folder does not contain the support libraries in libs/, presumably relying on AppCompat to export that. For the most part, my navigation drawer code resembles the standard example.

Everything works fine on Android 4+, but on Android 2 devices (both the Gingerbread emulator and a DROID 2), I get a VerifyError when the activity starts:

08-18 23:50:06.538: E/AndroidRuntime(6232): java.lang.VerifyError: com.myapp.activities.MainActivity$2
08-18 23:50:06.538: E/AndroidRuntime(6232):     at com.myapp.activities.MainActivity.onCreate(MainActivity.java:76)
08-18 23:50:06.538: E/AndroidRuntime(6232):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
...

It turns out the crash is occurring when I'm calling the constructor for ActionBarDrawerToggle.

import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;

public class MainActivity extends ActionBarActivity {
private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
    drawerView = (ListView)findViewById(R.id.left_drawer);
    drawerView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View view, int position, long id) {
            selectItem(position);
        }
    });
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }
    };
    drawerLayout.setDrawerListener(drawerToggle);
    ...
}

Note that the prior call to cast a DrawerLayout does not cause a VerifyError.

ADT 22, target API 17, min API 7. Not using Proguard, my project.properties is simply:

target=android-17
android.library.reference.1=../libraries/appcompat

I do have Android Private Libraries marked as an exported entry on my build path (in both the project and AppCompat library project), which seems to rule out one of the most common causes of VerifyError with the support library.

Was it helpful?

Solution

The issue was using invalidateOptionsMenu() instead of supportInvalidateOptionsMenu().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top