android-maven-plugin and resource filtering

前端 未结 3 1247
失恋的感觉
失恋的感觉 2021-01-06 08:46

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 contai

相关标签:
3条回答
  • 2021-01-06 09:16

    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>
    
    0 讨论(0)
  • 2021-01-06 09:27

    If you are specifying the property in your pom you shouldn't have it declared in a separate file as well. Conversely, if you want to specify it in a separate file you shouldn't declare it in your POM.

    However, I am not sure exactly what you are trying to do - maven properties are only valid within your pom file and are for use during the build process. You can't access them from within your application. Android/java have no idea they exist and can't see them, so the reason you see the ${helloFromPOM} in your code instead of MY PROPERTY is that android/java is just displaying the text - it doesn't know that it stands for a property and it has no way to parse it into a variable or other value.

    0 讨论(0)
  • 2021-01-06 09:29

    Sometimes it's caused by an inappropriate platform version. Try to set it right in your pom file. Look for smthg like

    <sdk>
        <platform>17</platform>
    </sdk>
    
    0 讨论(0)
提交回复
热议问题