Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Having the MSBuild property <AndroidUseSharedRuntime>true</AndroidUseSharedRuntime> or option set to "True" in the Android Build options is throwing a ClassNotFoundException in certain projects on Xamarin Studio. It is complaining about certain classes not being found in the 'classes.dex' file (Also known as the main dex list). In the stack trace below, it is trying to find a custom application class which is the entry point to the application:
However after directly investigating the `classes.dex` file in the `obj/Debug/android/bin` folder, the class is indeed in the dex list and thus this is a potential red herring to the actual issue at hand.
I then decided to check the actual .apk that is being added to the device. To do so I used the following:
1) `adb backup -apk com.companyname.applicationname'
2) Skip Encryption by not setting a password
3) `dd if=backup.ab bs=24 skip=1 | openssl zlib -d > backup.tar`
4) Extract the .tar
5) Navigate to the `a` folder and find the `base.apk` file
6) `unzip base.apk`
This now shows us the original `classes.dex` list in the project. However when the Shared Runtime is enabled in some projects, there is no such file and thus it makes sense why the exception above is being thrown. In other apps that have the Shared Runtime enabled and do work, you can find the `classes.dex` list.
`classes.dex` is not being deployed with the `base.apk` in some circumstances when the Shared Runtime is enabled
`classes.dex` should be deployed with the `base.apk` when the Shared Runtime is enabled
Xamarin Studio (Known)
Reproduction will be attached separately as a private comment with reproduction steps.
Xamarin Studio - 6.1 (build 5441)
Mono - 4.6.0 (mono-4.6.0-branch/746756c)
Xamarin.Android - 220.127.116.11
JDK - 1.8.0_102 64-bit
As a secondary note. I added https://bugzilla.xamarin.com/show_bug.cgi?id=43241 as a related bug/duplicate as this is the behavior on any device <= API 19. On Devices >= API 21, it will throw a ClassNotFoundException.
Marking as CONFIRMED as I am able to reproduce this issue with the repo project in comment 1 on a API 23 device.
I was able to confirm this symptom for my LG Volt API 19 device:
> Deployment failed because of an internal error: Failure [INSTALL_FAILED_DEXOPT]
=== Xamarin Studio Enterprise ===
Version 6.1 (build 5441)
Installation UUID: 8ef63a7c-1b18-40de-a334-7f78777fcb55
Mono 4.6.0 (mono-4.6.0-branch/746756c) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Package version: 406000245
=== NuGet ===
=== Xamarin.Profiler ===
=== Apple Developer Tools ===
Xcode 8.0 (11246)
=== Xamarin.iOS ===
Version: 10.0.0.6 (Visual Studio Enterprise)
Build date: 2016-09-09 13:01:32-0400
=== Xamarin.Android ===
Version: 18.104.22.168 (Visual Studio Enterprise)
Android SDK: /Users/kentgreen/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
4.0.3 (API level 15)
4.1 (API level 16)
4.2 (API level 17)
4.3 (API level 18)
4.4 (API level 19)
4.4.87 (API level 20)
5.0 (API level 21)
5.1 (API level 22)
6.0 (API level 23)
7.0 (API level 24)
SDK Tools Version: 25.2.2
SDK Platform Tools Version: 24.0.3
SDK Build Tools Version: 24.0.2
Java SDK: /usr
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
Android Designer EPL code available here:
=== Xamarin Android Player ===
=== Xamarin.Mac ===
Version: 22.214.171.124 (Visual Studio Enterprise)
=== Xamarin Inspector ===
Build date: Fri Apr 8 17:34:53 UTC 2016
=== Build Information ===
Release ID: 601005441
Git revision: 68292d1ab289911c815ddc715dd7cc29a9752f9f
Build date: 2016-09-09 04:43:23-04
Xamarin addins: ed25d008672663eeb9db55f1ccecb3c24d2fd3b2
Build lane: monodevelop-lion-cycle8
=== Operating System ===
Mac OS X 10.11.6
Darwin Kents-MBP 15.6.0 Darwin Kernel Version 15.6.0
Mon Aug 29 20:21:34 PDT 2016
=== Enabled user installed addins ===
Xamarin Inspector 0.7.1.0
Can someone who has replicated this provide a full diagnostic output of the msbuild /t:Install target.
1. Clean the project (i.e no bin/obj)
2. run 'xbuild <project.csproj> /t:Install /v:d > build.log 2>&1'
this will do a complete build and install.
Confirm that the problem still happens by running up the app.
Hopefully the diagnostic output should let us see what is going on with the classes.dex file.
Does this only happen on devices? I am running all the latest stable versions and the app deploys fine to the XAP emulator.
This is weird. In my case, an app that I am already developing more than a year happens this problem, but in a new app that I just create everything works perfectly.
I trying found any differences between projects to try solve this.
We think we know the problem, or at least the direction of the problem.
The problem is when Xamarin Studio runs the BuildApk-related targets, the MSBuild AfterTargets properties are apparently ignored.
1. Command-line build:
2. XS build:
(The second XS gist is the packaging output.)
There's a notable difference in the BuildApk task output:
# no output
If we look at `/Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild/Xamarin/Android/Xamarin.Android.Common.Debugging.targets`, we see:
The `<BuildApk/>` task in the `_BuildApkFastDev` target uses the `@(_DexFileForFastDev)` item group; this item group is *empty* in XS.
`@(_DexFileForFastDev)`, in turn, is filled by the `_CompileFastDevDex` target:
<Target Name="_CompileFastDevDex" AfterTargets="_CompileDex">
Note that the `_CompileFastDevDex` target is NOT executed in the XS packaging output, and the only thing that would trigger it to run is the //Target/@AfterTargets attribute.
We can thus theorize that, perhaps, //Target/@AfterTargets should be AVOIDED by anything that is executed within Xamarin Studio.
If we fix `Xamarin.Android.Common.Debugging.targets` so that the `_BuildApkFastDev` target has additional dependencies:
classes.dex *is* present in the BuildApk task output, and it is present in the generated .apk.
Alas, the app still fails to launch. Investigation is ongoing.
PR is up https://github.com/xamarin/monodroid/pull/510 and ready to merge
Any workaround meanwhile? To have fast compilation and working app?
Fixed in monodroid/master/a07a63ab
@alex the only work around would be to hack the
as mentioned in comment 9.
But you still might hit the other error it mentions.
*** Bug 44480 has been marked as a duplicate of this bug. ***
*** Bug 44485 has been marked as a duplicate of this bug. ***
*** Bug 43241 has been marked as a duplicate of this bug. ***
I am able to reproduce this issue with the sample project in comment 1 and I also observed that this issue is fixed is build xamarin.android-7.0.99-120_d46688705d068fc89e1e315fa7bb932cfb70ea3c
Device Logs : https://gist.github.com/Mohit-Kheterpal/d14d8218cb4c52bbc97dc3cadf42fada
Hence closing this issue by marking it as Verified.
*** Bug 44704 has been marked as a duplicate of this bug. ***
*** Bug 44681 has been marked as a duplicate of this bug. ***
*** Bug 44439 has been marked as a duplicate of this bug. ***