在自定义的Ant生成步骤更改应用程序包的名称 [英] Changing application package name in custom Ant build step

查看:166
本文介绍了在自定义的Ant生成步骤更改应用程序包的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个自定义生成重新包装我的Andr​​oid应用程序。我要创建我可以安装并排侧我的生产应用程序的内部测试版本。

I'm trying to use a custom build to repackage my Android app. I want to create an internal beta version which I can install side-by-side with my production app.

这个答案的样子正是我需要的,但它似乎并没有正常工作。

This answer looks like exactly what I need, however it doesn't seem to work.

下面是更新到我的build.xml:

Here's the update to my build.xml:

<target
    name="-package-resources"
    depends="-crunch" >

    <echo>Repackaging AndroidManifest.xml to ${package.manifest.name} ${out.absolute.dir}/${resource.package.file.name}</echo>

    <exec executable="${aapt}" failonerror="true">
        <arg value="package" />
        <arg value="-f" />
        <arg value="--auto-add-overlay" />
        <arg value="-M" />
        <arg path="AndroidManifest.xml" />
        <arg value="-S" />
        <arg path="${resource.absolute.dir}" />
        <arg value="-S" />
        <arg path="${android.library.reference.1}/res" />
        <arg value="-A" />
        <arg path="${asset.absolute.dir}" />
        <arg value="-I" />
        <arg path="${project.target.android.jar}" />
        <arg value="-F" />
        <arg path="${out.absolute.dir}/${resource.package.file.name}" />
        <arg value="--rename-manifest-package" />
        <arg value="${package.manifest.name}" />
    </exec>
</target>

运行似乎成功运行我的新code:

Running it seems to successfully run my new code:

ant debug -Dpackage.manifest.name=com.example.test    
...    
 -package-resources:    
      [echo] Repackaging AndroidManifest.xml to com.example.test /<mypath>/bin/<appname>.ap_
...    
BUILD SUCCESSFUL

然而,当我使用 APKTool 视察APK,包名在我AndroidManifest没有被改变为新的值。所有这一切似乎已经发生的事情是,我的相对活性路径.MyActivity已经扩展到我原来的包名。

However, when I use APKTool to inspect the APK, the package name in my AndroidManifest has not been changed to the new value. All that seems to have happened is that my relative activity paths ".MyActivity" have been expanded to my original package name.

apktool d --force bin/<appname>-debug.apk

有谁知道我在做什么错了?我看了所有的其他的答案#1和大多数似乎有点过时了。我建立了Android SDK工具版本21.1.0,为的minSdkVersion 8。

Does anybody know what I'm doing wrong? I've looked at all the other Stackoverflow answers and most seem a little out of date. I am building with Android SDK Tools Revision 21.1.0, for minSdkVersion 8.

更新:如下面他的回答@athor的意见,我对检查的Andr​​oidManifest.xml假设是错误的。为了验证这一点,你真的需要尝试安装它,而不是观看反编译XML!

Update: As @athor comments below his answer, my assumption about inspecting the AndroidManifest.xml is wrong. To test this you actually need to try installing it rather than viewing the decompiled XML!

推荐答案

这是我做的方式(工作)

This is the way I do it (working)

 <target
        name="-package-resources"
        depends="-crunch" >

        <!-- only package resources if *not* a library project -->

        <echo message="Current Package name: ${app.custompackagename}" />

        <do-only-if-not-library elseText="Library project: do not package resources..." >

            <aapt
                androidjar="${project.target.android.jar}"
                apkfolder="${out.absolute.dir}"
                assets="${asset.absolute.dir}"
                buildType="${build.target}"
                command="package"
                debug="${build.is.packaging.debug}"
                executable="${aapt}"
                ignoreAssets="${aapt.ignore.assets}"
                libraryPackagesRefid="project.library.packages"
                libraryRFileRefid="project.library.bin.r.file.path"
                libraryResFolderPathRefid="project.library.res.folder.path"
                manifest="${out.manifest.abs.file}"
                manifestpackage="${app.custompackagename}"
                nocrunch="${build.packaging.nocrunch}"
                previousBuildType="${build.last.target}"
                resourcefilename="${resource.package.file.name}"
                resourcefilter="${aapt.resource.filter}"
                versioncode="${version.code}"
                versionname="${version.name}" >

                <res path="${out.res.absolute.dir}" />

                <res path="${resource.absolute.dir}" />
                <!-- <nocompress /> forces no compression on any files in assets or res/raw -->
                <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
            </aapt>
        </do-only-if-not-library>
    </target>

行manifestpackage =$ {app.custompackagename}是关键。

The line manifestpackage="${app.custompackagename}" is the key.

这篇关于在自定义的Ant生成步骤更改应用程序包的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆