Android AdMob and Maven - android

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)

Related

Installing Sevntu in Android Studio

I am wondering how I can install Sevntu on Android Studio without using the JAR. I've added the maven url and everything works when I point to the local JAR file during the third-party configuration for Checkstyle, but is there a way to not use the JAR?
Thank you!
Unfortunately not. At the time of this writing (early 2019), you must use the JAR.
The Checkstyle plugin does not currently support build tool integration, and that is a feature that is also not on the roadmap at the moment (#107).
Since you are using maven, just include the sevntu maven plugin as a dependency with checkstyle.
Example: https://github.com/checkstyle/checkstyle/blob/c0e131dbc43a17537498432b14cc7e7743ecf407/pom.xml#L547-L551
<dependency>
<groupId>com.github.sevntu-checkstyle</groupId>
<artifactId>sevntu-checkstyle-maven-plugin</artifactId>
<version>1.32.0</version>
</dependency>

Cling how to install from github?

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.

integrating maven dependency into android Eclipse project, no JAR file

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/

How to use new Admob with ANT

I'm tryng to setup the new AdMob SDK using instructions on this Google site for ANT (not gradle).
This answer talks about the same problem, but it was asked before google decided to do awat with .jars distribution for Admob and included it in google play services.
I am baffled that the official site does not even talks about ANT configuration at all.
Is there a way to set it up, or do I have to give up and use gradle instead ?
If you use Ant you are pretty much on your own.
You will need to :
Unpack the Google Play Services AAR
Add each of the embedded jars onto your build classpath
Add each of the embedded jars onto your DEX path
Or you can use Maven or Gradle.
If you are using Maven (my choice) then just add the following dependency to your project. NB you will want to include the android-maven-plugin in your POM too.
https://github.com/simpligility/android-maven-plugin
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>play-services</artifactId>
<version>${play-services.verson}</version>
</dependency>

Maven could not find Android 4.2 dependency

I am building my android app with Maven (ok... trying to build), after several errors I got to this one :
[ERROR] Failed to execute goal on project AndroidPro: Could not resolve dependencies for project com.kowalsk.android.recipe:AndroidPro:apk:1.0.0-SNAPSHOT: Could not find artifact com.google.android:android:jar:4.0.3 in central (http://repo.maven.apache.org/maven2) -> [Help 1]
I used maven-android-sdk-deployer and downloaded all needed libraries, but it haven't solved the problem.
When using maven-android-sdk-deployer : the stub for android libraries will be installed in your local maven repo with the groupId android (i.e. not com.google.android)
The groupId com.google.android is the official groupId used by google to publish some versions of android API. I don't know why only few versions are available (probably because maven wasn't the build tool choose by google for the android platform). We can hope that in a near future (mainly because google choose gradle as new build tool): all versions will be available with the groupId com.google.android in central repo.
In my local repo, the stubs installed with maven-android-sdk-deployer have also a special version number with _rX appended. So to use the 4.0.3 I have the following dependency :
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.0.3_r3</version>
<scope>provided</scope>
</dependency>
See the link Maven Android Jar, maven repository does not have the version you mentioned in your pom 4.0.3
use any version mentioned in the link.

Categories

Resources