I'm building an Android app which uses a library that is defined in another Eclipse project (same workspace). All is working fine, but now I added a jar file to the library project's build path. In Eclipse I exported the jar file to make it visible to dependent projects of the library (Build Path -> Order and Export -> mark the jar file). Still Eclipse (ADT) complains that the import cannot be resolved.
I have set up a test project for the library as well, and there the imports are visible after exporting the jar file as mentioned above.
Is there anything I forgot to configure?
Regards,
Martin
ADT doesn't seem to pick it up automatically :-/
Manually configuring the main project's build path to rely on the library project's jars worked for me.
Build Path -> Libraries -> Add JARs -> {Library Project}\libs\myjar.jar
Related
I am using appcompat_v7 library and facebook sdk in my project and both the library have android-support-v4.jar.If I delete any of the jar the corresponding library is not working and having both jars is not allowed.
What should I do? Kindly help me out...
The conflict is due to different versions of the jar.
Make sure you have the update support library from the android sdk manager
Copy android-support-v4.jar to libs of both the projects. The jar can be found #
android-sdk/extras/android/support/v4/andorid-support-v4.jar
Clean and build your project
remove android-support-v4.jar from FACEBOOK SDK and add android-support-v4.jar as external jar facebookSDK properties -> java build path -> libraries -> add external jar (i had remove this problem like this )
Try removing the dependency library from both appcompat_v7 and your project. To do that got to build path=>configure build path. Then select the dependency library and click on remove.
Add the support library by Android Tools=>add support library.
Do this to both projects.Then you are good to go
Its really simple
Just right click on your project as well as on the library project >android tools >Add support Library.
This will update your support library to the latest which solves the problem.
This question is ask many times while everyone are start-up android development in learning stage.
I think everyone has same environment of android but they configure differently according to projects.
I had same issue while creating new project every time and i found solution on below.
I added library appcompat_v7 into project and remove jar android-support-v4.jar from lib folder of my new project and blink ERROR was gone.
Add appcompt_v7 library project
Remove android-support-v4.jar from project lib folder
Wow error was gone
Best way to fix this issue is to look out for both jar files path. If you have "appcompact folder" in your eclipse then look into libs folder. In libs folder you have jar files.So, It's better to remove jar files from your application folder. Then at the time of compilation it will take jars from "appcompact folder".Don't keep jars in your app folder which leads to "Jar mismatching error". Error is mentioned below:
Found 2 versions of android-support-v4.jar in the dependency list,All versions of the libraries must be the same at this time.
Path: /home/vinny/workspace/appcompat_v7/libs/android-support-v4.jar (Keep this jar as it is)
Path: /home/vinny/Downloads/Demo/libs/android-support-v4.jar(Remove this Jar )
Jar mismatch! Fix your dependencies
Note : Remove jars from this path "Path: /home/vinny/Downloads/Demo/libs/android-support-v4.jar" T(Application's folder path)
Safdar Akrami is right, but also to do it on facebook SDK project!
Just right click on your project as well as on the library project >android tools >Add support Library.
This will update your support library to the latest which solves the problem.
if you have problem with the other projects that depends of facebook SDK project, you can fixed in this way:
Fix Project Setup
Add project "appcompat_v7" to build path of FriendpickerSample for example
Try removing the dependency library from both appcompat_v7 and your project. To do that got to build path=>configure build path. Then select the dependency library and click on remove. Add the support library by Android Tools=>add support library. Do this to both projects.Then you are good to go
I'm having trouble trying to import a project. After doing so I get 6 error items. Of which 4 are the same (Unable to resolve target 'Android-8').
Another one is: Project 'MyProject' is missing required Java project: 'org.json'.
Even though the file org.json.jar is in the libs folder.
And the last one is: The project cannot be built until build path errors are resolved.
What can I do to make Eclipse properly import my projects?
I even tries to create a new project and manually copie the files, but didn't turn out as expected.
To import the existing project
Project Explorer-->new Android Project from Existing Resource-->select project and check copy to the work space option(if you need)--> finish.
Problem
Unable to resolve target 'Android-8'
Right click on the project-->android-->select the target as 8 and save.
org.json.jar
Download this jar from the internet and paste the jar file in the lib folder.
3.Clean the projec once
Unable to resolve target 'Android-8'
You dont have Android-8 SDK installed on your pc.Concider downloading this SDK or if you have any SDK above this version just select it. under project properties.
Project 'MyProject' is missing required Java project: 'org.json'
This message suggest you that this project is expecting org.json library project in your workspace and you should include it as library project.
If you have got jar file then its fine,under project properties just remove library project dependancies and include jar file in build path.
How have you installed the ADT?
It's possible that if Android options aren't available, you haven't installed the ADT plugin correctly.
I would do the following:
Ensure that the ADT is installed
Delete the project and re-import it under the option "Import existing Android code into workspace"
Check that the build path options are correct. Android projects add jars in the lib folder to projects automatically, but this is worth checking.
Keep us posted!
I'm trying to build my project using ANT. My project uses ActionbarSherlock, and Roboguice-Sherlock. ActionbarSherlock is an Android library project, but Roboguice-Sherlock is not. It's not even an Android project at all. See here:
https://github.com/rtyley/roboguice-sherlock
I can get ActionbarSherlock to build using ANT no problem, the problem lies with Roboguice-Sherlock. It's not an Android project, yet it has dependencies on Android and ActionbarSherlock, as well as Roboguice. When I try to build I get a ton of errors saying it can't find the Roboguice-Sherlock stuff.
If your project has the Roboguice .jar and the library project reference to ActionBarSherlock already configured you should be able to just drop it into your libs/ folder to have it automatically picked up.
I am working with Roberto to ensure that the .jar of his project gets uploaded to GitHub for non-Maven users to use.
For now, you can clone the project simply run mvn clean package to get a standalone .jar in the target/ folder which will enable you to do as I described above.
You need to add robiguice-sherlock as a .jar to your Android project. You can download it here (click Download (JAR)). Trying to build the source in Android will fail because it is not an Android project. Once it is in your directory, you need to open project properties and add the .jar to your build path.
I'm trying to use GSON in my project, but my application is crashing, with logcat saying that com.google.gson.Gson cannot be found. I've put import com.google.gson.Gson on my class files, I have gson in my package explorer, and added it by Right click -> build path -> add libraries. It also shows up in Project->properties->java build path->libraries tab->gson. What have I done wrong?
What worked for me: Check the checkbox next to the lib (gson-2.0.jar) in: 'Project Properties' -> 'Java Build Path' -> 'Order and Export' tab. Then do a clean/build.
This adds the exported=true attribute to the classpath entry
<classpathentry exported="true" kind="lib" path="libs/gson-2.0.jar"/>
Have you put the jar file in the libs folder of the project? If not , try moving it there, creating the folder if required. Should be at the same level as the src folder.
I had a similar issue trying to get an app built and that solved it.
I'm using IntelliJ, not eclipse but here is how I did it:
Download the source files from https://google-gson.googlecode.com/files/google-gson-2.2.4-release.zip
Unpack them
Copy them into the "libs" folder of your project. I did this manually by using the terminal but you can do it by going in your project folder located in your computer. Your Project_Name >app >Libs [paste them here]
Go to your editor (IntelliJ in my case) You should see the the following 3 files in the libs folder of the project structure:
gson-2.2.4.jar
gson-2.2.4-javadoc.jar
gson-2.2.4-sources.jar
Open your build.gradle file and insert the following line in the dependencies section:
compile files('libs/gson-2.2.4.jar', 'libs/gson-2.2.4-javadoc.jar', 'libs/gson-2.2.4-javadoc.jar')
Right click on each of the source files and select "Add as Library..."
Use the following options:
Name: name of the jar file
Level: Project Library
Add to Module: select project your adding to
Rebuild project
Build > Rebuild project
Import and use it!
import com.google.gson.Gson;
I have observed today that it doesn't like when you add your library.
The solution that worked for me was to add it as an external jar only. I have observed it by doing the steps described by author of this post i.e. Properties -> Java Build Path -> Libraries -> Add External JARs and point to the downloaded gson library.
I ran into the same issue (when installed SDK 17) ...
The solution is, that you just put the pure jar files into the "libs" folder (without subfolders).
You also don't need to declare them, android wil find them itself. You may need to do a Project > Clean
I had similar problem, but I guess my requirement was more complicated as the GSON libarary was used by an Android Library Project that my main Android project depended on. I have tried both approaches above but none of them worked for me. If I add the GSON jar file directly to the main Android project it works, but that is not what I wanted.
With a bit of investigation I have realised that the GSON jar does not use any dependencies (third party libraries) itself. So my solution was to copy the source file of the GSON project to my Android Library project's src filder and it worked like a charm. so you can use the Source code rather then the binary code. The source code is part of the download in a jar file, just unzip it.
i'm sure you have copied the jar into "libs",
and also added property> Java Build Path >(tab) Libraries, right?
my issue was stupid...
please check other than Gson jar, if you have two stuffs at least in above tab:
android x.x
Android Dependencies (especially this one, i missed this, eclipse show me an error of "could not find class com.google.gson.xx" )
simply do a project copy will solve this problem...
Do not edit .classpath file directly or even put files into lib folders out of Eclipse.
Instead use the Java Build Path->Order and Export tab to select libraries to be exported in the final deployment unit (eg war/apk)
To be on safer side, do a Project->Clean after you change the build path.
I faced the same thing.But the solution was quite easy,just Right-Click on your project->Properies->Libraries->Add external jars->OK and thats it.It solved my problem.hope it will solve yours as well
If Projct Properties -> Java build path -> Add external jars doesn't work and your project is a web project, try adding the gson jar directly to the server lib folder. Example: for apache Tomcat to apache-tomcat/lib.
I have been trying the same thing and read so many answers and tried so many things but to not vial, but i solved this problem by doing just one click and its simple.
1) Add your .jar file in libs folder make sure its libs not lib
2) Clean and Build your project you will see that file under libs folder
3) right click the file and go to build path and select add to build path
Run your project it will work fine. Hope this helps
I am using Android Studio
I had the same problem I had solve it by
select project press f4 from popup
click app and in dependencies
select file dependency and select the three folders which I had pasted in lib directory
If I have simple android library (set with project->properties->android->Library) with linked folders, the linked folders are not included in the application using the library.
Choosing a library project will add a link in the application project to the library's 'src' folder and all real folders, but it will ignore any linked folders in the Library project.
---Edit: this actually works with more recent Eclipse and adt---
I can add the library as a project dependency (project->properties->javabuildpath->project) - this will make Eclipse aware of the classes in the linked folders, and fix the compile errors in Eclipse, but will not include the library classes in the apk itself and the app will fail with java.lang.NoClassDefFoundError.
What is your suggestion on using a library project with source folders linked in from outside of the library project's main folder?
The solution was under my nose all the time:
Apparently with a more recent version of eclipse and/or android tools it is enough to add the library as a project dependency project -> properties -> javabuildpath -> project.
No need to use the android library setting at all project -> properties -> android.
I am now using eclipse Helios (3.6) with Android tools 10.0.1, and it works in this combination.