Android Gson no classDef found - android

i need a help with using Gson library. I made a build path and imported it into my class, but when i initialize the Gson object i get an NoClassDefFoundError. I also tryed to download some other versions but didnt helped. Now using 2.2.4.
Thanks in advance!

Try this
Right click on project
Properties
Java Build Path
Order And Export
Check all dependencies
Clean and Build
Now Run your project

Here is a guide that could help you. Its explains how to setup and use GSON.
Use GSON to work with JSON in your Android apps

To add support of GSON on android studio, just add line below to app build.gradle file.
compile 'com.google.code.gson:gson:2.7'
By now 2.7 is last current available version according to: https://mvnrepository.com/artifact/com.google.code.gson/gson
Please check this repository to be sure you are using last available version.

Related

greenDao importing classes in Android Studio

I'm trying to include in my project GreenDAO ORM, useless to say that there is no good tutorial that makes it work from scratch and there is ridiculous documentation on the official site. I used this greendao tutorial and made all intermediary steps to generating classes with gradle task. But now I'm stuck, Android Studio gives me an error for every generated class like:
Cannot resolve symbol 'AbstractDaoMaster'. All imports are actually in place but there is no way to make it work.
Things I tried:
invalidating caches
updating AS to 1.2.1.1
I have iMac OS X Yosemite 10.10.2
I have no clue what to do next.
The documentation on the official site it's a bit old, for Eclipse projects. Using Android Studio I always follow this tutorial, it worked always like charm.
I am sorry I didn't find your question in time - the answer was already in the 2nd part of the tutorial you mentioned:
compile files('libs/greendao-1.3.7.jar')
For the future, I really recommend adding Gradle dependency for greenDAO, instead of a jar file. It's more flexible and easy this way. Just add compile 'de.greenrobot:greendao-generator:2.1.0' to build.gradle and sync it. You can always check the last version here.
See this blog post for a step by step tutorial with explanation.
I actually had to update build.gradle in the app module with:
compile files('libs/greendao.jar')
and manually sync gradle scripts with project files. After that, all dependencies are met.

how to use JakeWharton-Android-ViewPagerIndicator in intellij?

Hi there I am just newer in android development and I am trying to build my first app and I do will until now.
but I need to use ViewPagerIndicator so I do my search and I've found JakeWharton-Android-ViewPagerIndicator also I am using inellij IDE
but the problem that when I want to add this library into my project I can't find the jar file and I don't know if the error from my side or what please any help.
regards
You will need to create a new module with the library sources and add it as a dependency to your main module. This answer has detailed steps you can follow. Just replace the library used with ViewPagerIndicator.

Android Studio + Volley [duplicate]

This question already has answers here:
Volley Android Networking Library
(19 answers)
Closed 8 years ago.
I'm new to Android Studio and I want to use Volley library for my app but i can't add the source as a library in Android Studio.
I've searched the web but couldn't find anything. Everywhere is said to import as a library but I don't know how.
I got the volley source from git repository:
https://android.googlesource.com/platform/frameworks/volley
But I don't know how to add it to my project as a library.
UPDATE:
Volley is now official and is available through the JCenter. Here's how to import it:
implementation 'com.android.volley:volley:1.1.1'
DEPRICATED WAY:
Late to the party, but was able to import it by adding this to the build.gradle file:
dependencies {
compile 'com.mcxiaoke.volley:library:1.0.19'
}
Here is the link to unofficial Maven repo
NOTE: Volley v1.0.19 is current as of 02/05/2016. Please go to the Maven Repo (use link above), look up the latest version (line where artifactId = library) and update the version in your gradle configuration accordingly.
If you don't want to import it as a module but simply use it as a dependency you can create a jar using ant. In your volley directory just type ant jar and you will find a volley.jar in YOUR_VOLLEY_DIRECTORY/bin (you need to install apache ant if you don't have it)
You can copy the jar in the libs directory in your android app project (or create a libs directory if you don't have one) and add the dependency to build.gradle like this
compile files('libs/volley.jar')
I know this is a little later than the other 2 answers, but I couldn't get the JAR import method to work, or exporting Volley to Gradle as the latest version kept on producing errors that the Gradle version was too old...
What I did was to create a new package in my project of com.android.volley, and then copy the source code from the Volley package, making sure that you have both volley and volley/toolbox - once I did this the app ran without an issue
I'm not very good at GIT, but there must be a way to export just the package into the root of your Gradle Java source
Edit: As pointed out in the comments, this doesn't work anymore.
File -> Import Module...
Select directory where you downloaded Volley and follow all of the directions (you probably won't have to change anything, just click "Next" a bunch.)
Then, start typing your volley stuff:
private static RequestQueue queue;
As you're typing RequestQueue, it might autosuggest it, or it might turn red after you type it (I can't remember for sure). If it autosuggests it, just select it, and you're done. If it's red and underlined, press Alt-Enter, and there should be an option for something like "Add from module 'volley'" Select that, and you're done.
(Sorry if this isn't all exact. It's from memory.)

AndroidAnnotations: #Rest annotation compile error

When trying to define a rest template using the #Rest annotation, and when providing one or more "converters" in that annotation, I receive the following compile error:
The converter class must be a subtype of org.springframework.http.converter.HttpMessageConverter
When, in fact, I have tried to pass in GsonHttpMessageConverter.class and MappingJacksonHttpMessageConverter.class which are both such subtypes.
I have the following libraries included in my /libs directory
androidannotations-api-2.7.1.jar
gson-2.2.4.jar
jackson-core-asl-1.9.12.jar
jackson-mapper-asl-1.9.12.jar
spring-android-auth-1.0.1.RELEASE.jar
spring-android-core-1.0.1.RELEASE.jar
spring-android-rest-template-1.0.1.RELEASE.jar
I'm not sure if this is an issue with AndroidAnnotations or with my own setup, but help would be appreciated.
I had the same problem but I solved it. Only change my Eclipse. I was using Helios with Android Development Toolkit
Now I dowload The Android SDK than includes Eclipse + ADT plugin. Use my old workspace with my proyect and all work fine!!!.
Hello its too late for answer but could be helpfull for others also who are searching for the same use Below code snippets for your problem:-
#Rest(rootUrl = BASE_URL, converters = {ByteArrayHttpMessageConverter.class,
FormHttpMessageConverter.class, StringHttpMessageConverter.class})
it is working for image as well and string params as well

GoogleAdMobAdsSDK-4.0.2.jar and google GSON

I recently downloaded the newest GoogleAdMobAdsSDK-4.0.2.jar to use in
my Android project. My project also uses the gson-1.5.jar library.
After importing the GoogleAdMobAdsSDK-4.0.2.jar and build, the Console
reports this error:
[2011-03-25 11:28:37 - <appname>] Error generating final archive:
Found duplicate file for APK: assembly-descriptor.xml
Origin 1: C:\Users\<myusername>\Documents
\admob4\GoogleAdMobAdsSDK-4.0.2.jar
Origin 2: C:\Users\<myusername>\Documents\gson\gson-1.5.jar
When i remove the gson-1.5.jar from the project, this error goes
away. I would like to use GSON in my project.
What is the problem
here? How can i use both GSON and GoogleAdMobAdsSDK-4.0.2.jar?
edit: just updated GSON to 1.6, same problem
I am having the same problem as you.
I couldn't fix it so I go back to an older version. You can get the jar that I am using from my github repo.
This is totally an admob issue and I hope they fix it soon. Someone should answer your question.
Admob includes GSON internally so you should probably use theirs. Other than that you can play around with the classpath and hope it doesn't break admob.
Although in the latest 4.1.0 it seems they removed it.

Categories

Resources