When applications crash when implementing the Action Bar v7 support library for Android 2.3 and higher

I have successfully created an application in Eclipse and it works for android 4.0 and higher. Now I want to make it compatible with Android 2.3 and higher. In my application, I used the action bar, so I added the support android-v7-appcompat android library project to my workspace in my workspace. Following the instructions of http://developer.android.com/tools/support-library/setup.html , I now have android-v7-appcompat.jar and android-support-v4 support. jar'under my projects Android Private Libraries section. I also have jar files in the libs folder of my project.

In my main activity, I imported:

import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBar; 

In the AndroidManifest.xml file, I stated:

 <application android:allowBackup="true" android:theme="@style/Theme.AppCompat" 

In addition, for various actions declared as:

  <activity android: android:uiOptions="splitActionBarWhenNarrow" 

Previously, my AndroidManifest.xml was something like this:

 <application android:allowBackup="true" android:theme="@style/<theme>" 

and the styles.xml file under res> values ​​looks like this:

  <resources xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="<base>" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="<theme>" parent="<base>"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> </resources> 

is used

  <style name="<base>" parent="android:Theme.Holo.Light"> <!-- API 11 theme customizations can go here. --> </style> 

in the folder -V11 and

 <style name="<base>" parent="android:Theme.Holo.Light.DarkActionBar"> <!-- API 11 theme customizations can go here. --> </style> 

in the values ​​folder is v14.

Now I have included all styles_base.xml and themes_base.xml files from the library project in my project. Also modified the styles.xml file, replacing Theme.

Every time I run the application, I encounter crashes, now even for versions 4.0 and later versions of Android. Message:

  java.main.NoClassDefFounderError: android.support.v7.appcompat.R$styleable at android.support.v7.app.ActionBarActivityDelegate.onCreate 

Please, help.

+4
source share
1 answer

Make sure the compatibility libraries are checked under "Project Properties β†’" Java Build Path "->" Order and Export ", as shown below:

enter image description here

Otherwise, they will not be included in the generated APK.

Edit:

I think you should start with this, as you should not add these XML files from the support library to your own project.

  • Remove all XML files and jars from the support library
  • Rebuild the new Android library project at the link you specified (follow the instructions "Adding libraries with resources").
  • Add an Android library project to your project
  • Clean and rebuild project
+4
source

Source: https://habr.com/ru/post/1494337/


All Articles