I want to sign an android .apk, I've got the following profile setup in my pom.xml

<profiles>
        <profile><!-- release profile. uses keystore defined in keystore.* properties. signs and zipaligns the app to the target folder-->
            <id>release</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <defaultGoal>install</defaultGoal>
                <finalName>${project.artifactId}-${project.version}</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jarsigner-plugin</artifactId>
                        <version>1.2</version>
                        <executions>
                            <execution>
                                <id>signing</id>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <phase>package</phase>
                                <inherited>true</inherited>
                                <configuration>
                                    <includes>
                                        <include>
                                            ${project.build.directory}/target/${project.artifactId}-${project.version}.apk
                                        </include>
                                    </includes>
                                    <keystore>my-release-key.keystore</keystore>
                                    <storepass>mypasshere</storepass>
                                    <keypass>mypasshere</keypass>
                                    <alias>mykeystore</alias>
                                    <verbose>true</verbose>
                                    <!--<destDir>gen</destDir>-->
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>maven-android-plugin</artifactId>
                        <configuration>
                            <zipalign>
                                <verbose>true</verbose>
                                <skip>false</skip>
                                <!-- defaults to true -->
                                <inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk</inputApk>
                                <outputApk>${project.build.directory}/MyApp_v${project.version}.apk</outputApk>
                            </zipalign>
                            <sign>
                                <debug>false</debug>
                            </sign>
                        </configuration>
                        <executions>
                            <execution>
                                <id>zipalign</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>zipalign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

I used the Novoda tutorial for the above (another similar example here which I've tried too, but same effect), and am executing mvn clean install -Prelease, however I get the following error :

[INFO] jarsigner: attempt to rename C:\android-projects\jameselsey_andsam_branch_mavenbranch\target\LanguageSelection-1.0.0-SNAPSHOT.jar to C:\android-projects\jameselsey_ands
am_branch_mavenbranch\target\LanguageSelection-1.0.0-SNAPSHOT.jar.orig failed
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed executing 'cmd.exe /X /C "C:\development\tools\Java\jdk1.6.0_20\jre\..\bin\jarsigner.exe -verbose -keystore my-release-key.keystore -storepass '*****' -keypass '
*****' C:\android-projects\jameselsey_andsam_branch_mavenbranch\target\LanguageSelection-1.0.0-SNAPSHOT.jar mykeystore"' - exitcode 1
[INFO] ------------------------------------------------------------------------

From what I can gather, the renaming is failing because that particular file is still in use during the packaging phase, so its essentially locked.

How can I correct this? I'm not entirely sure why a .jar is being signed, should it not just be the final .apk that gets signed?

I've tried to add a <destDir> (as suggested by a previous SO post) to move the artefacts out, but that doesn't appear to have any effect, possibly due to me not using it correctly.

Any suggestions?

Cheers

EDIT : If I take out the command from the error message and run that, substituting '*****' for mypassword, it works fine....

没有正确的解决方案

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top