Pergunta

We have a Xamarin.Android project that we are trying to build using Jenkins on a Mac. The Solution file contains several different projects, one of which is the MonoDroid project. The MonoDroid Project is dependent upon the other projects in the solution.

The problem that I have is that when I use xbuild to build the solution file, I have no way to use the /t:PackageForAndroid target, since it only is valid for the MD Project File.

Currently in Jenkins, I'm doing it like this:

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

This is working, but it seems to me that there should be a way to eliminate the 3rd step. Does anyone have any insight?

Foi útil?

Solução 2

The consensus around the interwebs seems to be that I am doing this the right way.

Outras dicas

You don't need to use Xamarin.Studio/MonoDevelop to sign & zipalign your APK, you can do that at the command line. I've had luck using rake to compile, sign, and zipalign my APK files. Would something like that work for you?

Failing that, here is a simple Powershell script that you could probably port over real easy:

# 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

Hope this helps.

Regarding Signing your apk i'm using something like this as a part of my makefile and it works ok:

...

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))

Hope this helps

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top