Android-Universal-Image-Loader(https://github.com/nostra13/Android-Universal-Image-Loader) is my favorite library.
But it can't add libs when i use Android Studio(use 0.1.5 version).
i know how to add libs in Android Studio
(https://stackoverflow.com/a/16628496/397457)
when i add Android-Universal-Image-Loader libs to Android Studio. Editor error about "can't reslove R". i try this Max OSX(i try too Windows but fail. Windows error message => "Gradle: error: package com.nostra13.universalimageloader.core does not exist". but Editor no error message. only show when i run application)
other libs like Gson no problem. but only Android-Universal-Image-Loader have this problem.
Your Android Studio success add Android-Universal-Image-Loader? if success tell me how to.
I just added the universal-image-loader like this:
Firstly download the universal-image-loader-1.8.5-with-sources.jar.
(For 5/2014. universal-image-loader-1.9.2.jar works great. Don't need the "with-sources" file.)
Then put it on my MyAppProject/MyApp/libs.
Right clicking on universal-image-loader-1.8.5-with-sources.jar i add it as a library with the default configuration.
Finally on MyAppProject/MyApp/build.gradle add the following:
dependencies {
compile files('libs/universal-image-loader-1.8.5-with-sources.jar')
}
From the error "package com.nostra13.universalimageloader.core does not exist", it seems like you have not added the source as the library. Right click the "universal-image-loader-1.8.4.jar" file under the libs folder and from the context menu, click "Add as a library" option.
If after this you are getting the "ClassDefNotFoundException", please follow the following steps:
Add the library to the project.
Edit your Gradle build file and add the dependency for the UIL in it
Close Android Studio
Open command prompt and go to the project's root folder (you will find 'gradlew' file there) and clean your build by issuing the clean command C:\CarApplicationProject> gradlew clean
Restart Android Studio.
1.Put the jar (in my case, gson-2.2.4.jar) into the libs folder.
2.Ensure that compile files ('libs/gson-2.2.4.jar') is in your build.gradle file.
3.Now Click on the "Sync Project with Gradle files"(Left to AVD manager Button on the topbar).
After I did the above three, it started working fine.
There are two ways to use Universal Image Loader
By downloading Jar and add it to lib folder and
compile files('libs/universal-image-loader-1.9.5-with-sources.jar')
Simply add gradle dependency
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
And here is a quick tutorial link
Related
I want to add third party sdk in my android project.
Can anyone tell me the process step by step....
I tried but can't...
My Process:
Copy and paste jar file in libs folder
Add dependency in build.gradle file
then clean the project and build
You can try below methods :
First method:
switch your folder structure from Android to Project.-> paste the .jar file inside libs folder->Right click on the jar file and at end click on Add as library->This will take care of adding compile files('libs/library_name.jar') in build.gradle after sync gradle -> make sure compile files('libs/library_name.jar') added your build.gradle file -> Then build your project
Second method:
2.(If 1st method does not work for you then try it.)
switch your folder structure from Android to Project.-> paste the .jar file inside libs folder->Select Dependencies Tab, add the file by using + .Click on file dependency and Select your jar file from libs directory.->Then click OK->This will take care of adding compile files('libs/library_name.jar') in build.gradle after sync gradle -> make sure compile files('libs/library_name.jar') added your build.gradle file -> Then build your project.
Open the Android SDK Manager. At the tools tab selecct Manage Add-on Site. Then go to the User Defined Sites tab and click new. A the prompt dialog enter the URL you wish to add. Then close the window. Back at the Android SDK Manager scroll down and u should be able to locate the SDK u added. If needed at the packages tab of the SDK Manager click Show Archive Details
I'm using IntelliJ/Android Studio with Ant build (not Gradle at the moment), and am trying to use android-support-v7-cardview.jar but I continue to get
android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.widget.CardView
java.lang.NoClassDefFoundError: android.support.v7.cardview.R$styleable
I am not using m2repository with the aar file, but am using the cardview at location
sdk/extras/android/support/v7
I have gotten it to work by using the classes from the jar in my own project, but it requires API 21 (5.0) which I don't want to use yet. I am trying to use the jar file in the libs folder and res files from
sdk/extras/android/support/v7/cardview/res
I have added the lib file and res files to my own project, but still get the error messages above. What should I do?
I had the exact same problem after adding compile 'com.android.support:cardview-v7:23.2.1' to build.gradle's dependencies to use the CardView, however after cleaning the project (Build > Clean Project) everything worked like magic.
Hi this might be helpful, this worked for me. (for intellij users)
click in your project,
right click -> open Module Settings (f4)
import cardview from \sdk\extras\android\support\v7\
add .jar file to cardview module
click on your project and give module dependency to cardview
now, click (+) button on cardview -> android -> at top you will see a check box (library module), enable it.
click ok and close your settings dialog.
rebuild your project and run it.
I think you have to import it as an Android library project, then the ressources should be found correctly. I also tried first to import only the jar which didn't work, so I did it this way:
The project for the CardView is located in your Android SDK folder: Android\android-sdk\extras\android\support\v7\cardview
In Eclipse use "Import" and select "Existing Android Code Into Workspace" and import the CardView project
Go to Properties->Android of the new project, mark it as a library project and then Link it as a library project in your own project where the CardView can not be found
That should do it
I didn't figure out the error really but I just commented out the stuff that uses Android 5.0 in the source code of the library and it works fine. I didn't want to use a minSdk of Android 5.0.
If you are using Android Studio then its quick easier, Please add compile 'com.android.support:cardview-v7:21.+' in dependencies in build.gradle.
dependencies {
compile 'com.android.support:cardview-v7:21.+'
}
I am getting the error that is pictured above when I try to build my project in Android Studio.
The file that is mentioned in the error does not exist in that folder. I tried to delete the entire folder hoping it would re-download the needed file. It did re-download the folder but again it did not have that file.
I am not using this file anywhere in my project and as far as I know.
Any help would be greatly appreciated.
Thanks.
Maybe the path of file is too long that it is unable to process it. In my case, it was:
C:\Users\ber$erk-kAjU\Downloads\Compressed\android-xmpp-asmack-sample-master\android-xmpp-asmack-sample-master\XMPPAsmackSample\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\drawable-ldrtl-xxhdp
As you can see, it is huge! I just moved my project to another path, and reduced it to:
D:\AndroidStudioWorkspace\XMPPAsmackSample\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\drawable-ldrtl-xxhdp
Maybe this can help!
Use
Build > Clean Project
To clean the build directory.
I think you are using AppCompat library in your build.gradle file
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
In order to use any support library in dependency make sure you have downloaded Android Support Repository from SDK manager
After downloading the repository, do sync the project with gradle using tiny gradle button available in toolbar.
After sync completion you will be able to see mentioned png file in directory as shown :
Inside the directory.
EDIT :
If still doesn't solve check the whether your sdk pointing to right sdk from File > Project Structure > Android SDK
Also check this Import Google Play Services library in Android Studio for AppCompat Library
If there is some issue make it correct ans sync project with gradle.
I recently downloaded Android Studio to develop Android applications (I'm coming from Eclipse), and I am having issues using external libraries and/or external JAR files alongside my own project. NOTE: the following tests were conducted on a new application project created from scratch in Android Studio.
Example 1: JAR Import.
Download a fresh copy of the Admobs SDK from Google.
Copy the library jar GoogleAdMobAdsSdk-6.4.1.jar to the project's /libs/ folder.
In the project explorer, right click on the newly added library.jar and click on 'Add as Library'.
Technically at this point everything works, imports work just fine, the layout editor shows a preview of the AdView widget and all that. The only problem is that it doesn't compile successfully.
Log from console:
Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':APITests:compilePaidDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
I tried running gradlew compileDebug --stacktrace, and the problem seems to be that the despite being able to import the classes successfully in both the code & design editor, at compile time, it cannot resolve the imports. Here's the relevant part of the log: (full stacktrace here)
java:6: error: package com.google.ads does not exist
import com.google.ads.AdRequest;
java:7: error: package com.google.ads does not exist
import com.google.ads.AdView;
java:11: error: cannot find symbol
AdView mAdView;
symbol: class AdView
location: class MainActivity
java:22: error: cannot find symbol
mAdView = (AdView)this.findViewById(R.id.adView);
symbol: class AdView
location: class MainActivity
java:23: error: cannot find symbol
mAdView.loadAd(new AdRequest());
symbol: class AdRequest
location: class MainActivity
5 errors
:Test:compileDebug FAILED
But again, the imports work well in the editor, and the dependency is there:
It's also worth noting that without attempting to add a library/JAR, the projects compiles just fine.
I then tried editing the build.gradle file to include the new lib like this:
dependencies {
compile files('libs/android-support-v4.jar', 'libs/GoogleAdMobAdsSdk-6.4.1.jar')
}
This time, it did compile successfully, but the app now forces closes, as apparently, it cannot find a specific class from the lib in the application package.
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /data/app/com.foo.test-1.apk
Any ideas?
So,
Steps to follow in order to import a JAR sucesfully to your project using Android Studio 0.1.1:
Download the library.jar file and copy it to your /libs/ folder inside your application project.
Open the build.gradle file and edit your dependencies to include the new .jar file:
compile files('libs/android-support-v4.jar', 'libs/GoogleAdMobAdsSdk-6.4.1.jar')
File -> Close Project
Open a command prompt on your project's root location, i.e 'C:\Users\Username\AndroidStudioProjects\MyApplicationProject\'
On the command prompt, type gradlew clean, wait till it's done.
Reopen your application project in Android Studio.
Test run your application and it should work succesfully.
You don't need to close the project and go to command line to invoke grade:clean.
Go to Build-> Rebuild Project
Easy way and it works for me. Using Android Studio 0.8.2.
Drag jar file under libs.
Press "Sync Project with Gradle Files" button.
"simple solution is here"
1 .Create a folder named libs under the app directory for that matter any directory within the project..
2 .Copy Paste your Library to libs folder
3.You simply copy the JAR to your libs/ directory and then from inside Android Studio, right click the Jar that shows up under libs/ > Add As Library..
Peace!
Here is how I got it going specifically for the admob sdk jar file:
Drag your jar file into the libs folder.
Right click on the jar file and select Add Library
now the jar file is a library lets add it to the compile path
Open the build.gradle file (note there are two build.gradle files at least, don't use the root one use the one in your project scope).
Find the dependencies section (for me i was trying to the admob -GoogleAdMobAdsSdk jar file)
e.g.
dependencies {
compile files('libs/android-support-v4.jar','libs/GoogleAdMobAdsSdk-6.3.1.jar')
}
Last go into settings.gradle and ensure it looks something like this:
include ':yourproject', ':yourproject:libs:GoogleAdMobAdsSdk-6.3.1'
Finally, Go to Build -> Rebuild Project
you export the project from Eclipse and then import the project from Android Studio, this should solve your problem, open a eclipse project without importing it from Android Studio you can cause problems, look at:
(Excuse my language, I speak Spanish.)
http://developer.android.com/intl/es/sdk/installing/migrate.html
I had the problem not able to load jar file in libs folder in Android Studio.
If you have added JAR file in libs folder, then just open build.gradle file and save it without editing anything else. If you have added this line
compile fileTree(dir: 'libs', include: ['*.jar'])
save it and clean the project .. In next build time Android Studio will load the JAR file.
Hope this helps.
I'm using Android Studio 0.5.2. So if your version is lower than mine my answer may not work for you.
3 ways to add a new Jar to your project:
Menu under Files-->Project Structure
Just press 'F4'
under Project navigation, right clink on any java library and a context menu will show then click on 'Open Library Settings'
A Project Structure window will popup.
On the left column click on 'Libraries' then look at the right pane where there is a plus sign '+' and click on it then enter the path to your new library.
Make sure the new library is under the 'project\libs\' folder otherwise you may get a broken link when you save your project source code.
I am currently using Android Studio 1.4.
For importing and adding libraries, I used the following flow ->
1. Press **Alt+Ctr+Shift+S** or Go to **File --> Project** Structure to open up the Project Structure Dialog Box.
2. Click on **Modules** to which you want to link the JAR to and Go to the Dependency Tab.
3. Click on "**+**" Button to pop up Choose Library Dependency.
4. Search/Select the dependency and rebuild the project.
I used the above approach to import support v4 and v13 libraries.
I hope this is helpful and clears up the flow.
I use android studio 0.8.6 and for importing external library in project , paste that library in libs folder and inside build.gradle write path of that library inside dependencies like this
compile files('libs/google-play-services.jar')
In Android Studio (mine is 2.3.1) go to File - Project Structure:
Check the libs version requirements. The lib might be trying to call a method from from a higher Android version. Try adding the apps compatability libs.
When all else fails try switching from a Gradle build to an Eclipse build.
Delete and restructure your folders to the eclipse style and delete everything but your code. Then reload the project with your libs.
Once it runs go back to Gradle, if you wish.
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