Recently I started mavenizing my android application. One of the obstacles on my way is following: During build maven plugin cannot find drawables which are used in layouts in res directory. I've tarted mavenizing first by using android quick start archetype:
mvn archetype:generate -DarchetypeArtifactId=android-quickstart -DarchetypeGroupId=de.akquinet.android.archetypes -DarchetypeVersion=1.0.8
Then I've copied all my resources to the res directory generated by archetype. IMHO this should be sufficient. But here is what I get after mvn clean install:
[INFO] --- android-maven-plugin:3.4.0:apk (default-apk) @ missnanny-android-app --- [INFO] Copying local assets files to combined assets directory. [INFO] D:\Environments\AndroidSDK\android-sdk\platform-tools\aapt.exe [package, -f, -M, D:\Programming\myproj.com\myproj\myproj-android-app\MyprojManifest.xml, -S, D:\Programming\myproj.com\myproj\myproj-android-app\res, --auto-add-overlay, -A, D:\Programming\myproj.com\myproj\myproj-android-app\target\generated-sources\combined-assets\assets, -I, D:\Environments\AndroidSDK\android-sdk\platforms\android-7\android.jar, -F, D:\Programming\myproj.com\myproj\myproj-android-app\target\myproj-android-app-0.0.1-SNAPSHOT.ap_]
[INFO] D:\Programming\myproj.com\myproj\myproj-android-app\res\layout\layout_1.xml:8: error: Error: No resource found that matches the given name (at 'src' with value '@drawable/image').
I'm getting many such errors. All of them are saying that no resource can be found for some layout.xml file. I've changed name of project and resources in the log above. The real name is th different than myproj. but that shouldn't matter. During mavenizing i've only copied resources into res directory generated by archetype. in res folder I've :
res/drawable res/drawable-hdpi res/drawable-mdpi res/drawable-ldpi res/layout res/raw res/values res/values-pl
I'd like to mention that there is no problem loading drawable in AndroidManifest.xml for application icon. All problems are conneced with layout and selectors in drawable.xml
my pom:
<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>pl.comapny.groupid</groupId>
<artifactId>projectid</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>appname-android-app</artifactId>
<packaging>apk</packaging>
<name>appname-android-app</name>
<properties>
<platform.version> 2.1.2 </platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>pl.company.groupid</groupId>
<artifactId>artifact</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${project.basedir}/res</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<!-- <executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/res</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/templates/res</directory>
<targetPath>${project.basedir}/res</targetPath>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions> -->
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.4.0</version> <!--3.4.0, 3.1.1, 3.0.0-alpha-14-->
<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>7</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>
Ok, I've managed to solve my problem. This was really stupid. There were problems with some 9 patch images which are corrupted. This resulted in build failure. It seems that eclipse android plugin accepts drawables which are marked as 9 patch image, but in fact they are not, and build can be completed ... As for maven android plugin situation is different. But still imho error messages I was getting were inapropriate - there made me focused not on real problem. I've lost a lot of time.. and I'm sure I would find a solution much faster if there weren't those error messages saying that "no resource found that matches given name". Those errors should be skipped by plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With