本文介绍了Android的行家,插件和资源滤波的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手的行家,并试图将其配置为与Android,Maven的插件建立我的Andr​​oid项目。我在其中包含不同的应用程序设置的资产目录中的application.properties文件。我想从我的聚甲醛获得此值。在属性文件中我定义一个属性为

  myFilteredProperty = $ {helloFromPOM}
 

和还定义在POM相同的属性:

 <性状>
        < helloFromPOM>我的财产与LT; / helloFromPOM>
    < /性状>
 

开机运行过滤资产目录

 <建立>
    ...
    <资源>
        <资源>
            <目录> $ {project.basedir} /资产< /目录>
            <过滤>真< /过滤>
        < /资源>
    < /资源>
    ...
< /编译>
 

和配置的recources插件如样本了解android- Maven的插件

 <插件>
            < artifactId的> Maven的资源,插件和LT; / artifactId的>
            <执行>
                <执行>
                    <阶段>初始化< /阶段>
                    <目标>
                        <目标>资源< /目标>
                    < /目标>
                < /执行>
            < /执行>
        < /插件>
 

但是,当我试图表现出吐司在我的应用程序具有这种性质,我看到$ {helloFromPOM}而不是我的财产。

在该所产生的行家我看到这个属性文件中的两个地方我的目标目录:

  • /target/generated-sources/combined-assets/assets/application.properties
  • /target/myapp-0.0.1-SNAPSHOT.apk\application.properties

首先是错误的,它包含$ {helloFromPOM}而不是我的财产。其次,apk文件里面是正确的。但是,当我在设备上安装这个APK它告诉我错了价值$ {helloFromPOM}。

我做了什么错了?

修改

感谢您的回答,我trye​​d它,但得到这个错误:

当我评论<$c$c><resourceDirectory>${project.build.directory}/filtered-assets</resourceDirectory>在聚甲醛,建设完成全成,但它不使用过滤租入资产价值。

此外,我试图执行这个 CMD.EXE / X / C,C:\ Program Files文件\机器人\ Android的SDK \平台工具\ aapt.exe包-m -JD: \项目\ MyApp的\目标\产生-源\ r-MD:\项目\ MyApp的\ AndroidManifest.xml中-SD:\项目\ MyApp的\目标\滤资产--auto-附加覆盖-AD:\项目\ MyApp的\资产-IC:\ Program Files文件\机器人\ Android的SDK \平台\ Android为8 \的android.jar在我的命令行,并得到这个错误:无效的资源目录名称:D:\项目\ MyApp的\目标\滤资产/ application.properties 。错误的斜杠,而不是反斜杠后滤资产。更改<$c$c><resourceDirectory>${project.build.directory}/filtered-assets</resourceDirectory>至<$c$c><resourceDirectory>${project.build.directory}\filtered-assets</resourceDirectory>也于事无补。

P.S。我的插件部分看起来像这样

 &LT;插件&GT;
        &LT; artifactId的&GT; Maven的资源,插件和LT; / artifactId的&GT;
        &LT;执行&GT;
            &LT;执行&GT;
                &LT;阶段&gt;初始化&LT; /阶段&gt;
                &LT;目标&GT;
                    &LT;目标&GT;资源&LT; /目标&GT;
                &LT; /目标&GT;
            &LT; /执行&GT;
        &LT; /执行&GT;
    &LT; /插件&GT;
    &LT;插件&GT;
        &LT;的groupId&GT; org.apache.maven.plugins&LT; /的groupId&GT;
        &LT; artifactId的&GT; Maven的编译器插件&LT; / artifactId的&GT;
        &lt;结构&GT;
            &lt;信源&GT; 1.6&LT; /源&GT;
            &lt;目标&GT; 1.6&LT; /目标和GT;
        &LT; /结构&gt;
    &LT; /插件&GT;
    &LT;插件&GT;
        &LT;的groupId&GT; com.jayway.maven.plugins.android.generation2&LT; /的groupId&GT;
        &LT; artifactId的&GT; Android的行家,插件和LT; / artifactId的&GT;
        &LT;版&GT; 3.2.0&LT; /版本&GT;
        &lt;结构&GT;
            &LT; SDK&GT;
                &LT;平台&GT; 8示/平台&GT;
            &LT; / SDK&GT;
            &LT;仿真器&GT;
                &LT; AVD&GT; 2.3.3_API-10&LT; / AVD&GT;
            &LT; /仿真器&GT;
            &LT; undeployBeforeDeploy&GT;真&LT; / undeployBeforeDeploy&GT;
            &LT; resourceDirectory&GT; $ {project.build.directory} /过滤,资产和LT; / resourceDirectory&GT;
        &LT; /结构&gt;
        &LT;扩展&GT;真&LT; /扩展&GT;
    &LT; /插件&GT;
 

解决方案

现在它的作品,我改变<$c$c><resourceDirectory>${project.build.directory}/filtered-assets</resourceDirectory>至<$c$c><assetsDirectory>${project.build.directory}/filtered-assets</assetsDirectory>.结果POM:

 &LT;性状&gt;
    &LT; myProperty的&gt;我的财产!!!! 111 LT; /&myProperty的GT;
&LT; /性状&gt;

    &LT;资源&GT;
        &LT;资源&GT;
            &LT;目录&GT; $ {project.basedir} /资产&LT; /目录&GT;
            &LT;过滤&GT;真&LT; /过滤&GT;
            &LT; TARGETPATH​​&GT; $ {project.build.directory} /过滤,资产和LT; / TARGETPATH​​&GT;
            &其中包括(includes)GT;
                &LT;包括&GT; ** / *属性和LT; /包括&GT;
            &LT; /包括&GT;
        &LT; /资源&GT;
    &LT; /资源&GT;

    &LT;插件&GT;
        &LT;插件&GT;
            &LT; artifactId的&GT; Maven的资源,插件和LT; / artifactId的&GT;
            &LT;执行&GT;
                &LT;执行&GT;
                    &LT;阶段&gt;初始化&LT; /阶段&gt;
                    &LT;目标&GT;
                        &LT;目标&GT;资源&LT; /目标&GT;
                    &LT; /目标&GT;
                &LT; /执行&GT;
            &LT; /执行&GT;
        &LT; /插件&GT;
        &LT;插件&GT;
            &LT;的groupId&GT; org.apache.maven.plugins&LT; /的groupId&GT;
            &LT; artifactId的&GT; Maven的编译器插件&LT; / artifactId的&GT;
            &lt;结构&GT;
                &lt;信源&GT; 1.6&LT; /源&GT;
                &lt;目标&GT; 1.6&LT; /目标和GT;
            &LT; /结构&gt;
        &LT; /插件&GT;
        &LT;插件&GT;
            &LT;的groupId&GT; com.jayway.maven.plugins.android.generation2&LT; /的groupId&GT;
            &LT; artifactId的&GT; Android的行家,插件和LT; / artifactId的&GT;
            &LT;版&GT; 3.2.0&LT; /版本&GT;
            &lt;结构&GT;
                &LT; SDK&GT;
                    &LT;平台&GT; 8示/平台&GT;
                &LT; / SDK&GT;
                &LT;仿真器&GT;
                    &LT; AVD&GT; 2.3.3_API-10&LT; / AVD&GT;
                &LT; /仿真器&GT;
                &LT; undeployBeforeDeploy&GT;真&LT; / undeployBeforeDeploy&GT;
                &LT; assetsDirectory&GT; $ {project.build.directory} /过滤,资产和LT; / assetsDirectory&GT;
            &LT; /结构&gt;
            &LT;扩展&GT;真&LT; /扩展&GT;
        &LT; /插件&GT;
 

I'm newbie in maven and trying to configure it to build my android project with android-maven-plugin.I have an application.properties file in assets directory which contains different application settings. And i want to obtain this values from my pom. In properties file i define one property as

myFilteredProperty=${helloFromPOM}

and also define the same property in POM:

    <properties>
        <helloFromPOM>MY PROPERTY</helloFromPOM>
    </properties>

Switched on filtering on assets dir

<build>
    ...
    <resources>
        <resource>
            <directory>${project.basedir}/assets</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    ...
</build>

And configure recources plugin as in samples for android-maven-plugin

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

But when i'm trying to show Toast in my application with this property i see ${helloFromPOM} instead MY PROPERTY.

In my target directory which generated by maven i see this properties file in two places:

  • /target/generated-sources/combined-assets/assets/application.properties
  • /target/myapp-0.0.1-SNAPSHOT.apk\application.properties

First is wrong, it contains ${helloFromPOM} instead MY PROPERTY. Second, inside the apk file is correct. But when i install this apk on the device it show me wrong value ${helloFromPOM}.

What did i do wrong?

EDIT

Thanks for answer, I tryed it, but get this error:

When i comment <resourceDirectory>${project.build.directory}/filtered-assets</resourceDirectory> in POM, build finishing successfull, but it doesn't use filtered assests.

Also i try to execute this cmd.exe /X /C ""C:\Program Files\Android\android-sdk\platform-tools\aapt.exe" package -m -J D:\projects\myapp\target\generated-sources\r -M D:\projects\myapp\AndroidManifest.xml -S D:\projects\myapp\target\filtered-assets --auto-add-overlay -A D:\projects\myapp\assets -I "C:\Program Files\Android\android-sdk\platforms\android-8\android.jar"" in my command line and get this error: invalid resource directory name: D:\projects\myapp\target\filtered-assets/application.properties. Wrong slash instead back-slash after filtered-assets. Changing <resourceDirectory>${project.build.directory}/filtered-assets</resourceDirectory> to <resourceDirectory>${project.build.directory}\filtered-assets</resourceDirectory> also doesn't help.

P.S. my plugins section looks like this

   <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
            <execution>
                <phase>initialize</phase>
                <goals>
                    <goal>resources</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <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.2.0</version>
        <configuration>
            <sdk>
                <platform>8</platform>
            </sdk>
            <emulator>
                <avd>2.3.3_API-10</avd>
            </emulator>
            <undeployBeforeDeploy>true</undeployBeforeDeploy>
            <resourceDirectory>${project.build.directory}/filtered-assets</resourceDirectory>
        </configuration>
        <extensions>true</extensions>
    </plugin>
解决方案

Now it works, i change <resourceDirectory>${project.build.directory}/filtered-assets</resourceDirectory> to <assetsDirectory>${project.build.directory}/filtered-assets</assetsDirectory>. Results POM:

<properties>
    <myProperty>MY PROPERTY!!!!111</myProperty>
</properties>

    <resources>
        <resource>
            <directory>${project.basedir}/assets</directory>
            <filtering>true</filtering>
            <targetPath>${project.build.directory}/filtered-assets</targetPath>
            <includes>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <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.2.0</version>
            <configuration>
                <sdk>
                    <platform>8</platform>
                </sdk>
                <emulator>
                    <avd>2.3.3_API-10</avd>
                </emulator>
                <undeployBeforeDeploy>true</undeployBeforeDeploy>
                <assetsDirectory>${project.build.directory}/filtered-assets</assetsDirectory>
            </configuration>
            <extensions>true</extensions>
        </plugin>

这篇关于Android的行家,插件和资源滤波的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 03:40
查看更多