How to add library to project in Android Studio 1.0.2? - java

First, this is not duplicate. I have browsed answers to "How to add library to project in Android Studio" but found no answer. I cant find src and libs folder. I want to add volley jar to project. Screenshot attached:
http://i.stack.imgur.com/2SyUp.png

For preferred way read bellow this answer:
If you need to add a library to the Android Studio project navigate to your project folder with default path at:
\YourProjectName\app\libs
You can paste your *.jar library there. Make sure your build.gradle contain this directive at dependencies part:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
To see the library at the Android Studio, switch to the "Project" view at the menu:
Preffered way:
Preferred way to import libraries to your project is by gradle dependency system.
To do so, open your build.gradle file and locate the dependencies part. To import the library you mentioned, Volley, your dependencies part should look somehow like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.mcxiaoke.volley:library:1.0.10'
}
You don't need to import the *.jar library manually any more. Gradle dependencies system will take care of it.
To find gradle dependency you need, you might use tools like:
http://gradleplease.appspot.com/
http://search.maven.org/

Related

how can i download AppCompatActivity librery for ADT

I have a problem with importing the package :
"import android.support.v7.app.AppCompatActivity".. i think because i should
download AppCompatActivity librery before importing it
Please, how can i download AppCompatActivity librery??
[1]: https://i.stack.imgur.com/mMPQs.png
No need to download it separately.You can fix it updating your "build.gradle(Module:app)" file. in order to do it you need to add your compiler dependencies for project.
Add this line to "build.gradle(Module:app)" file
compile 'com.android.support:appcompat-v7:25.3.0'
then Sync your project and make sure network connection is working.That's it :)
bellow is an example that shows where you add a compiler dependency to your project.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espressocore:2.2.2',{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.0'
testCompile 'junit:junit:4.12'
}
To Setup Android Support Library :
The Android Support Repository package is provided as a supplemental download to the Android SDK and is available through the Android SDK Manager.
Follow the instructions below to obtain the Support Library files.
To download the Support Library through the SDK Manager:
1.Start the Android SDK Manager.
2.In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder and, if necessary, expand to show its contents.
3.Select the Android Support Repository item.
4.Click the Install packages... button.
Then After Downloading,
Adding Support Libraries
In order to use a Support Library, you must modify your application's project's classpath dependencies within your development environment. You must perform this procedure for each Support Library you want to use.
To add a Support Library to your application project:
Make sure you have downloaded the Android Support Repository using the SDK Manager.
Open the build.gradle file for your application.
Add the support library to the dependencies section. For example, to add the v4 core-utils library, add the following lines:
dependencies {
...
compile "com.android.support:support-core-utils:25.3.1"
}
Then you can use your Support Library elements.

How to add EasyPost Library to Android Studio Project

I have downloaded the library which is a folder containing several files from:
https://github.com/EasyPost/easypost-java/archive/master.zip
I have added my own folder named myLibs and added the unzipped project folder to it (folder named easypost-java-master).
My settings.gradle looks as follows:
include ':app'
include ':myLibs:easypost-java-master'
My build.gradle looks as follows:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile files('libs/gson-2.2.4.jar', 'libs/gson-2.2.4-javadoc.jar', 'libs/gson-2.2.4-javadoc.jar')
compile fileTree(dir: 'myLibs', include: ['easypost-java-master'])
}
I am getting no errors and able to sync. But when I try to import for example import com.easypost.EasyPost;at my MainActivity, I get the error
Cannot resolve easypost
Am I missing a step?
Am I missing a step?
Yes, the BIG one. On EasyPost library GitHub profile, there are installation instructions. Did you notice that:
Installation
mvn package or build the jar from src!
To do it, just follow these steps:
In the latest build of Android Studio 1.2, the creation of JAR library
has been made as simple as point and click.
Steps to follow :
Goto File -> New -> New Module
Select "Java Library" at the end of the options list
Enter the name of the jar lib and name of class in it and hit finish button
Thats it !
The next step is adding your Jar Library as dependency in your app.
Simple as that just
Goto File -> Project Structure -> Select 'app' -> Select 'Dependency'
Select the '+' at the bottom -> Select 'Module Dependency'
Select your jar lib module you just created above
Select Ok and thats it!
....Or you could just add the below line to your App gradle file
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) // Default Gradle Task, should be already present
compile 'com.android.support:appcompat-v7:21.0.3' // Default Gradle Task, should be already present
compile project(':nameOfYourJarLibraryModule') // This is your jar library module
}
Google is promoting the Android Archive(AAR), even though JAR
supported is brought back to android studio.To find out the difference
between AAR and JAR refer this link
From: Create an Android Jar library for distribution
Hope it help

How to use external Jars in javafxports-Application

i write a javafx andoid application in netbeans with javafxports and gradle. I added the dependencies to gradel, but now i dont know how to add the jars to my project or to use it in my app-code. . .
Do you know how i can us it? I tried searching the www for hours ...
Ok i tried it but i dont get it ...
I did exactly what you said but netbeans still says:
package io.netty.bootstrap does not exist
I created a folder unter src/android/ called libs and add my jar there ...
Here are my dependencies:
dependencies {
compile fileTree(dir: 'src/android/libs', include: ['*.jar'])
compile files('src/android/libs/netty-all-4.0.29.Final.jar')
}
FINAL SOLUTION:
You have to add: compile 'io.netty:netty-all:4.0.24.Final' to the build.gradle file. (Example for netty JAR-Libary)
I copy the Libary (netty) to an Folder called "libs" in my main Folder not in sry and so on. Create the folder if not exist
Write your code and you will see, import works.
Thank you to José Pereda for the time and the final solution!
Based on the edited question, these are a few suggestions for working with dependencies on a JavaFXPorts project.
Dependencies and build.gradle file
According to this, the default dependency configurations compile and runtime are supported, and the jfxmobile plugin adds extra configurations for each supported platform like androidCompile or desktopRuntime.
To access third party dependencies, from a given repository this should be added:
repositories {
jcenter()
}
dependencies {
compile 'groupId:artifactId:version'
}
Since jcenter() is a superset of 'mavenCentral()`, you can use any maven dependency that was in the form of:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
as compile 'groupId:artifactId:version'. So in this case:
dependencies {
compile 'org.glassfish:javax.json:1.0.4'
}
Local files
Accesing local jars can be done using files:
dependencies {
compile files('lib/my-jar.jar')
}
having my-jar.jar at a lib folder inside your project, but outside the src folder.
If you want to add several jars:
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
}
Gluon plugin for NetBeans
After any change in the build.gradle file, it is necessary to reload the project, so the new changes are taken into account, and the new dependencies are retrieved.
Under the Projects view, right click on the Project root and select Reload Project.
Check also the Dependencies folders, those should contain the jars included in the build.
Since there are several of these folders, you can see for instance that Compile for android includes android.jarand jfxdvk-8u60-b3.jar. Compile for main should contain all the jars defined for compile.
Samples
These are some projects where the build.gradle contains dependencies, so they are a good way to start with JavaFXPorts.
HelloPlatform and other samples.
2048FX
SMSTracker
HelloCharm

Gradle Warning "unspecified depends on libraries but is a jar " while compiling an android module within a custom java library module

I am a newbee in Gradle. I have a simple project structure (shown bellow) having a main android app module, one android module (myandroidlibrary), and one pure java module (myjavalibrary). They have simple dependencies, app -> myjavalibary, and myjavalibary -> myandroidlibrary (pls see fig. below). Gradle files snapshots are also given below.
However, while sync the gradle it produces following error:
D:\MyTestCodes\MyTestApplication\app\build.gradle
Warning:Module version MyTestApplication:myjavalibrary:unspecified depends on libraries but is a jar
Pls help me out! I have spent this whole day to sort it out with no result!
MyProject
- app
- myjavalibrary (pure java library)
- myandroidlibrary (android library)
Now the dependency is as follows:
"app" depends on -> "myjavalibrary"
"myjavalibrary" depends on -> "myandroidlibrary"
Gradle files for each of the modules are as follows:
build.gradle for app:
apply plugin: 'com.android.application'
android {
// ommitting other detail
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile project(':myjavalibrary')
}
build.gradle for myjavalibrary:
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':myandroidlibrary')
}
build.gradle for myandroidlibrary:
apply plugin: 'com.android.application'
android {
//ommiting other detail.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}
settings.gradle:
include ':app', ':myjavalibrary', ':myandroidlibrary'
Now while I sync the gradle files it shows the following error:
D:\MyTestCodes\MyTestApplication\app\build.gradle
Warning:Module version MyTestApplication:myjavalibrary:unspecified depends on libraries but is a jar
Warning is caused by pure-jave myjavalibrary module having a dependency on the myandroidlibrary one, which is an Android library.
Gradle warns you that a pure-java module doesn't know anything about Android specific stuff of myandroidlibrary (like Android resources, assets etc.). By having this dependency (pure-java to android library one) you might lose some stuff you expect to have.
A much cleaner dependency direction would be the one from a android library to a pure-java library. In this case Gradle won't give you any warnings.
If you want to create an Android app project from java code, use apply plugin: 'com.android.application'.
If you want to create a library project from java code, use apply plugin: 'com.android.library'.
If you want to use pre-built jar files, do not create any project for them. Just add them into the projects, into the libs folder, which depend on them. The compile fileTree(dir: 'libs', include: ['*.jar']) in the dependencies would take care of them.

Android Studio cannot find AAR packages

I am having a problem with Android Studio recognizing classes inside an #aar library imported locally.
So... I've made a library and exported is an aar file. Inside android studio I selected Import Module and them Import .JAR or .AAR Package.
The project compiles and works with the classes inside the aar file but Android studio can not find the classes or offer any auto completion of so all.
Here is a few of screenshots:
The same problem also happens with other #aar libraries imported the same way:
Any suggestions?
Edit:
build.gradle:
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':UpPlatformSdk')
compile project(':simpleorm')
... // more libraries here
}
settings.gradle:
include ':app', ':UpPlatformSdk', ':wear', ':simpleorm'
Looks like you could do this How to manually include external aar package using new Gradle Android Build System
If you have them in your lib folder
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'UpPlatformSdk', ext:'aar')
}
This may not be the quickest way, but this works for autocompletion and also solved my problem of missing classes when I tried compiling my local AAR using the method #puj described. Essentially you need to create a local Maven repository to host the AAR, but any changes you make are pulled by the build system when you do a Gradle sync.
Android Library AAR depending on another library

Categories

Resources