'mono shared runtime'总是部署到android设备上

时间:2013-04-02 13:10:10

标签: android mono xamarin.android apk xamarin

我正在尝试使用xamarin.android&创建一个APK visual studio 2012,但'package ... apk文件'的选项被禁用 - 我相信这是一个如下所述的错误:(https://bugzilla.xamarin.com/show_bug.cgi?id=10530)。

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

1 个答案:

答案 0 :(得分: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

希望这有帮助。