简体   繁体   English

我可以将我的Android应用程序构建为调试,但使用发布密钥库进行签名

[英]Can I build my Android app as debug but sign with release keystore

I'm trying to test in-app billing in my app. 我正在尝试在我的应用中测试应用内结算。 I have billing and product id's all setup in the Play store but to test a transaction I need to sign my app with my release keystore otherwise it fails. 我在Play商店中设置了计费和产品ID,但为了测试一个事务,我需要使用我的发布密钥库来签署我的应用程序,否则它将失败。

I'm using IntelliJ Idea (Ver. 11 CE) and can't quite figure out how to configure the project to build with debug set and sign with my release keystore before deploying to my device. 我正在使用IntelliJ Idea(Ver.11 CE),并且无法弄清楚如何配置项目以使用调试集进行构建,并在部署到我的设备之前使用我的发布密钥库进行签名。

I see I can set an ant target for a configuration and I'm assuming that's the way to go but since my build.xml imports the Android SDK /tools/ant/build.xml there aren't any targets in to choose. 我看到我可以为配置设置一个ant目标,我假设这是要走的路,但是因为我的build.xml导入了Android SDK /tools/ant/build.xml,所以没有任何目标可供选择。

To debug do I merely need to enable set android:debuggable="true" in the manifest? 要调试我只需要在清单中启用set android:debuggable =“true”吗? Anyone have a suggestion for an ant target that would do the things I need? 任何人都有一个蚂蚁目标的建议,可以做我需要的东西吗? One that I can add to my build.xml? 我可以添加到build.xml中的一个?

With pointers in the right direction form Ixx I ended up setting android:debuggable="true" and using the command line to build and deploy. Ixx的正确方向指针我最终设置android:debuggable =“true”并使用命令行来构建和部署。 Then attaching to the running process to debug. 然后附加到运行进程进行调试。

My application is setup to build at the command line with an ant build.xml file that imports androidSDK/tools/ant/build.xml and a supporting build.properties file. 我的应用程序设置为在命令行中使用ant build.xml文件构建,该文件导入androidSDK / tools / ant / build.xml和支持的build.properties文件。 I discovered that when I set android:debuggable="true" and then do 'ant release' the build process will create a debuggable apk and sign it with the release key. 我发现当我设置android:debuggable =“true”然后执行'ant release'时,构建过程将创建一个可调试的apk并使用释放键对其进行签名。

I created a target in my build.xml file that I could set for this case called set-debuggable 我在build.xml文件中创建了一个目标,我可以为这种情况设置一个名为set-debuggable的目标

<target name="set-debuggable" description="sets internal named property">
    <echo>Setting internal named property...</echo>
    <property name="set.debuggable" value="true" />
</target>

Then in my -pre-build target I added 然后在我的-pre-build目标中我添加了

    <if>
        <condition>
            <isset property="set.debuggable"/>
        </condition>
        <then>
            <replaceregexp
                    file="AndroidManifest.xml"
                    match="(android:debuggable=&#34;).*(&#34;)"
                    replace="\1true\2"/>

        </then>
        <else>
            <replaceregexp
                    file="AndroidManifest.xml"
                    match="(android:debuggable=&#34;).*(&#34;)"
                    replace="\1false\2"/>

        </else>
    </if>

This creates my debuggable apk that is signed with my release key when I use 'ant set-debuggable release'. 这创建了我的debuggable apk,当我使用'ant set-debuggable release'时,用我的发布密钥签名。 Then I use 'adb install -r myApp-release.apk' to re-install the new build. 然后我使用'adb install -r myApp-release.apk'重新安装新版本。 I can then launch and attach to the running application for debugging through in-app purchases. 然后,我可以通过应用内购买启动并附加到正在运行的应用程序以进行调试。

It appears as though both IntelliJ Idea and Eclipse use a self signed debug key somewhere on your system to build and deploy a debug apk from the IDE. 似乎IntelliJ Idea和Eclipse都在系统的某个地方使用自签名调试密钥来从IDE构建和部署调试apk。

In hindsight I might have been able to replace the debug key that the IDE created with my release key and attempted to get the build to sign with that key (and find the password to use the key) but the build process above took me very little time to setup and start using. 事后我可能已经能够用我的发布密钥替换IDE创建的调试密钥,并尝试使用该密钥签署构建(并找到使用密钥的密码),但上面的构建过程对我很少设置和开始使用的时间。 If anyone goes in this direction and gets it working, please add a comment to my answer. 如果有人朝着这个方向前进并使其正常工作,请在我的回答中添加评论。

As of IntelliJ IDEA 12 (don't know about the previous versions), you can set a "Custom debug keystore" in the Android facet for the top level module. 从IntelliJ IDEA 12开始(不了解以前的版本),您可以在Android facet中为顶级模块设置“自定义调试密钥库”。 This way you can control how your APK is signed and actually use your release keys for debugging from the IDE. 这样,您就可以控制APK的签名方式,并实际使用发布密钥从IDE进行调试。

I have this in build.xml to set debuggable attribute: 我在build.xml中有这个来设置debuggable属性:

<condition property="build.env" value="${build.env}" else="local">
    <isset property="build.env" />
</condition>

<!-- set debuggable=false for release and true for debug and others -->
<condition property="isDebuggable" value="false" else="true">
        <equals arg1="${build.env}" arg2="release" />
    </condition>
    <replaceregexp 
        file="AndroidManifest.xml"
        match="(android:debuggable=&#34;).*(&#34;)" 
        replace="\1${isDebuggable}\2"
        >
    </replaceregexp>

Where build.env is passed to the ant program like this (in the case of "release"): 将build.env传递给ant程序,如下所示(在“release”的情况下):

ant <targets> -Dbuild.env=release

In order to sign, you add this to the property files: 要进行签名,请将其添加到属性文件中:

key.store=C:/path/to/keystore/mykeystore.keystore

Debug app has a debug keystore (although I currently don't remember exactly why this keystore is necessary)-> here 's more information on it. 调试应用程序有一个调试密钥库(虽然我目前不记得为什么这个密钥库是必要的) - > 这里有更多的信息。 Probably you just have to use the release keystore instead. 可能你只需要使用发布密钥库。

IntelliJ is using .android/debug.keystore file by defult for signing debug version of your application. IntelliJ使用defult的.android / debug.keystore文件来签署应用程序的调试版本。 You could change this file with your release keystore or import your release certificate to debug.keystore file. 您可以使用发布密钥库更改此文件,或将发布证书导入debug.keystore文件。 I have prepared step by step instructions for this at http://www.denizoguz.com/2013/01/12/failure-install_parse_failed_inconsistent_certificates/ 我在http://www.denizoguz.com/2013/01/12/failure-install_parse_failed_inconsistent_certificates/上为此准备了一步一步的说明

Given that Lint now advises against hardcoding of "android:debuggable" flag in AndroidManifest.xml I've come with a better solution (at least for my case). 鉴于Lint现在建议不要在AndroidManifest.xml中对“android:debuggable”标志进行硬编码,我会提供更好的解决方案(至少在我的情况下)。 Just define a new ant target in your custom_rules.xml that does everything exactly the same as the android debug target does, but signs the apk with release key as well. 只需在custom_rules.xml中定义一个新的ant目标,该目标执行与android调试目标完全相同的操作,但也会使用释放键对apk进行签名。

<target name="build-debug" depends="-set-debug-files, -do-debug, -release-sign, -post-build" />

The only subtask that needs to be added is "-release-sign" before "-post-build" and then run your "bulid-debug" instead of android "debug" target. 需要添加的唯一子任务是“-post-build”之前的“-release-sign”,然后运行“bulid-debug”而不是android“debug”目标。

Or, you can just "-release-sign" to debug dependency like this: 或者,您可以“发布 - 签名”来调试依赖关系,如下所示:

<target name="build-debug" depends="debug, -release-sign" />

but this doesn't work for me, because I do some extra stuff on "-post-build" and need to sign the package before "-post-build". 但是这对我不起作用,因为我在“-post-build”上做了一些额外的东西,需要在“-post-build”之前签署包。

Try setting the debuggable flag to true in your android manifest. 尝试在android清单中将debuggable标志设置为true。

 <application
        android:debuggable="true"

Debuggable Flag 可调试标志

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我丢失了密钥库,如何在我的 Android 应用上发布新版本? - How can I make a new release on my android app if i lost my keystore? 如何使用 AppCenter 上上传的发布密钥库对 Android 发布版本进行签名? - How to sign Android release build using uploaded release keystore on AppCenter? 如何使用Android密钥库对Flex Mobile App进行签名? - How can I sign a Flex Mobile App using Android keystore? 使用发布(我自己的)密钥库进行调试 - Debug with release(my own) keystore Android调试密钥库可与发布密钥库一起使用吗? - Does Android debug keystore work with release keystore? Android Google登录:未发布调试版本时,应用发布版本始终显示“错误:12500” - Android Google Sign In: App Release Build Always Got “Error: 12500”, While Debug Build Isn't 如何在Android Studio中使用我的上传密钥(没有密钥库)对我的android应用捆绑包进行签名? - How do I sign my android app bundle with my upload key (without the keystore) in Android Studio? 如何知道我的Android应用程序是在发布版还是调试模式下构建的? - How can I know if my android app was built in release or debug mode? 无法在发布模式下构建应用-密钥库被篡改,或者密码不正确 - Can't build app on release mode - Keystore was tampered with, or password was incorrect 为 Jenkins 和 Android 构建调试密钥库 - Debug keystore for Jenkins and Android build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM