I tried different goals. mvn package results in package R does not exist, mvn android:generate-sources results in BUILD SUCCESS but no R.java will be created.
I would like to pack my classes into a jar container (not apk) because I would like to use it as a library in other projects.
AndroidManifest.xml: (minimal setup, because there are no Activities)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
</manifest>
default.properties:
android.library=true
target=android-8
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mylib</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.4.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
The only resource is ./res/layout/example.xml.
android-maven-plugin has no capability to generate a fully functional jar (contains all compiled class file, resources, manifest and etc) from Android library project.
The solution given by android-maven-plugin is apklib, which is simply a zip of the library project (has same directory structure contains raw java file, resource, manifest and etc). I have explained a bit more about how apklib works in this answer, for some sample projects, check out maven-android-plugin-samples/libraryprojects.
The furthest android-maven-plugin can go is a jar that contains only compiled class file, no resource, this is covered by the default <packaging>apklib<packaging> build life cycle and generated along with the .apklib file.
Related
When I try compile a android project generated with this command:
mvn archetype:generate \
-DarchetypeArtifactId=android-quickstart \
-DarchetypeGroupId=de.akquinet.android.archetypes \
-DarchetypeVersion=1.0.11 \
-DgroupId=com.kleber \
-DartifactId=app2
which generates a project with this structure:
app2
-assets
-res
...
-layout
-menu
-values
...
-src
-main
-java
-com
-kleber
HelloAndroidActivity.java
AndroidManifest.xml
default.properties
pom.xml
I got this error:
[ERROR] Found files or folders in non-standard locations in the project!
[ERROR] ....This might be a side-effect of a migration to Android Maven Plugin 4+.
[ERROR] ....Please observe the warnings for specific files and folders above.
[ERROR] ....Ideally you should restructure your project.
[ERROR] ....Alternatively add explicit configuration overrides for files or folders.
[ERROR] ....Finally you could set failOnNonStandardStructure to false, potentially resulting in other failures.
I have this pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.kleber</groupId>
<artifactId>app2</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<name>app2</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version>4.1.1.4</platform.version>
<android.plugin.version>4.1.1</android.plugin.version>
<android.sdk.path>C:\Users\00940831503\AppData\Local\Android\Sdk</android.sdk.path>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<!--<groupId>com.jayway.maven.plugins.android.generation2</groupId>-->
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>29</platform>
</sdk>
</configuration>
</plugin>
<!--<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>29</platform>
</sdk>
</configuration>
</plugin>-->
</plugins>
</build>
</project>
What the correct project structure to compile the project without errors? Is there a maven archetype which generate the project with the correct structure already?
The Android Maven plugin expects AndroidManifest.xml in src/main rather than in the root.
Option 1: Move AndroidManifest.xml to the location in which the plugin expects it, though this may have side effects in the IDE you’re using (Eclipse seems to fine with it, as far as I can tell).
Option 2: Tell the plugin where to look for the file by adding the following to the POM, at projects/build/plugins/plugin/configuration:
<androidManifestFile>
${project.basedir}/AndroidManifest.xml
</androidManifestFile>
The same applies to resources if your project has them anywhere other than src/main/res (old projects originally built for the Eclipse/ant toolchain have them under res). The property for these is resourceDirectory.
I have started since 2 days learning Maven & using goals as deploy and install.So I hv used this command:
mvn install android:deploy
Note:clean,install commands work fine
this is what I get:
[ERROR] No plugin found for prefix 'android' in the current project
and in the plugin groups [com.cryptolog.maven.plugins,
org.apache.maven.plugins, org.codehaus.mojo] available from the
repositories [local (/home/yougostt/.m2/repository), central
and this is the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>univer.lib.androidtestxmlrpc</groupId>
<artifactId>android_xmlrpc</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.cryptolog.rpc</groupId>
<artifactId>libxmlrpc</artifactId>
<version>${rpc.version}</version>
</dependency>
<dependency>
<groupId>com.cryptolog.rpc</groupId>
<artifactId>libxmlrpc-client</artifactId>
<version>${rpc.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<rpc.version>3.7</rpc.version>
</properties>
</project>
How can I fix it please?
Supposing you are using the com.simpligilty.maven.plugins Android Maven Plugin (but the same would also work for any other plugin), you can add to your pom the following (as also explained by its official usage page:
<build>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.4.1</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
If instead you are using the Jayway Androind Maven Plugin, the configuration would look like (as also explained by the official Spring guide:
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.9.0-rc.1</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
I am trying to create an Android base project using android-quickstart archetype, and adding RoboGuice, ActionBarSherlock dependencies, plus RoboGuice-Sherlock to combine the two.
This is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>BaseApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<name>BaseApp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version> 4.1.1.4
</platform.version>
<android.plugin.version>3.6.0</android.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.roboguice</groupId>
<artifactId>roboguice</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.4.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.github.rtyley</groupId>
<artifactId>roboguice-sherlock</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>16</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
But m2eclipse wont work with this Pom.xml, as it is unable to find the apklib dependency.
Speficically I am getting the following message under "Problems" tab in Eclipse:
dependency=[com.actionbarsherlock:actionbarsherlock:apklib:4.4.0:compile] not found in workspace pom.xml /BaseApp line 1 me.gladwell.eclipse.m2e.android.markers.dependency.apklib
I have tried removing the <type>apklib</type> line but then my ABS resources (namely the required Themes) are not imported into the project.
I've read in several questions that the apklib type only works on command line, and that if I want to stick to the IDE I need to import ABS manually as a library. I did, but then RoboGuice crashes because the project becomes a library project and, apparently, resource ids are not final anymore in library projects. (The compile-time error I get is "The value for annotation attribute InjectView.value must be a constant expression"). For reference, this is my only Activity:
public class HelloAndroidActivity extends RoboSherlockActivity {
#InjectView(R.id.helloworld) TextView textView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView.setText("Roboguice says Hello World");
}
}
IS there any proper way to create a base project with these three elements using maven and Eclipse?
Turns out I accidentally clicked the "Is Library" checkbox on Project Properties. Now it works with ABS manually imported as a library.
It is a pity though not being able to use Maven directly :(
I am working on a small project to allow cookies to persist. I want to make the project as a JAR so other developers can use it in there project. At the moment I am able to build the project as an APKLIB however this seems unnecessary as the resources are not needed. If I change the packaging to JAR I get the follow error when building
Results :
Tests in error:
shouldAddCookie(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
shouldClearAllCookies(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
shouldClearExpired(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
The POM looks like this
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.doward</groupId>
<artifactId>persistantcookiestore</artifactId>
<version>1</version>
<packaging>jar</packaging>
<name>persistantcookies</name>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.2.2_r2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<sdk>
<platform>17</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
If you want to just build a JAR file from .class files and no resources e.g. no XML files releating to layouts, values, colours etc then you can do so from the command line:
jar -cvf <filenameorjar.jar> <files to be included>
Example:
jar -cvf cookiepersist.jar com/*
This will create a jar file in the present working directory and include all the .class files from the directory com in the present working directory.
If you have a andorid project and you wish to use the same in another project you can make the project as a library project and refer the same in another Android project. This can include your resources also.
http://developer.android.com/tools/projects/projects-eclipse.html
You export your utility classes that do not refer to resources in android ie pure java classes. If you use eclipse you can have a look at the tutorial below
http://androiddevelopement.blogspot.in/2011/01/creating-jar-file-in-eclipse.html
Just moving my Android project over to Maven / Jenkins and am exploring the build / compile / testing procedures.
Issue:
I introduced a simple compilation error in the java code, but when i run mvn clean install package I get a build success. It's only when I deploy the App to my device that it crashes and fails.
Is there something wrong with my POM?
ps. I have XXXXX'd out some info. Don't worry about it.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>xxxxx</groupId>
<artifactId>xxxxxx</artifactId>
<version>1.0.0</version>
</parent>
<groupId>xxxxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging>
<name>Android App</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.0.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId>
<version>4.0.0</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<platform>15</platform>
<path>/Users/aidenfry/android-sdks</path>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I suspect, that the reason you're not seeing an error is most likely because maven didn't even bother compiling your classes in the first place.
Maven has various conventions, and one of them is that it expects your sourcecode to be located under src/main/java.
I'm betting that you've just dropped the above pom.xml into your project root area and run mvn clean install. Maven will happily run that, but since you've probably left your source files in the default IDE locations, maven just skips over it. Have a look in your target directory and you'll see it hasn't compiled any classes in there for you
You have 2 options:
Add this somewhere inside the <build> tags in the above pom :
${basedir}/src
Re-arrange your source files so they follow the src/main/java structure.
Personally, I'd opt for number 2.
P.S, there is also src/main/test too, test classes should go there :)
You can read more about the configuration of the pom file here