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
Related
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.
I am trying to import the Support v7 library to get ActionBarActivity however it is not working. I am unable to extend ActionBarActivity.
I followed the tutorials of adding the support library in from these links
https://developer.android.com/tools/support-library/setup.html
http://hmkcode.com/add-actionbar-to-android-2-3-x/
I followed these line by line however i cannot import android.support.v7.app.ActionBarActivity; it seems to not exist. All i can import is android.support.v7.app.appcompat.R;
I am using Eclipse
Can someone help me out please. Many Thanks!.
This is the summary of what I have done which is working now
Went to SDK manager. Checked that I have the latest Android Support Library ( I have Rev 20). I did not install Support Repository as this is for android studio
Imported existing code into workspace. Selected sdk/extras/android/support/v7/appcompat/. I did NOT check copy to workspace.
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.
what I did differently was Create a new Android project rather than using an existing. By default it seemed to extend ActionBarActivity automatically since I put min SDK to API 8.
What it also did was actually do all the steps above for me! I see new project in my work space appcompat-v7
The only problem I see is on console it said something like unable to write Java cache. I lost the message but I will post it
You can create a new Project(if possible) with the viewpager activity and select actionbar in the settings. This will automatically import it into your NEW project. If you can copy your old files that'd be great.
You basically have to:
Import the android-support-v7-appcompat to your Eclipse as described on these links you read.
Link your own project with 'android-support-v7-appcompat' by going to Project Properties / Android/ Add the 'android-support-v7-appcompat' under the 'Library' section (there's a 'Add' button).
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 want to use the new ActionBarActivitiy class from the v7 support library but I cannot find the support JAR anywhere. I have a v7 folder in my extras directory but it contains 3 directories and not a jar
In Eclipse right click on on your Project -> Android Tools -> Add Support Library... and follow the instructions. As the result, required jar-file gets copied into your project's libs folder. Or you can add libraries manually how it is described in Android documentation.
Update 1: Android Tools team has made some changes to the way support library is integrated.
Android updates do this a bit different. There is still Android Tools -> Support Library option, but now it behaves a bit different. Once activated, Eclipse will silently create a new project called appcompat_v7 or similar. The name might change in the next versions of ADT. You must be able to find this project in your workspace. This project contains android-support-*.jar file. This is a new library project. In turn, your project receives a dependency on that library project.
You can stay with the updated configuration "as is" and start using compatibility API. Or alternatively, you can copy android-support-*.jar files into your project's lib folder and remove dependency on appcompat_v7 library project. Both options will work just fine.
Update 2: They change this behavior quite often. Try Project -> Android Tools -> Add Support Library... first. If it doesn't work, please check out official documentation for more recent information.
Update 3: It is really worth to migrate to Android Studio to avoid multiple issues with ATD nowadays.
ActionBarActivity is in an Android library project, not a JAR. There are instructions in the Android developer documentation for how to add an Android library project to your environment and attach it to your application project.
You have to update your Support Library through your SDK and then navigate to the folder where your SDK is located! Then go to : Extras->Google and you will find the Project and the jar included!
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