Android-Maven-Plugin v3.4.0 cannot find drawable resources when building app
Asked Answered
H

1

7

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>

Hobnail answered 6/11, 2012 at 9:40 Comment(0)
H
10

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.

Hobnail answered 6/11, 2012 at 11:16 Comment(8)
So what was the solution to the problem? Still unclear how you fixed it.Attrahent
Ideally you would provide a pull request that improves the error message.Cataphoresis
But it seems like the only solution is to fix the images .... there's no way to get around it like how the Eclipse plugin handles it?Attrahent
Yes I think so - the only solution is to fix images - and in fact this good, why would You keep broken images in your resources ? - there is no reason for that. The problem is that error message from plugin is not saying what it should.Hobnail
I know in the long run I want to fix the images ... the problem is it's blocking my company to switching to Android Maven, the interim while we fix the images we would like to use Android Maven, but it looks like we have to have everyone fix the images before switching over unlike how we can use Eclipse or IntelliJ to compile and run the project.Attrahent
The error message is most like produced by the Android SDK tool that the Android Maven Plugin invokes so we can not easily make the error message better.Cataphoresis
+1 Same issue for me. Fixing 9 patch images fixed the problemHanoi
I have got similar problem , no resource found in apklib. But generating apklib was fine. When used that apklib in a different projects as a dependency then I got the same issue of no resource found. Could this be same nine patch issue~? The project builds with Ant , no issues!Flinn

© 2022 - 2024 — McMap. All rights reserved.