Trying to import a android project into Android studio error - java

I am new to android studio and tried to import a project which someone else had made into it .The project has google play services jar file in its libs folder.I got the following error while importing:
Why does this error occour and how do i fix it?Will it be shown for other library files also?

This can happen when your external library or the dependencies are not added in the Android Studio Properly .
So what you can do is :
1.Put the jar file into the libs folder.
2.Right click it and hit 'Add as library'.
3.Ensure that compile files('libs/google-play-services_lib.jar') is in your build.gradle file and Finally add the dependencies.
Eg.
dependencies {
compile fileTree(dir: '../jar', include: '*.jar')
compile project(':pull-to-refresh')
compile files('libraries/abcdef.jar')
compile files('libraries/google-play-services_lib.jar')
}
Hope this helps :)

With Gooole Play Services - you don't have to even copy library from old project to new one. You can get it is easily by adding in build.gradle in dependecies section:
compile 'com.google.android.gms:play-services:5.0.89'
(or any other version, that will be suitable for you) and lib will be automatically downloaded/added

Related

Add FFT algorithm to android studio

i found lot of FFT library on github but i don't know how to add them to my project.
I try to import it without success.
Can you help?
Here what i found:
1) https://sites.google.com/site/piotrwendykier/software/jtransforms
2) https://github.com/wendykierp/JTransforms
If your project has a libs folder for external dependencies then you are good. Else create one under the main project. If you have the jar with all dependencies for the FFT algorithm, put it in the above mentioned libs folder. Next open build.gradle under app and add the following line under dependencies if it not already there..:
compile fileTree(dir: 'libs', include: ['*.jar'])
Sync the project as you usually do.

Android Studio 3.0 - "Failed to transform file 'gson-2.2.4.jar' to match attributes {artifactType=android-classes}"

I'm a newcomer to Android Studio development, and I'm currently following an online tutorial to make a messenger app.
I've followed the steps of this tutorial, and it now needs me to download the Library files for Smack API & GSON, and add the .jar files to the libs folder in my project.
With this done, I right-clicked the files in the directory and clicked Add as library (the tutorial says to do Build Path -> Add to Build Path, but this doesn't seem to be an option in this version of Android Studio).
At this point, the project directory menu sidebar looks like this:
From here, I tried to rebuild the project but was met with the following error:
I've not been able to find a way around this error at all, and don't know enough about Android Studio to know if this is an issue with the IDE or the package itself. I've had a look around S/O but none of the posts seem to describe the same issue, or offer any solutions to similar issues that appear to work for this too.
If anyone has run into this before, or if it is a common Android Studio problem, would you be able to advise me on how to resolve it please? Very frustrating when I just want to get on with learning how to code for Android!
Any help massively appreciated, thanks in advance!
Mark
Here is best solution for importing any jar, arr libs
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
....
}
You do not need to add repeatable lines with libs file name.
if you are a new to android studio, you can check the project structure from android by tapping drop-down menu.
Since Gson is in maven central, you have to add mavenCentral() in buildscripts phase. you have to add the Gson library in the dependency using project structure, now to update the gradle, for the add the .jar file to your build.gradle file like:
dependencies {
compile files('libs/gson-2.2.4.jar')
}
or
dependencies {
compile 'com.google.code.gson:gson:2.2.+'
}
And make sure you are connected to the internet
did you try
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
}
in your build.graddle file of app module

Jxl.jar in android

I don't know how to add jxl.jar in android studio
I tried to pasts jxl.jar in lib project and using project structure
then tried to start to create WorkBook obj
but not working.
what I missed?
If you use gradle (Android Studio), then add in dependencies:
dependencies {
implementation 'net.sourceforge.jexcelapi:jxl:2.6.12'
}
Paste your jxl.jar into the libs folder
Right click it and select 'Add as library'
Make sure that compile files('libs/jxl.jar') is in your
build.gradle file (or compile fileTree(dir: 'libs', include: '*.jar')
if you are using many jar files) if it still not there then you can try to add it manually by adding this compile files('libs/jxl.jar') inside dependancies
Synch your project

How to add classpath in an Android Studio project

I have an Android project with an Android application that depends on a pure Java library (and the Java library uses some others compiled jars libraries). I added the dependencies, I can build the project, but at run time I have a ClassNotFoundException error.I had to add to theCLASSPATHenvironment variable the path to the jars.Is there a way to set the classpath locally for the project only, like using the command line option
java –classpath <path to the jars>
in the Android studio Run/Debug Configurations?
First off all, be sure there's a "libs" subfolder in the "app" folder of your project. If there's not, create one.
Next, in the app/build.gradle file, add this line of code:
dependencies {
...
compile fileTree(dir:'libs', include: ['*.jar'])
...
}
Place all of your .jar files in the "libs" folder, and voila, you're done
Thanks to Arnold Layne, I created a folder named libs.
Then, I went to
Files -> Project Structure (new menu opens) -> Modules (on the left) -> app -> Dependencies
There, I could add the library with the + Button.
This created this entry:
dependencies {
implementation files('libs/commons-lang3-3.7.jar')
}
Add this lines to build.gradle of app module.
dependencies {
...
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation files('libs/mysql-connector-java-8.0.16')
...
}

Java only project not adding dependecies on Android Studio

I am using Android Studio 0.8.2 and in my project I have one Android module and one Java only module.
The java only module depends on a external library. I have tried adding it in the libs dir of the project:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And using maven repositories:
repositories {
mavenCentral()
}
dependencies {
compile 'net.sf.kxml:kxml2:2.3.0+'
}
Both systems allows compilation but the library is not included on final jar. I have unzipped the jar and the classes are not there!
Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
A Gradle sync shows this warning message:
"A top-level `dependencies` block should only appear in build files that correspond to a module"
Any idea? Thanks advanced.
Looks like you are not declaring dependencies in build.gradle in app folder, but in the main roof of project? Am I right? You should compare declaring dependencies with other projects like hmm on github. Example: https://github.com/loopj/android-async-http/blob/master/sample/build.gradle (this is build.gradle file in module project, if you go up to root, in build.gradle file there is not declaring not connected to gradle depenncies). Read carefuly the comments and warnings.

Categories