How to add EasyPost Library to Android Studio Project - java

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

Related

Android Studio 3.X update and lost connection with AChartEngine (can't find symbol class ChartFactory)

I'm using AChartEngine in my project and connected it in build.gradle via
allprojects {
repositories {
jcenter()
maven {
url = "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
After update Android Studio and Gradle\Building mechanisms i can't build\make a project with set of similar errors like -
Error:(53, 24) error: cannot find symbol class ChartFactory
for every java class, where i do the "import org.achartengine.ChartFactory"
I have tryed add "compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'"
I have tryed Invalidate caches\Restart and Clean\Rebuild project,
i have changed syntax in tag maven and add symbol "=" after url.
It doesn't work still.
Gradle 3.X or 4.X do not see including of libs in way of:
maven {
url = "https://repository-achartengine.forge.cloudbees.com/snapshot/"
Please help me with that issue.
I have solved a problem. Thanks to #YaronRecher for hint about missing a real maven dependency on adress - https://repository-achartengine.forge.cloudbees.com/snapshot/
After every Studio \ Gradle Engine update your project do repeat its import from Maven repository. So if you're using AChartEngine and have updated Android Studio to 3.X your project wouldn't find anything on "https://repository-achartengine.forge.cloudbees.com/snapshot/"
Solution:
1) take JAR from https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip and put in folder "app/lib" in your project;
2) Add jar in Studio via "File-Project Scructure", after - menu Modules-app and dependencies (button "plus")
3) Delete real folder .gradle in project and after use Clean and Rebuild (in "Build" Menu)
4) Look your build.gladle file (Module:App) and make sure that you have:
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha2'
implementation files('libs/achartengine-1.2.0.jar')
}
and
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
testCompile 'junit:junit:4.12'
}
Enjoy!

Use provided/compileOnly dependency with Android libraries

For a project, I have this type of structure :
--- app => my Android application
|
\- lib => my Android library
The application use methods from the lib, but I want a build without embedding classes from the lib (since they are also available in a custom AOSP build), which could be done with provided/compileOnly directive for dependencies. The problem is that this directive doesn't work with aar librairies generated by the Android plugin, only with jars.
I found a way to build also jar files by using the custom makeJar task found here :
Build library jar with Gradle
Then in the build.gradle for the application, I can add a dependency like this :
dependencies {
compileOnly fileTree(dir: '../lib/build/outputs/jar', include: ['*.jar'])
...
}
This works fine, but only if the jar has already been generated by a previous build, which means I have to launch ./gradlew build two time to make it work.
I suppose the problem is that unlike regular dependencies (ie compileOnly project(':lib')), the fileTree dependency is evaluated without requesting a build of the sub project and on the first build, no jar file is added to the classpath.
I tried things like preBuild.dependsOn(':lib:makeJar') but without success because it's executed after evaluation.
I can't switch lib to Java plugin because it's Android specific code and I need to build aar for other projects, so is there a better way to use the compileOnly directive with this module ? Or maybe a way to force the lib to be built before the app build.gradle is evaluated ?
add this on your build.gradle(app)
compile fileTree(include: ['*.jar'], dir: 'libs')
or directly compile your jar file as following
compile files('libs/your_filename_in_libs_folder.jar')

Gradle does not include compile dependency using compile configuration

I have added a compile dependency to may android project. Gradle downloads the jar file from the server but it does not add it to class path. Here is what I have done so far. I have added dependency,
compile 'com.mallaudin.android:oxygeroid-annotations:1.0.0'
and checked the cached path of gradle
C:\Users\---\.gradle\caches\modules-2\files-2.1\com.mallaudin.android\oxygeroid-annotations\1.0.0\95cdbaf882c04d8cbb891143e83af3c3f0858947
and it was there. This dependency adds a #ViewFactory annotation which I am not getting currently.
I have added the same jar file in my app/libs folder and as compile fileTree(dir: 'libs', include: ['*.jar']) ensures, this will be added to my class path and it works this way.
What's wrong with first method. Jar is there, but still I can't refer
to any of the classes in jar.

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

How to add library to project in Android Studio 1.0.2?

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/

Categories

Resources