Exception java.lang.NoClassDefFoundError: android.

2020-03-19 03:48发布

问题:

Hi all I am getting a exception while working with support lib. I know lot of question and answer are available in SO but no one work for me

11-27 11:58:15.470: E/AndroidRuntime(19609): FATAL EXCEPTION: main
11-27 11:58:15.470: E/AndroidRuntime(19609): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:147)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at com.devicemonitor.DeviceMonitorActivity.onCreate(DeviceMonitorActivity.java:29)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.app.Activity.performCreate(Activity.java:5104)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.os.Looper.loop(Looper.java:137)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at android.app.ActivityThread.main(ActivityThread.java:5041)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at java.lang.reflect.Method.invokeNative(Native Method)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at java.lang.reflect.Method.invoke(Method.java:511)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-27 11:58:15.470: E/AndroidRuntime(19609):    at dalvik.system.NativeStart.main(Native Method)

What i have did is like this - I have android-support-v7-appcompat.jar as well as android-support-v4.jar in android java build path.

In some answer in SO suggested that unchecked Android dependencies in java build path i tried it also but nothing is working for me.

In my gen folder there are two package one for goole-play-service-lib and another for my project , and in my project package under gen folder only trwo file is there R.java and BuildCOnfig.java. Anybody have any suggestion please suggest me

回答1:

Import the support.v7.appcompat as a library project in your workspace and attach it with your project.

Try this,it will work for sure. if you still face any issue, do comment.



回答2:

You have to just delete your appcompat and re-import it to eclipse and change its android built property to highest api configuration. Clean your project, copy-paste R file in gen package and change project build path to highest api level like api-21.

This will solve your problem.



回答3:

In "android-support-v7-appcompat" project:

-Delete “android-support-v7-appcompat” from Package explorer.
-Import again and check “Copy into workspace”
-In Properties -> Android -> in Project build target, uncheck Android 2.2 and check Android 4.1.2
-In Java build path, uncheck if you have any .jar library, and uncheck the Dependence

and finally this is what you need to do.



回答4:

Try to import v7 appcompat with resources for your project rather than directly using .jar file.

Here is the link for importing appcompat with resources - https://developer.android.com/tools/support-library/setup.html

If you come across problems in your project after importing v7 appcompat, cross check target sdk version in manifest and set the target sdk version to the latest sdk api version.

Hope this helps !!



回答5:

The problem seems wider, but in my particular case it was caused by clashing between the following dependencies in build.gradle

compile 'com.facebook.android:facebook-android-sdk:3.21.1'

compile 'com.google.android.gms:play-services-plus:7.5.0'