我正在开发一个应用程序,它应该支持多个 android sdk 版本。它使用 ActionBarSherlock 库和滑动菜单。在 android 4.0+ 上,该应用程序运行良好。但是当我尝试在所有具有较低 sdk 版本的设备上运行它时,应用程序崩溃并出现奇怪的错误。这是堆栈跟踪:
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)
显现:
<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>
我想,那是因为滑动菜单。我尝试使用本机 SlidingPaneLayout,但问题是一样的。我读了很多关于此的内容,但没有任何帮助。请帮忙 !!!
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();
}