I trying include to project Cling, but before I never used manually install from maven.
On page instructions is:
Install Maven 3.2.3 or newer.
Install the Android SDK and set the ANDROID_HOME environment variable
to the SDK install directory.
Clone the Cling source:
git clone https://github.com/4thline/cling.git
Change into the cling/ directory.
Install everything into your local ~/.m2 Maven repository (this will
take a few minutes if all dependencies have to be downloaded for the
first time).
mvn clean install
If your build fails with Android/dex packaging errors, you forgot the clean.
Use Cling in your pom.xml with:
don't know why, but pom.xml not insert here
you can see pom.xml on github page
I have done 1,2,3,4 steps, but what is "Install everything" in step 5, how to do it ?
And last step with pom.xml, where need to put it?
Step 5 comes down to running the command mvn clean install from the command line.
Maven is configured with the help of a file, called the POM file. It is an XML file named pom.xml. This file contains everything that Maven will do during the build. One of those things is to compile the Java sources into a final artifact. To compile the source code, it needs to resolve its dependencies; that is, other libraries that Cling depends on. All of those required libraries are declared in this POM file.
Maven will automatically download every dependency of the project. It will store them (or install them in the Maven jargon) into a local repository. This repository is just a directory structure on your local drive that will contain every JAR and POM that Maven will have downloaded from the Internet (more precisely from remote repositories configured for the project).
Maven will only do that process once. When all the dependencies are installed in your local repository, it won't download them again (by default). That is why the very first build will be longer that the subsequent builds.
So, to go through step 5, you need to:
Open a command prompt
Go into the directory where you checked out Cling with the command git clone https://github.com/4thline/cling.git at step 3.
Go into the cling subdirectory.
There should be a pom.xml file here. This is the main entry point for Maven. Run the command mvn clean install from this location.
Step 6 targets the project you are building. When steps 1 to 5 are done, you have compiled and installed the latest version of Cling. Now is the time to use it then!
Well to use it, you need to create a Maven project (there are facilities for that with every major IDE like Eclipse or IntelliJ) and declare that your project will have a dependency on Cling. That declaration is done with this bit of XML in the POM file of your project.
<dependencies>
<dependency>
<groupId>org.fourthline.cling</groupId>
<artifactId>cling-core</artifactId>
<version>2.1.1-SNAPSHOT</version>
</dependency>
</dependencies>
I strongly suggest that you read the Maven book from Sonatype to get you acquainted with using Maven.
Related
I saw two method of adding external jar.
First is copying to libs folder and then adding manually in build.gradle.
compile files('libs/commons-net-3.1.jar')
Other is the graphical method: right click on app folder> import external .jar > then adding dependency........
I choose the first one but this gives me and error:
/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java - Dfile.encoding=UTF-8 -jar /Users/abhimanyuaryan/AndroidStudioProjects/UniSnap/app/libs/commons-net-3.1.jar
no main manifest attribute, in /Users/abhimanyuaryan/AndroidStudioProjects/UniSnap/app/libs/commons-net-3.1.jar
Process finished with exit code 1
Your problem is better solved by not including a local jar at all, but by a remote artifact.
Make sure your build.gradle has to following to load from maven central -
repositories {
mavenCentral()
}
and add the following to your dependencies block --
compile 'commons-net:commons-net:3.1'
Do a gradle sync after making these changes.
The format is 'group:name:version'. See the docs on dependencies for more info. To find libraries you are interested in, check their install docs for a maven or gradle artifact description, or you can search Maven Central.
Lastly, want to point out that 3.3, not 3.1, is not the most current version of Apache Commons Net.
Ok, so, I'm developing an app for the Amazon FireTV, so I have to use Eclipse.
I'm trying to use this socket.io Java client library: https://github.com/nkzawa/socket.io-client.java
at the bottom of this post, i included the installation instructions, which I'm not really sure how to make work with my existing Eclipse project (I'm new to maven). so from my understanding, do i just add a pom.xml file and a test folder? Then paste in their "maven central code" into the pom.xml? Will this cause any issues with the other code in my project? Or, can I just copy and paste all their SRC code into my project, since it's MIT licensed? I'd rather learn how to do this the proper way. The project is not in JAR format, so I was thinking maybe copying the folder structure into my project then using the Project Properties, Add Library option to connect to my code? Maybe?
Their installation instructions, (available in their readme.md):
The latest artifact is available on Maven Central. Add the following dependency to your pom.xml.
<dependencies>
<dependency>
<groupId>com.github.nkzawa</groupId>
<artifactId>socket.io-client</artifactId>
<version>0.3.0</version>
</dependency>
</dependencies>
Or to install it manually, please refer dependencies to pom.xml.
Add it as a gradle dependency for Android Studio, in build.gradle:
compile 'com.github.nkzawa:socket.io-client:0.3.0'
So, I learned that Maven Central has JAR files available for download. That way, you can just include them in your project via the Project Properties dependencies options. Without having to learn Maven.
You need to first understand how Maven works (and what pom.xml stands for). Maven is a tool that helps you automatically install dependencies (files need) for a given project. E.g if a project needs to process json files, it will need to "import" a json library which will then be a dependency for that project. When you add the dependency file above to your project, and run Maven install, it goes and fetches all the dependencies for your socket.io-client to work.
Unfortunately, Maven does work very well in building android application projects and can be fairly complex to setup correctly (from my limited experience). I would advise that you manually download the jar dependencies and then add them to your android classpath if you are not keen on investing a lot of time learning to use Maven.
To manually install the files .. you can create a default maven project (http://www.tech-recipes.com/rx/39279/create-a-new-maven-project-in-eclipse/) in eclipse, add the dependency file above to your pom.xml and run Maven-install. This will download the dependencies you need to your Maven local repository. You can then copy them from there to your android project.
Regarding installing the socket.io client you can find more on these steps here
http://denvycom.com/blog/socket-io-java-android-without-maven/
I am trying to use RobolectricSample application for unit testing Android application.
In the instruction for installation of application with Maven the first step is
ant maven-setup. I could not understand why is this command required and what it will do?
Any explanation will be great help.
According to the Ant build file build.xml, ant maven-setup does two things:
maven-install-jars:
Install 2 required jar libraries (guice-2.0-no_aop.jar & maps.jar) into Maven local repository.
maven-set-android-sdk:
Reset Android SDK path in pom.xml iff <path> is defined in android-maven-plugin.
This is not a elegant solution, ideally all those tasks should be handled purely by Maven. However, as this project provide both Ant and Maven build, it reuse the script from Ant in Maven build lifecycle for convenience.
I am using merge list in my android project and up until now I have just been shoving the source into my src root with the rest of my code. However I'm not modifying anything so I figured it was time to include this stuff as libraries. I clone the first repo and:
$ ant
Buildfile: /Users/user/dev/projects/cwac-sacklist/build.xml
BUILD FAILED
/Users/user/dev/projects/cwac-sacklist/build.xml:49: taskdef class com.android.ant.SetupTask cannot be found
using the classloader AntClassLoader[]
Total time: 0 seconds
It looks like this ant script is looking for some stuff created by the "android" tool.. but I don't see any docs.. but I see the missing prop sdk.dir.. so I create that in local.properties.. but then I get:
/Users/user/dev/libs/android-sdk-mac_x86/tools/ant/lib_rules.xml:126: Reference android.libraries.src not found.
What is the right way to go about packaging this stuff so I can shove it in my local maven repo? Or better yet, where can I find it pre-packaged or in an existing maven repo?
UPDATE - 2014-07-08
It looks like commonsware now has all this stuff in a proper repo:
from: https://github.com/commonsguy/cwac-sacklist
repositories {
maven {
url "https://repo.commonsware.com.s3.amazonaws.com"
}
}
dependencies {
compile 'com.commonsware.cwac:sacklist:1.0.0'
}
Your first error is a standard one, caused by a discrepancy between the build files in the repo and your version of the build tools. Simply run:
android update project -p ...
where ... is the path to the project in question, to update the build files.
Your second error is solved by adding the following lines to build.xml, just after the <setup/> tag:
<path id="android.libraries.src"><path refid="project.libraries.src" /></path>
<path id="android.libraries.jars"><path refid="project.libraries.jars" /></path>
You will see those lines in the MergeAdapter edition of build.xml, though they apparently are not in the SackOfViewsAdapter build.xml file, as I have not touched that project in some time.
Or better yet, where can I find it pre-packaged or in an existing maven repo?
If there is one, it's unofficial, as I am not a Maven user.
I have an Android Project where I need to build multiple versions of the same application from the same sources.
To do this, I use the android plugin for Maven
Each version must be able to include ads from admob. So in my POM I added this dependancy
<dependency>
<groupId>com.admob.android</groupId>
<artifactId>ads</artifactId>
<version>20101109-ANDROID-3312276cc1406347</version>
<scope>system</scope>
<systemPath>THE_PATH\libs\admob-sdk-android.jar</systemPath>
</dependency>
I don't get any errors at build time but, when I execute the application I get this exception
java.lang.ClassNotFoundException: com.admob.android.ads.AdView
So apparently the package is not properly included ?
You can NOT use system scope for runtime required libraries. Deploy the jar into your local repository or your repository server (using e.g. mvn install:installFile ..) and remove scope and systemPath from the dependency declaration.
Update: As of the latest releases my Maven Android SDK Deployer can do the install of the AdMob jar from the SDK into your local Maven repository or repository server for you.
To use the Maven Android SDK Deployer, do the following:
Clone the repo:
git clone https://github.com/mosabua/maven-android-sdk-deployer.git
Go to your SDK Manager and install all APIs (this may take a while if you haven't done it yet)
Make sure you have the correct environment variable set for ANDROID_HOME. For Windows this might be:
set ANDROID_HOME=c:/android-sdk-windows
Run the installer:
c:\Tools\maven-android-sdk-deployer>mvn install
After you have done this you can just use all the android dependencies from your pom.xml, e.g.
<dependency>
<groupId>com.google.android.admob</groupId>
<artifactId>admob</artifactId>
<version>6.4.1-r11</version>
</dependency>
(There's a whole list on the github page)