I am using Xamarin in Visual Studio.
I created an boilerplate android app (click me) and I tried the following:
Scenario 1:
Switch to release mode
right click on project > Export Android Package (.apk)
Side loaded generated .apk it onto my phone
App launches with no issue
Scenario 2
Switch to release mode
Tools > Android > Publish Android App
Signed APK after creating private key store
Side load generated .apk (in release folder) onto phone
App closes immediately after launching (no error message, nothing)
What could be the issue here?
Do I need to do anything else after signing the package?
In both scenarios, the output apk is the same size 5227kb
UPDATE:
I have tried the same thing running on the android emulator. Same results. The app runs fine in debug mode on the emulator. Once I've switched it to Release, I get "Unfortunately, App1 has stopped"
Here's the error log http://pastebin.com/4j1Vwtgf
UPDATE 2:
Here's the logs when I'm deploying under release mode:
1>Starting deploy 5" KitKat (4.4) XXHDPI Phone ...
1>Deploying 5" KitKat (4.4) XXHDPI Phone ...
1>Build started.
1>C:\Program Files (x86)\MSBuild\14.0\bin\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE;__XAMARIN_ANDROID_v1_0__;__MOBILE__;__ANDROID__;__ANDROID_1__;__ANDROID_2__;__ANDROID_3__;__ANDROID_4__;__ANDROID_5__;__ANDROID_6__;__ANDROID_7__;__ANDROID_8__;__ANDROID_9__;__ANDROID_10__;__ANDROID_11__;__ANDROID_12__;__ANDROID_13__;__ANDROID_14__;__ANDROID_15__;__ANDROID_16__;__ANDROID_17__;__ANDROID_18__;__ANDROID_19__;__ANDROID_20__;__ANDROID_21__;__ANDROID_22__;__ANDROID_23__ /errorendlocation /preferreduilang:en-US /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\Mono.Android.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\App1.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /target:library /utf8output MainActivity.cs Resources\Resource.Designer.cs Properties\AssemblyInfo.cs "C:\Users\a\AppData\Local\Temp\MonoAndroid,Version=v6.0.AssemblyAttributes.cs" obj\Release\\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs obj\Release\\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs obj\Release\\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
1>App1 -> C:\Users\a\Documents\Visual Studio 2015\Projects\App1\App1\bin\Release\App1.dll
1> Processing: obj\Release\res\layout\main.xml
1> Processing: obj\Release\res\values\strings.xml
1>C:\Program Files (x86)\Java\jdk1.7.0_55\\bin\keytool.exe -list -alias androiddebugkey -storepass android -keypass android -keystore "C:\Users\al\AppData\Local\Xamarin\Mono for Android\debug.keystore"
1>C:\Program Files (x86)\Java\jdk1.7.0_55\\bin\jarsigner.exe -keystore "C:\Users\a\AppData\Local\Xamarin\Mono for Android\debug.keystore" -storepass android -keypass android -digestalg SHA1 -sigalg md5withRSA -signedjar bin\Release\\App1.App1-Signed-Unaligned.apk "C:\Users\a\Documents\Visual Studio 2015\Projects\App1\App1\obj\Release\android\bin\App1.App1.apk" androiddebugkey
1>No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2046-02-20) or after any future revocation date.
1>C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.1\zipalign.exe 4 "C:\Users\a\Documents\Visual Studio 2015\Projects\App1\App1\bin\Release\App1.App1-Signed-Unaligned.apk" "bin\Release\\App1.App1-Signed.apk"
1>Build succeeded.
1>Deploy successfully on 5" KitKat (4.4) XXHDPI Phone
And here are the build logs for debug mode
2>Starting deploy 5" KitKat (4.4) XXHDPI Phone ...
2>Deploying 5" KitKat (4.4) XXHDPI Phone ...
2>Build started.
2>C:\Program Files (x86)\Java\jdk1.7.0_55\\bin\keytool.exe -list -alias androiddebugkey -storepass android -keypass android -keystore "C:\Users\a\AppData\Local\Xamarin\Mono for Android\debug.keystore"
2>C:\Program Files (x86)\Java\jdk1.7.0_55\\bin\jarsigner.exe -keystore "C:\Users\a\AppData\Local\Xamarin\Mono for Android\debug.keystore" -storepass android -keypass android -digestalg SHA1 -sigalg md5withRSA -signedjar bin\Debug\\App1.App1-Signed-Unaligned.apk "C:\Users\a\Documents\Visual Studio 2015\Projects\App1\App1\obj\Debug\android\bin\App1.App1.apk" androiddebugkey
2>No -tsa or -tsacert is provided and this jar is not timestamped. Without a timestamp, users may not be able to validate this jar after the signer certificate's expiration date (2046-02-20) or after any future revocation date.
2>C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.1\zipalign.exe 4 "C:\Users\a\Documents\Visual Studio 2015\Projects\App1\App1\bin\Debug\App1.App1-Signed-Unaligned.apk" "bin\Debug\\App1.App1-Signed.apk"
2>Build succeeded.
2>Deploy successfully on 5" KitKat (4.4) XXHDPI Phone
I had the same error running release builds in the emulator (VS Android emulator). Turns out, we had disabled x86 as supported architecture.
I had a similar issue with a basic app when I started with Xamarin. The problem was with the apk file I was using. I picked it from my bin/Release folder while the path for the actual signed + published + zip-aligned app was at the project folder level outside the bin directory.
The signed.apk file in Release mode uses the debug keystore and so it is not possible to publish that, more info here.
Was a pretty silly miss by me, so in case someone else also has this issue please make sure you are picking the right apk file before diving into further debugging.
Inside your pastebin logs, it looks like you have a specific error here. It seems that the libmonodroid.so is not being loaded here.
03-25 00:40:18.531 E/AndroidRuntime( 1407): java.lang.UnsatisfiedLinkError:
Couldn't load monodroid from loader
dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/App1.App1-
1.apk"],nativeLibraryDirectories=[/data/app-lib/App1.App1-1, /system/lib]]]:
findLibrary returned null
This issue typically means that for some reason libmonodroid.so is not being installed.
I would recommend the following items:
use adb uninstall <package name> to completely remove any old App1.App1 applications.
Clean / Rebuild your project (Also be sure to manually delete the bin/obj folders in your solution.
If this continues to be an issue. Ensure a File->New Android Project will Debug and also install correctly as a Release .apk. You should also gather adb logcat of your attempts once you follow steps #1-2.
I found a possible solution.
On your device, in the developer options menu, you have to enable 'Force gpu rendering'.
Hope that helps.
Related
I have to write couple tests on Xamarin UI Test framework to check apk on emulator. I tried to install my apk in two ways:
1 adb.exe install path\com.company.mobiledemo.apk
2 through Xamarin UI Test
if (platform == Platform.Android)
{
AndroidApp app = ConfigureApp.Android
.ApkFile("path\\com.company.mobiledemo.apk")
.Debug()
.EnableLocalScreenshots()
.DeviceSerial("emulator-5554")
.StartApp();
return app;
}
In first approach apk installed and working correctly. But when apk installed via code above apk will be install but wont launch, just stopped after splash screen.
I have no idea why because both use the same apk file.
NUnit: 3.13.3
NUnit3TestAdapter: 4.2.1
Xamarin.UITest: 2.2.6
Emulator OS: Android 6.0 Api 23
Ok I found the solution. It's a bit confused and maybe there is a more easy fix. Problem as I understood is your apk and Instrumentation backend apk must be signed the same cert.
My steps:
I installed apk via adb command : >adb.exe install ~\..\com.company.mobiledemo.apk
Then changed AppInitializer.cs like this :
if (platform == Platform.Android)
{
string keystore = "~\\..\\..\\some.keystore";
AndroidAppConfigurator appConfigurator = ConfigureApp.Android
.KeyStore(
keystore,
"storePassword",
"keyPassword",
"\"keyAlias\""
)
.InstalledApp("com.company.mobiledemo.apk")
.Debug()
.EnableLocalScreenshots();
AndroidApp app = appConfigurator.StartApp(AppDataMode.Clear);
return app;
}
Then tried to launch test and got error :
System.Exception : Failed to execute: C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin\jarsigner.exe -sigalg SHA1withRSA -digestalg SHA1 -signedjar "C:\Users\{user}\AppData\Local\Temp\uitest\a-287A943C412ED6ED5DEB1675E7FDF91843FD0807\20344\SignedTestServer.apk" -storepass bla-bla -keypass bla-bla -keystore "~..\Mobile\Mobile.Android\Certificate\some.keystore" "C:\Users\{user}\AppData\Local\Temp\uitest\a-287A943C412ED6ED5DEB1675E7FDF91843FD0807\TestServer.apk" ""Key Alias"" - exit code: 1
Please type jarsigner -help for usage
Only one alias can be specified
It's ok.
Open folder from error message :
C:\Users{user}\AppData\Local\Temp\uitest\
You will see something like this :
Delete all and run tests once again. After launching new test data will appear:
Copy command from error message above, go to C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin or directory where located jarsigner.exe
Execute command after System.Exception : Failed to execute:
Find SignedTestServer.apk and copy it into folder containes dummy.apk
Run tests once again and see that FinalTestServer.apk appeared
PS Close folder C:\Users\{user}\AppData\Local\Temp\uitest before 9.
How to sign your APK or Android App Bundle in release mode in Visual Studio Native-Activity Application (Android) project?
When I rebuild solution and deploy solution in release ARM target, navigate to Release folder and drag and drop apk file to play.google.com (Play Store), there is following error message.
Upload failed
You uploaded a debuggable APK or Android App Bundle. For security reasons you need to disable debugging before it can be published in Google Play. Learn more about debuggable APKs or Android App Bundles.
You uploaded an APK or Android App Bundle that was signed in debug mode. You need to sign your APK or Android App Bundle in release mode. Learn more about signing.
I have manged to generate and download deployment_cert.der on play store, but not sure how it can be added to apk in Visual Studio Native-Activity Application (Android) project.
Figered it out now.
Built APK file can be signed by using command line (without need of installing Android Studio). This can be done as follows:
1.) Bellow will allow to build unsigned APK in release mode:
.packing project Properties --> Ant --> Ant Build Target --> Release (Release Mode)
2.) Add JDK and Android SDK to PATH. In my case (installed by VS installer) those paths are:
C:\Program Files\Java\jdk1.8.0_172\bin
C:\Program Files (x86)\Android\android-sdk\build-tools\25.0.3
3.) Create keystore with key:
keytool -genkey -v -keystore my_app.keystore -alias alias_name -keyalg PSA -keysize 2048 -validity 10000
4.) Sign APK:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my_app.keystore My.App.Packaging-release-unsigned.apk alias_name
5.) ZIP align:
zipalign -f -v 4 My.App.Packaging-release-unsigned.apk My.App.apk
6.) Drag and drop to Play Store
My game is developed by Unity3d, I need to encrypt the DLL in APK.I add the following steps in build pipeline:
unzip the APK file
encrypt the managed dlls and replace with modified libmono.so (same Unity version, same ABI)
zip & jarsigner & zipalign
jarsigner -verbose -keystore debug.keystore -signedjar "%1"_unaligned.apk "%1".apk %alias%
zipalign -f 4 "%1"_unaligned.apk "%1"_release.apk
The resulting APK can install, but dies immediately after startup, no useful logcat, any helps?
Every time I want to deploy my Android.Xamarin project I'm getting the following error:
3>The specified task executable location
"C:\Users\Alexey\AppData\Local\Android\android-sdk\tools\zipalign.exe"
is invalid.
I'm working from Visual Studio 2013 on alpha channel.
VS Xamarin Plugin v3.2.5.0
Full output log:
3>Packaging application.. 3>Build started. 3>C:\Program Files
(x86)\Java\jdk1.6.0_39\bin\jarsigner.exe -keystore
"C:\Users\Alexey\AppData\Local\Xamarin\Mono for
Android\debug.keystore" -storepass android -keypass android -digestalg
SHA1 -sigalg md5withRSA -signedjar
bin\Debug\com.xxx-Signed-Unaligned.apk
C:\Sources\Git...\obj\Debug\android\bin\com.xxx.apk androiddebugkey
3>The specified task executable location
"C:\Users\Alexey\AppData\Local\Android\android-sdk\tools\zipalign.exe"
is invalid. 3>Build FAILED.
Please help
Android SDK has changed the folder structure. The fix is easy, just follow the instructions at Xamarin Forums: http://forums.xamarin.com/discussion/19772/zipalign-error-executing-tool-executable-location-invalid-android-sdk-tools-23#latest
Windows
Open Android SDK Manager, and ensure that you have "Android SDK
Build-tools" Rev. 19.1 or 20 installed. If not, install it. Locate
your Android SDK folder. You can find this in the error message, or
you can look in Visual Studio under "Tools -> Options -> Xamarin ->
Android Settings -> Android SDK Location". For this example, I'll use:
%LOCALAPPDATA%\Android\android-sdk Copy zipalign from the build-tools
folder:
%LOCALAPPDATA%\Android\android-sdk\build-tools\19.1.0\zipalign Into
the tools folder:
%LOCALAPPDATA%\Android\android-sdk\tools\zipalign
keytool -list -alias androiddebugkey -keystore "C:\Users\hp\.android\debug.keystore" -storepass android -keypass android
thats what i type into my command, on windows 7 and i keep getting the reply "keytool is not recognised as an internal or external command, operable program or batch file."
=S not sure weather to install andriod again or if ive miss typed something
The keytool utility is not part of the Android SDK, but the Java JDK.
It appears you may not have your JDK bin/ directory in your PATH. While in a command-prompt, try browsing to the directory C:\Program Files (x86)\Java\jdk#\bin (# is your jdk version installed) then running the command.
Note: If you are using jdk 1.7.0 you may need to add the -v option to keytool as it doesn't give MD5 by default, only SHA.