How to edit build path entries in Eclipse? - android

So I have been having trouble with the Android Support Library with respect to a Jar mismatch or the like where for some reason I was having trouble extending the ActionBarActivity as it was giving the error that appcompat_v7.apk could not be found.
Hence I deleted the original library I had in my Eclipse projects and reinstalled the Support Library, attaching it to my project of interest with these instructions. Note that following these instructions, the new project folder is now "android-support-v7-appcompat" rather than the original "appcompat_v7".
Following this, I have tried several times to clean my project, quit and reenter Eclipse, but I still come up with two problems stating: "The project cannot be built until build path errors are resolved" and "'ProjectName' is missing required Java project: 'appcompat_v7'".
However, when going to Project --> Properties --> Java Build Path, under "Order and Export" a folder named "appcompat_v7" is shown as missing, though the other jars of interest are present, as can be seen in this screenshot:
What can I do to delete or edit this build path entry? To be clear, at this point my project will not even compile, although prior to my deleting the original appcompat_v7 folder it was able to compile but not load any Activity that extended the ActionBarActivity. I would love to be able to compile my code again -_-

The folder icon next to "appcompat_v7" indicates that it is a project. You should remove it from the "Projects" tab.

Related

Android dependencies error after renaming project

I renamed my Project:
after that i got the red callsign at my Project(which you see in the first Image) and this:
also my projectproperties says this but i'm not sure if this was also the case before renaming:
even that the path is(!) spelled correctly.
I referenced the libaries to my Project:
But i'm not able to fix the Problem. Still he doesn't recognize the Facebook and GPS libs in my Project..
I also checked this:
Libraries do not get added to APK anymore after upgrade to ADT 22
this:
accidentally removed android dependencies folder
and this...
Completely renaming a project in Eclipse
but nothing did the trick.
Any help is appreciated.
(following up after some comments)
If your project is broken after a refactor and you are going crazy to figure out what's wrong you can consider to create a fresh new project.
Create an empty project starting from the existing one is really simple, just follow this steps:
Create a new project with the desidered name
Copy oldProject/src/ to newProject/src/
Copy oldProject/res/ to newProject/res/
Copy oldProject/libs/ to newProject/libs/
Copy oldProject/AndroidManifest.xml to newProject/AndroidManifest.xml
Check that your project's classpath is set correctly, same for other dependecies.
Refresh all the projects in the workspace (one by one)
Clean (yes, it's always a good idea)
Build all
For each of your projects, verify dependencies in project references & java build path:
File -> Properties
"Java Build Path"
verify, that all projects, referenced by current project, are added.
"Project references"
verify, that all projects, referenced by current project, are checked.

What is the correct way to add an Android Library to an Android Project?

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.

NoClassDefFoundError - GameHelper Google Games

Using Eclipse IDE
Following the: https://developers.google.com/games/services/android/quickstart
Using the copy of google-play-services_lib (as recommended) and imported as Eclipse project.
Editing the game manifest with:
Adding our APP ID to res/values/strings.xml
Linked google-play-services_lib with our game project and set references in Order and Export tabs in the project settings
In accordance with https://developers.google.com/games/services/android/init using the project BaseGameUtils, from which our activity cannot inherit, because there’s another class already.
So, we moved to the second method without inheriting (see Using GameHelper without BaseGameActivity). We linked google-play-services_lib for BaseGameUtils and set the Library (compilation went down OK).
Linking added to our project to be able to use GameHelper as well as google-play-services_lib.
At this moment SDK from Facebook started causing trouble, so we had to add android-support-v4.jar (used by BaseGameUtils as well) and error during compilation occurs:
Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
Versions found are:
Path: /Users/travis/Work/Craneballs/Mafia_android/facebook-android-sdk/facebook/libs/android-support-v4.jar
Path: /Users/travis/Work/Craneballs/Mafia_android/BaseGameUtils/libs/android-support-v4.jar
the project can be launched, but crashes on GoogleHelper = new GameHelper(this, GameHelper.CLIENT_ALL)
with the error message: java.lang.NoClassDefFoundError: com.google.example.games.basegameutils.GameHelper
I’ve spent many painful hours on this and am at my wits end. Any ideas?
I was having the same problem.
Here's the solution that fixed it for me:
I had the same issue, I did the following to fix the problem.
Go to "Properties" of the project.
Select "Java Build Path"
Select "Order and Export" Tab
You should see the selected project's "src" and "gen" paths and dependencies here.
The order how they listed were first "src" and then "gen" path
I switch them, so that "gen" folder is build before the "src"
gen - automated code in project (from dependencies and references)
src - source code in project
There was no need to restart the Eclipse. It just started working.
Honestly I have never tried "Android Tools > Fix Project Properties", sometimes it might be doing the same thing. I do not know, I just did above after seen the error message, thinking something is wrong with the build paths.
Resources that might help...
NoClassDefFoundError for code in an Java library on Android
Android app crashes after SDK-tools update version (NoClassDefFound, tool version 22)

Cannot build library dependent project after update to ADT 14

In order to implement different versions of our UI we broke our program up into UI specific code and a common library project that has everything else. Up until yesterday when I updated to ADT 14 everything was working fine. Now I can't build. I keep getting the error "The container 'Library Projects' references non existing library 'path to the bin folder of my common project and the name of the project.jar'
I've been all over the web and tried everything I can think of to fix this to no avail. Can someone help me out? I'm basically stuck at this point.
Maybe you have the same issues I had when switching to the new ADT:
In my previous setup I had some resources split between the library and the main project. The library project would not compile error free on its own but only in combination with the main project which added the missing resources.
It doesn't work like this any more.
The library project must compile completely error free now. When it does the build process will create a <lib_project_name>.jar in the bin folder of the library project.
If the jar file is not created ( thus the build process of the library project failed for some reason - eg. because the changes in the R.java file (see http://tools.android.com/recent/buildchangesinrevision14 )) you will get the error message you described.
Also, I had to manually remove the <lib_project>_src from the project.
I've had a problem with a few different projects where I did the fixes suggested in the other answer, but they were only fixed temporarily.
Every time I reopened Eclipse or did a Clean on a project, the "Library Projects" directory would disappear, and I would have to open the project properties, remove the library, and add it again.
I solved this the hard way by creating a new project and copying everything into it.
Then I found an easy way to solve it. Right click the project, Refactor-->Rename. You can rename it back afterwards. This fixed it.
Check out the article "Changes to Library Projects in Android SDK Tools, r14" ( http://android-developers.blogspot.com/2011/10/changes-to-library-projects-in-android.html ) on the Android Developers blog.
E.g. #P.Melch: "I had to manually remove the _src from the project" should be done as follows:
To fix the project, you must remove the extraneous source folders with the following steps:
Right click source folder and choose Build Path > Remove from Build
path.
A dialog will pop up. In it, make sure to check “Also unlink the folder from the project” to completely remove the folder.
You have to update the Android SDK in Android SDK Manager
Android SDK Tools Intalled
Android SDK Plataforms Installed
Android SDK Builds Installed

In eclipse, unable to reference an android library project in another android project

As I was writing up this question I managed to solve it so repeat it here for the benefit of others. Here is the initial problem:
I have created a very simple library project which I want to reference in another project. I have done this previously with no problems so not really sure why it is not working this time. I have:
Flagged the library project via project properties. The default.properties file has this set : android.library=true
In my other project added reference to my library project via project properties. The default.properties file has the reference added as expected ie android.library.reference.1=K:/android_test_ws/applicationRegistrar
The green tick against the referenced library project starts off green and then changes to a red cross.
This implies that there must be something wrong / missing from the library project but I don't know what. My library project on this occasion is MUCH simpler than the previous one I created.
OK Here is the solution which I found when I was looking for the default.properies file of the referencing project (not the library) in my file system. Although the referencing project was in the same eclipse workspace as the library project, the actual files were somewhere else in the file system ie they were'nt in the same parent folder of the library project. As soon as I placed the referencing project in the same physical folder as the library project it all went fine.
I guess that this must be something to do with android using ant underneath the covers.
Edit: The project name needs match the folder name on the file system. What you are seeing in the Project Properties->Android->Library Reference is a relative file system path.
Make Sure both the projects are present in same work space.
To Do it, while importing the projects make sure "copy project into work space" check box is checked.
the same problem will occur if your library project is in different partition from your current workspace. I have the same problem just now. My git source is in C: and I just move my workspace to D: and everything start to collapse.
Simplest way to get the library paths paths correct is to use the GUI from Eclipse to add the library as shown in the following screenshot and let Eclipse take care of putting the correct relative paths in project.properties. Its a common setup to have your library projects hosted at directories vastly different than your main projects that uses the library. This method will work if the "libary project" and the project using it are in the same eclipse "workspace" (they "need not" be in same parent folder):
Please ensure that the library project is marked as "Is Library" - right click on the library project - properties - Android - mark the "Is Library" checkbox - in project.properties of the library project you should have a new entry:"android.library=true. Now add it into the project you want as described in the post below.(the post with image integrated - from Nilesh Pawar).
This bug is referenced several times here 27199, 35786, 36460 & 38052
Maybe by voting for them, it will be fixed one day...
Yet another observation on the same issue.
For me the two projects where on the same parent folder, and were both local inside the workspace. Even then the issue was still happening.
The I edited the "project.properties" file and put the absolute path(with forward slashes '/' for seperator) of the library project. Saved and closed it. Then went to the project properties dialog, removed the library(which was still showing the cross icon but with abs path) and added it back as usual.
Surprisingly the issue is resolved, and the project compiles and runs.
This is really strange and must be a bug with the ADT.
I am using ADT version 20.0.2
when developer referencing the facebook or any other library project then first of all clean the project from eclipse->project->clean project.
that want allow the error of red cross in referencing screen.
For me, I just restart the eclipse and the added library works fine.
I mean first time it showing red marks after adding the library project.
Though eclipse main project and library project are in same workspace folder and no resources files are in outside of the project folder.
So, you can try with to restart your eclipse. Happy coding....
Workaround for me was to
Create a new workspace
Import Library Project in that workspace
Import The desired project in that workspace
Having both project and library project the same target Android OS version
Reference library project in my project
solved my problem
i had the same problem there when i try to change my workspace so this my solution:
import and copy all project data including library project into workspace
delete the old project reference by Right-click on the project-->Properties-->Android-->Library, and select corrupted library(so that waht i call it) and choose Remove
clean project first (to refresh ur project properties)
go to library project Properties-->Android-->Library and check the is library if it does'nt click Apply then OK
if the library project is library is already checked, first Unchecked it then Clean the library project after that do the Step 4 again
go to project that u want the library are in then Right-click on the project-->Properties-->Android-->Library, Add then choose the library project (it should be there) and click Apply then OK
if still doesn't appear clean the project once more time and that should do
Just restart your eclipse. It's solve my problem
When you have a look at the reference-path before and after, it comes from i.e. "C:/workspace/mylib" and goes to "../../mylib" when copied to the correct location, quite interesting.
FYI,
What worked for me was to delete the 'library' projects (the actual projects) from my workspace (without deleting the files), and then re-importing them using the wizard (import existing android project from source code).
Thanks for posting the question.
I had exactly the same problem while integrating Facebook with my Android application. I fixed the issue by moving my development project to the same Windows drive in which library project was located. Somehow Eclipse is unable to read the library project's location properly from default.properties file if it is in a different drive.
Similar to Sufi Khan's post I also solved this issue with a reboot. My case differed in that when I first accessed Properties->Android and added the library I got a lovely green checkmark. When I closed the dialog Eclipse was still showing class-not-found type errors. When I checked the properties again I saw the red X. But Mr. Kahn's solution (delete the bad lib, restart Eclipse, add the lib again) worked fine.
I'm using the 0702 version of the ADT bundle (starts with "cluster", rhymes with "duck").
I followed the accepted answer but also had to make sure my "project.properties" file was readable.
If the file is readonly (checked into source control) eclipse will not edit it. Adding the library reference will succeed, but the change won't be persisted after hitting OK.
If closing the preferences window and reopening in again removes the library you just added, this may be your solution.
In case your library project still doesn't show up try adding library flag in your library project properties
Add android.library=true
project.properties
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-17
android.library=true

Categories

Resources