【问题标题】:xamarin.android App signing does not workxamarin.android 应用签名不起作用
【发布时间】:2013-05-13 14:30:15
【问题描述】:

所以我试图将我的新 android 应用程序发布到 Google PlayStore。通过阅读this 教程,我了解到我必须先签署我的应用程序,然后才能将其发布到 PlayStore。我所做的与教程中的完全相同。将其上传到 PlayStore 后,我尝试在我的设备上安装该应用程序。我收到消息“包文件未正确签名”。这是个悲剧。在 xamaran 工作室中,我收到“包裹已成功签名”的消息。

如果我尝试从设备上的 apk 安装应用程序,我会收到消息“无法安装”

这里有什么问题?

我在 Mac 上使用 Xamarin Studion。

【问题讨论】:

  • 您使用的是 Xamarin Studio 还是 Visual Studio?您运行的是 OSX 还是 Windows?
  • @TomOpgenorth 我编辑了我的问题:)
  • 根据我的经验,我建议您手动签署您的申请。docs.xamarin.com/guides/android/…
  • @AaronHe Ok 手动签名工作得很好,但是当我尝试 zipalign 时,我得到消息“没有这样的命令”谷歌搜索了一下,发现你必须做 ./zipalign 但后来我得到了消息“没有这样的文件或目录”。
  • @AaronHe 它现在工作了,我压缩并签署了我的包裹。当我现在将其上传到 Playstore 时,它​​会显示“您的 APK 已使用多个证书签名。请仅使用一个证书对其进行签名并重新上传。”

标签: android xamarin.android code-signing xamarin-studio


【解决方案1】:

找到问题..这是一个 JAVA 工具问题。这种情况在系统上混合使用 JDK 和 JRE 工具时经常发生。

不要使用 Java 7 中的工具!

仅使用 JDK 6 中的工具。 您可以通过键入以下内容来检查您拥有的版本:

java -version

如果您仍然不确定签名是否成功,您可以输入:

which jarsigner

jarsigner -verify -verbose -certs myapp.apk

【讨论】:

  • 刚遇到这个问题,想补充一下JDK 6的路径(至少在OSX 10.9上)是/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home您可以在 Xamarin Studio 的 Preferences -> SDK Locations -> Android 中进行设置
  • 我不确定是否只有 Java 6 有效,但我可以确认 Java 8 在 OSX Yosemite 上不适合我。我没有更改我的开发环境中使用的任何工具或 Java 版本(这是来自java -version 的 Java 8)......并且开发环境是 Xamarin......但我可以说当我使用 Java 6 jarsigner 的版本,然后我就可以从 Google Play 商店运行该应用程序,但无法运行。
【解决方案2】:

在 Mac 上发布时,我使用 rake 自动执行该过程。 This gist 是一个示例 rake 文件,展示了如何执行此操作。此 rake 文件将对程序集进行版本控制、编译应用程序,然后对 APK 进行签名/压缩对齐。

注意Albacore gem也必须安装。

【讨论】:

  • 已经通过使用不同版本的 java 修复它。 Java 7 JDK 中有一个错误。但这看起来要容易得多。我会尽快尝试。
【解决方案3】:

这似乎是从 JDK 1.6 切换到 JDK 1.7 造成的。我建议不要坚持使用 JDK 1.6(在某些情况下不是一个选项),而是创建一个小脚本来创建基于 http://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/ 的签名和对齐 apk

# First clean the Release target.
msbuild.exe HelloWorld.csproj /p:Configuration=Release /t:Clean

# Now build the project, using the Release target.
msbuild.exe HelloWorld.csproj /p:Configuration=Release /t:PackageForAndroid

# At this point there is only the unsigned APK - sign it.
# The script will pause here as jarsigner prompts for the password.
# It is possible to provide they keystore password for jarsigner.exe by adding an extra command line parameter -storepass, for example
#    -storepass <MY_SECRET_PASSWORD>
# If this script is to be checked in to source code control then it is not recommended to include the password as part of this script.
& 'C:\Program Files\Java\jdk1.6.0_24\bin\jarsigner.exe' -verbose -sigalg SHA1withRSA -digestalg SHA1  -keystore ./xample.keystore -signedjar ./bin/Release/mono.samples.helloworld-signed.apk ./bin/Release/mono.samples.helloworld.apk publishingdoc

# Now zipalign it.  The -v parameter tells zipalign to verify the APK afterwards.
& 'C:\Program Files\Android\android-sdk\tools\zipalign.exe' -f -v 4 ./bin/Release/mono.samples.helloworld-signed.apk ./helloworld.apk

重要的部分是使用参数-sigalg SHA1withRSA -digestalg SHA1 强制 JDK 1.7 使用预期的摘要算法(而不是 SHA-256,这似乎是 JDK 1.7 中的默认值,并非所有 Android 版本都接受)。

请注意,您可以使用

找到 msbuild 位置
$dotNetVersion = "4.0"
$regKey = "HKLM:\software\Microsoft\MSBuild\ToolsVersions\$dotNetVersion"
$regProperty = "MSBuildToolsPath"

$msbuildExe = join-path -path (Get-ItemProperty $regKey).$regProperty -childpath "msbuild.exe"

【讨论】:

    【解决方案4】:

    我在这里https://forums.xamarin.com/discussion/comment/72399/#Comment_72399找到了解决方案。

    Felix Alcala 的回答非常完美。设备上不再出现“应用未安装”消息。

    在 Xamarin Studio 中打开 SDK 位置

    首选项/项目/SDK 位置/Android

    并将 Java SDK(JDK) 设置为

    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

    【讨论】:

      【解决方案5】:

      当使用来自 Xamarin 的 Google Play 服务组件 ICS 时,如果您使用的是 JDK 6,则会出现以下错误。

      2>JAVAC : warning : com\google\ads\mediation\MediationBannerListener.class(com\google\ads\mediation:MediationBannerListener.class): major version 51 is newer than 50, the highest major version supported by this compiler.
      2>JAVAC : warning : com\google\ads\mediation\MediationBannerAdapter.class(com\google\ads\mediation:MediationBannerAdapter.class): major version 51 is newer than 50, the highest major version supported by this compiler.
      

      Error building Xamarin.Android project with Google Play Services

      通过从 JDK 6 更改为 JDK 7 解决了此错误。因此,现在我已经部署到 Google Play 商店的应用程序在某些智能手机中抛出“包文件未正确签名”。

      有没有办法使用 JDK 7 和 Xamarin 正确签署应用程序?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-02-09
        • 1970-01-01
        相关资源
        最近更新 更多