1

我正在尝试使用 xamarin.android 和 Visual Studio 2012 创建一个 APK,但是“包 ... apk 文件”的选项被禁用 - 我相信这是这里描述的错误:( https://bugzilla. xamarin.com/show_bug.cgi?id=10530)。

但是,在部署到设备时仍然会创建一个 apk,问题是我只想要一个包含所有内容的 APK(所以我可以通过 Web 服务器部署它),但是当以这种方式构建时,即使在发布时使用“使用共享运行时” '未勾选,'单共享运行时'仍然安装在设备上。我在这里创建了一个问题:(https://bugzilla.xamarin.com/show_bug.cgi?id=11419)但还没有回复..

4

1 回答 1

4

听起来您只想发布一个 APK,对吗?在这种情况下,可以从命令行构建 APK。如果您使用的是 Windows,则可以使用以下 Powershell 脚本作为模板自动执行此操作:

# 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 MD5withRSA -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

在 Mac 上也可以从命令行构建。我通常会使用 Rake 构建文件自动执行此操作(您需要从Albacore为 .NET Rake 任务安装 gem )。以下是您可以用作模板的 rakefile:

require 'albacore'

@file_version = "2.0.0.0"
@keystore     = "../keystores/opgenorth-release-key.keystore"
@alias_name   = "mytrips"
@input_apk    = "EmploymentStandardsJudgments.Android/bin/Release/net.opgenorth.esj.apk"
@signed_apk   = "EmploymentStandardsJudgments.Android/bin/Release/net.opgenorth.esj-signed.apk"
@final_apk    = "deploy/AlbertaEmploymentJudgments.apk"

task :default => [:clean, :versioning, :build, :sign] 

desc "Remove the bin and obj directories."
task :clean do
  rm_rf "EmploymentStandardsJudgments.Android/bin"
    rm_rf "EmploymentStandardsJudgments.Android/obj"
end

desc "Update the build number before compiling."
assemblyinfo :versioning do |asm|
    asm.input_file  = "EmploymentStandardsJudgments.Android/Properties/AssemblyInfo.cs"
    asm.output_file = "EmploymentStandardsJudgments.Android/Properties/AssemblyInfo.cs"
    asm.version = @file_version
    asm.file_version = @_file_version
end

desc "Compiles the project."
xbuild :build do |msb|
    msb.solution = "EmploymentStandardsJudgments.Android/EmploymentStandardsJudgments.Android.csproj"
    msb.properties = { :configuration => :release }
    msb.targets [ :Clean, :Build, :SignAndroidPackage ]
end

desc "Signs and zip aligns the APK."
task :sign do 
    sh "jarsigner",  "-verbose", "-sigalg", "MD5withRSA", "-digestalg", "SHA1", "-keystore",  @keystore, "-signedjar", @signed_apk, @input_apk, @alias_name
    sh "zipalign", "-f", "-v", "4", @signed_apk, @final_apk
end

desc "Install the APK on a device."
task :install do
    %x[adb shell pm uninstall -k net.opgenorth.esj.android]
    %x[adb install deploy/AlbertaEmploymentJudgments.apk]
end

希望这可以帮助。

于 2013-04-02T17:24:09.583 回答