0

I'm developing an app, that should support multiple android sdk versions. It uses the ActionBarSherlock library and sliding menu. On android 4.0+ the app runs just well. But when I try to run it on all of the devices with lower sdk version, the app crashes with strange error. Here is the stack trace:

08-08 11:54:11.626: ERROR/dalvikvm(4782): Could not find class 'ru.arsenalmedia.AvatatorActivity', referenced from method ru.arsenalmedia.Auth.complete
08-08 11:54:11.646: ERROR/dalvikvm(4782): Could not find class 'ru.arsenalmedia.AvatatorActivity', referenced from method ru.arsenalmedia.Auth.onActivityResult
08-08 11:54:11.696: ERROR/ResourceType(4782): Style contains key with bad entry: 0x010102ce
08-08 11:54:12.346: ERROR/dalvikvm(4782): Could not find class 'android.os.StrictMode$ThreadPolicy$Builder', referenced from method ru.arsenalmedia.proto.Utils.enableStrictMode
08-08 11:54:18.346: ERROR/AndroidRuntime(4782): FATAL EXCEPTION: main
        java.lang.NoClassDefFoundError: ru.arsenalmedia.AvatatorActivity
        at ru.arsenalmedia.Auth.complete(Auth.java:119)
        at ru.arsenalmedia.proto.ServiceWorker$ClientRequest$2.handleMessage(ServiceWorker.java:951)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:143)
        at android.app.ActivityThread.main(ActivityThread.java:4914)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
        at dalvik.system.NativeStart.main(Native Method)

Manifest:

   <uses-sdk
          android:minSdkVersion="8"
          android:maxSdkVersion="17"
            />
<application android:icon="@drawable/icon"
             android:label="@string/app_name"
             android:name="ru.arsenalmedia.Avatator"
             android:theme="@style/actionBarStyle"
        >
    <activity
            android:screenOrientation="portrait"
            android:name="ru.arsenalmedia.Auth"
            android:label="@string/app_name"
            android:clearTaskOnLaunch="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
            android:label="@string/app_name"
            android:name="ru.arsenalmedia.AvatatorActivity"
            android:screenOrientation="portrait"
            >
    </activity>
    <activity android:name="ru.arsenalmedia.SlidingPanelActivity" />
    <activity android:name="ru.arsenalmedia.TestAct"/>

</application>

I thought, that it was because of the sliding menu. I've tried to use native SlidingPaneLayout, but the issue is the same. I read a lot about this and nothing really helps. Please, help !!!

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.SearchView;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import ru.arsenalmedia.avatator.R;
import ru.arsenalmedia.proto.ContactInfo;
import ru.arsenalmedia.proto.GroupInfo;
import ru.arsenalmedia.proto.ServiceWorker;

public class AvatatorActivity extends SlidingFragmentActivity implements SearchView.OnQueryTextListener, MenuItem.OnActionExpandListener {

    private static final String TAG = "AvatatorActivity";
    protected Fragment mFragment;
    private SearchView searchView;

    private Menu menu;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle(R.string.app_name);
        actionBarInit();

        // set the Above View
        if (savedInstanceState != null)
            mFragment = getSupportFragmentManager().getFragment(savedInstanceState, "mFragment");
        if (mFragment == null)
            mFragment = new GroupsList();
        //searchView = (EditText) findViewById(R.layout.contact_search_edittext);

        setContentView(R.layout.content_frame);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.content_frame, mFragment)
                .commit();

        // set the Behind View
        setBehindContentView(R.layout.menu_frame);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.menu_frame, new AppMenuFragment())
                .commit();

        customizeSlidingMenu();
        //updateMenuTitles();
        invalidateOptionsMenu();
    }

    private void actionBarInit() {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
        setSlidingActionBarEnabled(false);
    }

    private void customizeSlidingMenu() {
        SlidingMenu sm = getSlidingMenu();
        sm.setShadowWidthRes(R.dimen.shadow_width);
        sm.setShadowDrawable(R.drawable.shadow);
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        sm.setFadeDegree(0.35f);
        sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        sm.setBackgroundResource(R.drawable.sliding_menu_selector);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        getSupportFragmentManager().putFragment(outState, "mFragment", mFragment);
    }

    public void switchContent(Fragment fragment) {
        Log.d(TAG, "SWITCH CONTENT");
        mFragment = fragment;
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.content_frame, fragment)
                .commit();
        //updateMenuTitles();
        invalidateOptionsMenu();
        getSlidingMenu().showContent();
    }
PAcan
  • 871
  • 2
  • 15
  • 32

4 Answers4

2

Are you using eclipse adt plugin? if so, just right click the project->properties->Java Build apth ->Order and export, then make the Android Dependencies is checked.enter image description here

EDIT: as you are using Intellij, have you checked if you have imported the SlidingMenu library as a module?enter image description here

ps. , I am using Android studio & Maven, I think you can just import the project as library if you are not using maven.

Weibo
  • 1,042
  • 8
  • 18
  • No, I'm using itellij Idea. Thanks for the answer – PAcan Aug 08 '13 at 02:30
  • Yeah, exactly. You can do it like this, but I've imported all of the source code into my project. – PAcan Aug 08 '13 at 02:43
  • 1
    Try to use targetSdkVersion instead of maxSdkVersion and change the style to android:theme="@style/Theme.Sherlock". As far as I know, the android-sdk add actionbar in 4.x, ActionBarsherlock helps us to implement the actionbar in android which version is below 4.x. – Weibo Aug 08 '13 at 02:50
  • 1
    Send me along your code if you can, i want to look more detail into the issue. – Weibo Aug 08 '13 at 03:02
  • This helped! But I had also to reset my super Eclipse ADT IDE. – Chris W Apr 18 '14 at 23:37
1

StrictMode was introduced in API level 9 (version 2.3) so the older versions you're testing on must not be able to call it...

08-08 11:54:12.346: ERROR/dalvikvm(4782): Could not find class 'android.os.StrictMode$ThreadPolicy$Builder', referenced from method ru.arsenalmedia.proto.Utils.enableStrictMode

When you call your Utils.enableStrictMode() method you should first check if the users device is running a version that has access to StrictMode.

EDIT: Something like this may also be causing a problem; using xml attributes that didn't exist in older platforms in your styles.xml, per this line:

08-08 11:54:11.696: ERROR/ResourceType(4782): Style contains key with bad entry: 0x010102ce

It still doesn't explain your NoClassDefFoundError

Community
  • 1
  • 1
Tonithy
  • 2,300
  • 1
  • 20
  • 20
  • Strict mode in the app is never used. So it's not even working. I thought about that this is the issue, but I've commented out the method and found out that it's not. Thanks for quick response. – PAcan Aug 08 '13 at 01:15
  • 1
    @PAcan Hmm... Did that change the stack trace much? – Tonithy Aug 08 '13 at 01:25
  • No :)) the stack trace is the same, but this line disappeared: 08-08 11:54:12.346: ERROR/dalvikvm(4782): Could not find class 'android.os.StrictMode$ThreadPolicy$Builder', referenced from method ru.arsenalmedia.proto.Utils.enableStrictMode – PAcan Aug 08 '13 at 01:30
  • @PAcan Actually, another question. Are you using ActionBarSherlock? – Tonithy Aug 08 '13 at 01:32
  • Yes, and fleinstein's(smth like this) sliding menu. – PAcan Aug 08 '13 at 01:33
1

This is a pretty elusive problem. You mentioned that it works on Android 4.0+, and that sets off an alarm that you might be using something that's not supported in older versions of Android.

But before all that, if you're using Eclipse, you should refresh your project and do a clean build. Sometimes Eclipse has trouble picking up AndroidManifest changes and you might be loading an older version on your emulator/device.

If it still fails, it might be that you're importing something not supported in older APIs, or perhaps the AvatatorActivity class extends something only available in newer APIs. Can you post some code for your AvatatorActivity (namely, the imports and what AvatatorActivity extends)?

It would also help to know what you set for android:minSdkVersion and android:targetSdkVersion.

======== EDIT ========

Thanks for posting the code. The SlidingFragmentActivity is very suspicious, and chances are this library is missing. The easiest way to debug this would be to save a copy of the current AvatatorActivity.java and replace it with the following to see if you can launch the activity.

public class AvatatorActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(R.string.app_name);
    }
}

If this bare-bone Activity launches, then there's a problem with your SlidingMenu setup.

don
  • 121
  • 4
0

Thanks everyone, I've found the solution. It was the problem with SearchView. You should use one from ActionBarSherlock or SupportLibrary

PAcan
  • 871
  • 2
  • 15
  • 32