【问题标题】:Using Xbuild with Xamarin.Android (formerly Mono for Android)将 Xbuild 与 Xamarin.Android(以前的 Mono for Android)一起使用
【发布时间】:2013-04-04 15:35:15
【问题描述】:

我们有一个 Xamarin.Android 项目,我们正在尝试在 Mac 上使用 Jenkins 构建该项目。解决方案文件包含几个不同的项目,其中之一是 MonoDroid 项目。 MonoDroid 项目依赖于解决方案中的其他项目。

我遇到的问题是,当我使用xbuild 构建解决方案文件时,我无法使用 /t:PackageForAndroid 目标,因为它仅对 MD 项目文件有效。

目前在 Jenkins,我正在这样做:

xbuild MyCoolDroidAp/MyCoolDroidApp.sln /p:Configuration=Release /t:Clean
xbuild MyCoolDroidApp/MyCoolDroidApp.sln /p:Configuration=Release /t:Build
xbuild MyCoolDroidApp/MyCoolDroidProject.csproj /p:Configuration=Release /t:PackageForAndroid

这是可行的,但在我看来,应该有一种方法可以消除第三步。有人有什么见解吗?

【问题讨论】:

    标签: jenkins xamarin.android xamarin xbuild


    【解决方案1】:

    您无需使用 Xamarin.Studio/MonoDevelop 对您的 APK 进行签名和压缩对齐,您可以在命令行中执行此操作。我很幸运使用rake to compile, sign, and zipalign my APK files。类似的东西对你有用吗?

    如果做不到这一点,这里有一个简单的 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
    

    希望这会有所帮助。

    【讨论】:

    • 所以我试过这个,但使用 xbuild 而不是 msbuild。我的问题是在第二步...... MonoDroid 项目所依赖的解决方案中有一些项目。当我在 .csproj 文件上调用 xbuild 时,不会构建那些依赖的解决方案。
    • 我在 xbuild 过程之外进行签名和 zip 对齐——它们是 Jenkins 中的后续步骤。
    【解决方案2】:

    互联网上的共识似乎是我这样做是正确的。

    【讨论】:

      【解决方案3】:

      关于签署你的 apk 我正在使用这样的东西作为我的 makefile 的一部分,它工作正常:

      ...
      
      BUILD_DIR = ./builds/$(platform)
      KEYSTORE_PATH = your_keystore_pass
      STORE_PASS = your_keystore_pass
      ANDROID_SDK_PATH = path/to/your/android/sdk/dir 
      #example ANDROID_SDK_PATH = /Developer/AndroidSDK
      RES_APK = my_apk.apk
      APK_NAME = my_signed_apk.apk
      
      ...
      
      
      sign:
        (cd $(BUILD_DIR); jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore $(KEYSTORE_PATH) -storepass $(STORE_PASS) result.apk $(STORE_PASS))
        (cd $(BUILD_DIR); $(ANDROID_SDK_PATH)/tools/zipalign -v 4 result.apk $(APK_NAME))
        (cd $(BUILD_DIR);rm result.apk)
        (cd $(BUILD_DIR);rm $(RES_APK))
      

      希望对你有帮助

      【讨论】:

      • 我在 jenkins 中使用 jar signer 和 zip align 做了类似的事情。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多