最近我开始 mavenizing 我的 android 应用程序。我遇到的障碍之一是:在构建 maven 插件期间,找不到 res 目录中的布局中使用的可绘制对象。我首先使用 android quick start archetype 进行了 mavenizing:
mvn archetype:generate -DarchetypeArtifactId=android-quickstart -DarchetypeGroupId=de.akquinet.android.archetypes -DarchetypeVersion=1.0.8
然后我将所有资源复制到原型生成的 res 目录中。恕我直言,这应该足够了。但这是我在 mvn clean install 后得到的:
[INFO] --- android-maven-plugin:3.4.0:apk (default-apk) @missnanny-android-app --- [INFO] 将本地资产文件复制到组合资产目录。[信息] D:\Environments\AndroidSDK\android-sdk\platform-tools\aapt.exe [包,-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:错误:错误:找不到与给定名称匹配的资源(在 'src' 中,值为 ' @drawable/图像')。
我收到很多这样的错误。他们都说找不到某些 layout.xml 文件的资源。我在上面的日志中更改了项目和资源的名称。真名与 myproj 不同。但这不重要。在 mavenizing 期间,我只将资源复制到由原型生成的 res 目录中。在 res 文件夹中,我有:
res/drawable res/drawable-hdpi res/drawable-mdpi res/drawable-ldpi res/layout res/raw res/values res/values-pl
我想提一下,在 AndroidManifest.xml 中为应用程序图标加载 drawable 没有问题。所有问题都与 drawable.xml 中的布局和选择器有关
我的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>