I want to be able to use the action bar in my android project (2.3), so I am trying to import the actionbarsherlock library. However, I am having problems....
I've imported the library, edited the build path of my android project to include the library, and also deleted the android-support-v4 jar from the ABS /libs directory and copied my project's android-support-v4 into the ABS /libs directory to solve the jar mismatch. However, now that I've done all those things, my project can't resolve myproject.R anywhere. I import myproject.R in almost all of my .java files, and they all have the same error ("The import com.myproject.R cannot be resolved"). In addition, when I clean my project, I get a lot of errors in the console window:
They all go along the lines of:
error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light'.
To my knowledge, R is where all of the layout information is stored, so I have no idea why this is even a problem...
I've been working on this error for days, and I'm extremely frustrated and finally decided to take it to stack overflow. Thanks guys for the help!
ActionBarSherlock is a library project.
So import the library project in your eclipse
Its a library project. To check Right Click on your library project. goto Properties.
Choose android. You will see a Is Library checked as shown in the below pic.
Add your library project to your Android project.
Right click on your Android project. Goto Properties . Choose android . Click add button add the library to your project. You can see a green tick in the below pic.
Make sure you have one copy of andorid-suuport-v4.jar in your libs folder.
Do not import R.*;
You will see two R.java one for the library project and one for your android project.
Clean and build.
edited the build path of my android project to include the library
Never manually modify the build path of an Android project.
ActionBarSherlock is an Android library project. You need to add a reference to ActionBarSherlock's library project from your main application project and undo the manual change to the build path.
UPDATE
The second half of your problem was that your build target was set too low. The build target controls what version of the Android classes, resources, etc. is available to your app, and if you use ActionBarSherlock, you need this to be API Level 14 or higher.
if I make my project build target 4.0, can I still run it on an emulator/phone running Android 2.3?
Yes. Set your android:minSdkVersion to be 10 or lower. Eclipse (via Lint) will yell at you if you accidentally try using classes, methods, and such that are higher than your minSdkVersion, even though they are legal due to your build target.
I found that
if minSDKVersion in AndroidManifest.xml of the Project is lower than library,
it also make the Project to be error to build R.java
Related
A moment ago I updated Java to 8.025 (and auto removed the old one) so suddenly Eclipse won´t start. Therefore I reinstalled eclipse with the Andriod SDK and everything but now no project works anymore working from the same workspace. Creating a new project gives an exclamation mark on the project folder, the rest of the projects have one (!?) class that gives an error. I´m fairly sure that this has something to do with the appcompat thing that automatically gets installed but that´s just a guess.
Cleaning all projects gives back this error for a bunch of themes it seems:
error: Error retrieving parent for item: No resource found that matches the given name 'Theme.Base.AppCompat.Light.DialogWhenLarge.Base'.
Sorry for not being anymore precise but I have no clue of what is going on. If someone could explain this appcompat thing, what it does, and why it is needed as well (as if you´re explaining it to a child), and give a guess of what might be wrong that would be awesome.
Also, even the appcompat gives an error. Seems strange as it gets installed automatically.
v7 appcompat library gets added when you create a new project in Eclipse if the min SDK is set lower than API 14. v7 appcompat library adds support for the Action Bar user interface design pattern. This library includes support for material design user interface implementations. This library is located in the /extras/android/support/v7/appcompat/ directory after you download the Android Support Libraries. Source: Android Support Library Features.
This library depends on the v4 Support Library. Make sure you include the v4 Support Library. Also make sure that the projects that include v7 appcompat library have same version of v4 Support Library as well.
In regards to the resource error and themes errors, make sure that the App theme in styles.xml in values-v11 values-v14 etc. folders in the projects that include v7 appcompat library are updated to the latest appcompat themes.
Since appcompat library project is giving error, it may be because the appcompat project is older version (Preview L) and should be updated to (v21 Android 5.0). I suggest deleting the library project and adding it again following these steps in Eclipse:
Select File > Import.
Select Existing Android Code Into Workspace and click Next.
Browse to the SDK installation directory and then to the Support
Library folder. For example, if you are adding the appcompat
project, browse to /extras/android/support/v7/appcompat/.
Click Finish to import the project. For the v7 appcompat project,
you should now see a new project titled
android-support-v7-appcompat.
In the new library project, expand the libs/ folder, right-click
each .jar file and select Build Path > Add to Build
Path. For example, when creating the the v7 appcompat project, add
both the android-support-v4.jar and android-support-v7-appcompat.jar
files to the build path.
Right-click the library project folder and select Build Path >
Configure Build Path.
In the Order and Export tab, check the .jar files you just added to
the build path, so they are available to projects that
depend on this library project. For example, the appcompat project
requires you to export both the android-support-v4.jar and
android-support-v7-appcompat.jar files.
Uncheck Android Dependencies.
Click OK to complete the changes.
Source: Android Support Library Setup
I am trying to add android-support-v7-appcompat to my newly created Android project.
Following the Support Library Setup Documentation (developer.android.com/tools/support-library/setup.html), section Adding libraries with resources, I have created an android-support-v7-appcompat project, before adding it as an Android dependency.
EDIT: Here are more details on the process I followed to add the library project as an Android Dependency to the main project:
In the Project Explorer, right-click your project and select Properties.
In the category panel on the left side of the dialog, select Android.
In the Library pane, click the Add button.
Select the library project and click OK.
However, even if the dependency is correctly recognized, Eclipse still sees the compatibility references, such as ActionBarActivity, as errors, forbidding me to build the project. (See picture here).
To solve this problem, I tried the solutions accepted by similar questions on SE, i.e. adding android-support-v7-appcompat to the Project's Build Path, which successfully silents the errors that prevented me to compile earlier.
However, now when building and deploying the project, I get an error: the app crashes at launch, and the Console displays an error message: Could not find android-support-v7-appcompat.apk! (See picture here).
To resume, with the first configuration I am not able to compile with Eclipse, while with the second configuration I can't launch the application.
Therefore, I have two questions:
First, how should I be adding a library to my project, so I can at the same time build my project and be able to use the library's additions in my code in Eclipse?
Secondly, I feel like I am missing theoretical knowledge on how Eclipse handles dependencies.
What is the difference between adding a library as Android dependency vs Java Dependency / vs adding the project or its jar to the Build path?
First, how should I be adding a library to my project, so I can at the same time build my project and be able to use the library's additions in my code in Eclipse?
Your first approach should be fine, which would indicate that there is some other problem. For example, there may be errors in the appcompat library project that are preventing it from being compiled. However, given the error from the second approach, either you are running the appcompat library (which will not work) or something else is more fundamentally broken in your project setup, where your app thinks that it is supposed to build android-support-v7-appcompat.apk, when there is no such APK.
What is the difference between adding a library as Android dependency vs Java Dependency / vs adding the project or its jar to the Build path?
Never manually modify the build path in Eclipse for an Android project. While that will satisfy the compiler, the contents of the JAR(s) will not be packaged into your APK for use at runtime, resulting in runtime crashes (e.g., VerifyError).
"Java dependency" is for pure Java source code. Not only do you not have the source code to appcompat from the SDK, but an Android library project includes Android resources (and, at least on Android Studio, also assets and an optional manifest file).
For Eclipse, library projects are attached via the approach you describe as the first approach in your question. For Eclipse, plain JARs are just dropped into libs/ in your project root, and those are automatically added to your compile-time and runtime classpaths.
OK, maybe it's just the lack of sleep, but I am having difficulty getting AppCompat classes to be visible in my Eclipse project, despite the fact that:
this project used to work
a Gradle build of this project works fine
Here's my Eclipse project setup:
So, I have:
android-support-v4.jar in libs/
android-support-v7-appcompat attached as an Android library project
The symptom is that the AppCompat classes are not visible: Eclipse reports "The import android.support.v7.app cannot be resolved" when I try to import android.support.v7.app.ActionBarActivity. The android-support-v7-appcompat.jar file appears to have the class, and it appears to be properly added to my build path (by virtue of being in "Android Dependencies", which is checked in the Eclipse build path dialog).
Other notes:
I temporarily removed the appcompat library project from the Eclipse configuration, exported Gradle build files, and added it back, with no effect on Eclipse. Adding compile 'com.android.support:appcompat-v7:19.0.1' to the dependencies block in the Gradle build file was sufficient to get the project to build using gradle assembleDebug, so it's not like I have the import statement wrong.
I created a new project and have the same issue there, so it is not tied to this specific project.
The SDK Manager reports that I have 19.0.1 of the Android Support Library installed.
I have cleaned this project and appcompat, restarted Eclipse, and have tried various profanities, with no effect on Eclipse.
Any suggestions as to where I am going wrong?
UPDATE
Here's my Java build path, per Eclipse:
Well, I'm not completely certain what I did, but it's now working.
The most likely situation is that the directory had some of the wrong files marked read-only. Allowing all files to be writeable, plus restarting Eclipse for the fourth time today, eliminated my problems, in both projects (the one depicted above and another one).
Now, it's entirely possible that I did something else along the way that got picked up by the restart of Eclipse, or just that Eclipse wanted to restart (again) before it decided to behave.
Anyway, thanks to all who provided advice!
Have you checked if the android-support-v4.jar is the same version in both projects? When you are using appcompat, in fact, you don't need the android-support-v4.jar, as it is packed in appcompat project. Another try is to verify if the Project Build Target of appcompat is <= project build target of your project.
Remove support jar from your project, since support jar is there in app-compat lib also.
I have a problem with actionbarsherlock that it drives me crazy!
I have a new workspace, I imported my project and the library projects. There is also actionbarsherlock library project.
My project doesn't generate R file, I suppose because there isn't actionbarsherlock in library path.
image 1
I import the library project and fix the path...
image 2
I clean project but if I return to project properties in the android section I SHOW LIKE IMAGE 1!!!!! It seems like eclipse doesn't save project's changes..
I try:
Change project Build Target to 4.2.2 (In my project and in actionbarsherlock).
Change in java compiler the 1.6 java compiler compliance level (checked "enable project specific settings").
Change in manifest.xml android:minSdkVersion="8".
Add android support libraries.
Refresh & clean projects...
What am I doing wrong?????
I post 2 other images and the eclipse problems..
image 3: my project
image 4: actionbarsherlock project: I change android 4.3 to 4.2.2 after screen capture..
Eclipse problems
Error retrieving parent for item: No resource found that matches the given name '#style/Theme.Sherlock'.
Cannot cast from Activity to MainActivity.
Error retrieving parent for item: No resource found that matches the given name '#style/Widget.Sherlock.ActionBar.Solid'.
Menu cannot be resolved to a type.
etc etc...
Thak you very much.
Actually you have only one problem. ie, ABS library import. If it is fixed, second problem will vanish.
The problem is your library location(you fade out it in pics;)). Try this,
1.Delete the library from project explorer(be careful, don't delete original files from disc).
2.Go to your original workspace folder and make sure that the library ABS(actionbar sherlock) is out of all other folders( the folder
contains only that library). If not, cut&past it out( or you can paste
it inside your project folder).
3.Import the library from new location.
Now, add the library to your project and see if the problem resolved.
After some time, to fix them I did some things:
Delete all my project in eclipse (not from disk).
Close eclipse.
New Workspace (3rd).
change directory of actionbarsherlock and my project
import in eclipse all actionbarlibrary (with sample project, actionbarsherlock-i18n, etc..).
import my project
fix library
close another time eclipse
now it seems to work...
Thanks to all for your answers.
I'm trying to get ActionBarSherlock and the ViewPagerIndicator libraries set up for my projects, but I seem to be running into a few issues. I sent Jake Wharton (The developer) a few messages earlier about it, and got a few replies but couldn't get anywhere - and I think he got busy with a few other things.
What my issue is, For both VPI and ABS
Both libraries open up without any errors, and I'm using compiler version 1.6 for all as is required.
The funny thing is, if I load in the samples that are provided - they work fine and link to his library; but when I go to add the library to my project - the above happens.
Where to store the actual library project does not matter, as long as you use a relative link to reference it. Check out the Library Projects - Development considerations:
Library project storage location
There are no specific requirements on where you should store a library project, relative to a dependent application project, as long as the application project can reference the library project by a relative link. What is important is that the main project can reference the library project through a relative link.
You should always use the Eclipse ADT plugin to select and set up Library Project Reference, i.e. right-click project -> Properties -> Android -> Add, then in the opened Project Selection window, select the Library Project list here (of cause you should import them in the same Eclipse workspace as your Main Project). This will add a android.library.reference using relative path into project.properties as well as show relative path in the Android preference window:
android.library.reference.2=../../../../../Documents and Settings/yorkw/Desktop/JakeWharton-Android-ViewPagerIndicator-f09acb0/library
If you directly alter it using absolute path from project.properties as below:
android.library.reference.1=C:\\Documents and Settings\\yorkw\\Desktop\\JakeWharton-Android-ViewPagerIndicator-f09acb0\\library
Then after Eclipse refresh your project, you get the exact error described in your question, see my screenshot below:
Hope this helps.
While importing the libraries, make sure that you tick the "Copy projects int workspace" check box. The library projects need to be in the same workspace for them to work.
delete and import the project and lib again. build the lib project , add lib to project, still error shows.. rename the lib project. this worked for me ....