Граф коммитов

353 Коммитов

Автор SHA1 Сообщение Дата
Atsushi Eno cac0f33f23 [Xamarin.Android.Build.Tasks] Support updated DroidDoc (#274)
* [Mono.Android] update API description with the latest class-parse output.

It seems to add java.util.Hashmap#put() override, which does not affect
the public API.

* [Mono.Android] add API Level 25 description.

Since there is no documentation component yet, it is actually generated
with API Level 24 docs, so it lacks parameter names for newly added
abstract methods that class-parse cannnot extract. But there is only one
method that falls to the issue.

* [msbuild] add new droiddoc related arguments in ClassParse task.

Note that this task is not functional enough to support javadocs correctly
as it does not distinguish doclet type while it pretends to be able to.
2016-10-21 14:15:06 -04:00
Radek Doulik 875e3488c7 [Xamarin.Android.Build.Tasks] Cleanup PreserveTlsProvider (#272)
- removed unused methods

 - process only System assembly, because we are looking just for
   Mono.Net.Security.MonoTlsProviderFactory.CreateDefaultProviderImpl
   method
2016-10-21 11:42:15 -04:00
Jonathan Pryor 8207b2c2d2 [Mono.Android] Include the Android.Service.Quicksettings.TileState type (#271)
Commit 25663510 overlooked adding the `TileState` enum type to the
`Mono.Android.dll` build, meaning that the
`Android.Service.Quicksettings.TileState` type wasn't present in the
resulting assembly.

Add the `Android.Service.Quicksettings.TileState` enum to the build.
2016-10-18 23:39:44 +09:00
Radek Doulik a6a31d98c8 Merge pull request #266 from xamarin/work-linker-pr
[Xamarin.Android.Build.Task]: Add linker support to select the TLS Provider
2016-10-18 16:28:03 +02:00
Atsushi Eno a967b24cf3 [msbuild] support custom proguard via ProguardToolPath for multidex etc. (#267)
We had ProguardToolPath and it could be used for custom proguard tools,
which should be useful if we want to support Java8 based libraries which
doesn't work with the one in Android SDK. In theory.

In fact, it was not sufficient because proguard is also used by multidex.
To support multidex, we have to generate correct mainDexClasses rules
that should depend on Android SDK path, not proguard.

To support custom proguard, we need PROGUARD_HOME environment variable
in mainDexClasses(.bat). That actually uncovered another issue we had:
we were using ToolTask.EnvironmentOverride which is [Obsolete] and
converts every entry to lowercase, which can work on Windows but not
elsewhere i.e. even if we had PROGUARD_HOME, it became proguard_home(!)
Therefore we use ToolTask.EnvironmentVariables instead from now on.

Due to xbuild property parser issue, it differentiates MSBuild on
Windows and xbuild elsewhere to give some additional env. variables.
2016-10-17 14:51:53 -04:00
Jo Shields eb45485f10 [build] Detect Flatpak, and don't use lsb_release if we're sandboxed. (#268) 2016-10-17 14:15:01 -04:00
Atsushi Eno d481b4de40 [Mono.Android] update API xml based on current class-parse + api-xml-adjuster (#260)
There were non-breaking API definition files changes caused by
https://github.com/xamarin/java.interop/pull/94

This update reflects the changes.

Additionally, the pre-API-24 API descriptions were generated by
`jar2xml`, not `class-parse`, which generated extraneous
generic constraints. Update all API descriptions to be generated by
`class-parse` and `api-xml-adjuster`.
2016-10-14 10:50:27 -04:00
Marek Habersack 17bdeb38cf [monodroid] Get network information from Java (#261)
With Android 7.0 (Nougat) it is no longer possible to read some
information about network interfaces from the /sys filesystem. Google
placed restrictions on two files used by the Mono BCL to read
information about the interface:

  /sys/class/net/[DEVICE]/flags
  /sys/class/net/[DEVICE]/operstate

The information we used to read from `flags` let us determine whether
the interface supports multicast and the `operstate` file provided us
with detailed information on the current device state.

Additionally, it is now impossible to read the hardware MAC address used
by any interface. This bit of information is also unavailable when using
the Java APIs and therefore applications running on devices with API
24 (and possibly newer) will not be able to access this information.

More details about the issue are available from the upstream Android
bug:

  https://code.google.com/p/android/issues/detail?id=205565

In order to obtain the required information, we now need to use the Java
APIs on devices with API 24+ and this commit implements the backend to
retrieve this information. It is done in C in order to avoid overhead of
creating mirror .NET objects when calling Java, thus saving time and
memory during an operation which may be performed by some applications
quite frequently.

Part of fix for https://bugzilla.xamarin.com/show_bug.cgi?id=44296
2016-10-14 10:37:50 -04:00
Bernhard Urban 53fd09bb54 [monodroid] Move mono.android.GCUserPeer loading to JNI_OnLoad()
The Bridgeless SCC support (commit 70807523) requires the
`mono.android.GCUserPeer` type to work, which is a type located within
`classes.dex`.

On the main/UI/startup thread, `JNIEnv::FindClass()` uses a
`ClassLoader` that will find types located within `classes.dex`. Other
threads do *not*. Other threads...such as mono's GC thread.

Unfortunately, this means that the `JNIEnv::FindClass()` use within
`gc_prepare_for_java_collection()` -- called from the mono GC thread
-- would always return `NULL`, with a pending exception, which would
cause the process to exit with an untimely death:

	F/art     : art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION:
	JNI GetMethodID called with pending exception java.lang.ClassNotFoundException:
	Didn't find class "mono.android.GCUserPeer" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

Move the `JNIEnv::FindClass()` lookup for `mono.android.GCUserPeer`
into `JNI_OnLoad()`, which *is* invoked on the UI thread, and thus
*can* find the `mono.android.GCUserPeer` type. This avoids the error.
2016-10-13 11:36:51 -04:00
Marek Habersack 14fb09177e [Mono.Android] Assign AndroidHttpResponseMessage fields properly (#264)
Code failed to assign the class fields from constructor parameters. Make
sure the fields are assigned to properly.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=45311
2016-10-13 11:02:27 -04:00
Dean Ellis dc5488ac4b [Xamarin.Android.Build.Tasks] Error executing task ResolveAssemblyReference: Path is empty (#265)
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=44528

Something changed between C6 and the current master of xbuild or mono.
Before adding a reference like so

	<Reference Include="Foo.dll" />

used to work without any issues. Now we get the following

	Error executing task ResolveAssemblyReference: Path is empty

This is because xbuild seems to interogate the path from the reference
and it gets an empty string. But apprarently this is a problem.

This commit adds a call to Path.GetFullPath when resolving the assemblies
to work around this problem.
2016-10-13 10:59:35 -04:00
Martin Baulig bc9d5ad197 [Xamarin.Android.Build.Task]: Add linker support to select the TLS Provider.
* Bump Mono to mono-4.8.0-branch commit 90699022b6fed7fd273ba3379a2e3696bbd8956f.

* Add new PreserveTlsProvider step, which rewrites MonoTlsProviderFactory.CreateDefaultProviderImpl()
  to only include the selected TLS Provider.

* Added 'TlsProviderType' to <LinkAssemblies>.
2016-10-13 16:32:46 +02:00
Atsushi Eno 25663510be [Mono.Android] fix incorrect Tile enum type. (#262)
The consts should have been mapped to `Android.Service.QuickSettings`,
not `Android.Service.Quicksettings`.
2016-10-12 10:53:18 -04:00
Dean Ellis 752a25f3a0 [Xamarin.Android.Build.Tasks] State Error CS0117 'Resource.Attribute' does not contain a definition for 'actionBarSize' (#252)
Context https://bugzilla.xamarin.com/show_bug.cgi?id=39910

Under certain circumstances users can end up in a situation
where the Resource.Designer.xx file being generated will NOT
compile. This is normally down to a miss match between Nuget
packages like Xamarin.Forms and Android.Support libraries. It
is possible to have incpmpatible versions of Xamarin.Forms
(or other third party library like ZXing) which contain references
in the Resource.Designer.xx which DO NOT exist in the main application.

As a result when the code generator emits the code to set the field values
like

	global::ZXing.Mobile.Resource.Id.contentFrame = global::Bug39910Repro.Droid.Resource.Id.contentFrame;

you can get into a situation where "contentFrame" does NOT exist in
the app (in this case Bug39910Repro) Id class. This results in a
compilation error CS0117.

This commit makes sure the compilation error is removed by checking
that the target type exists before emitting the code. If the type does
NOT exist we will emit a Warning XA0106 which will inform the user
they might have a problem with the Nuget versions.

While this might not be ideal as it may result in runtime issues. It
seems to be preferable to compilation errors that stop a user completely.
Possible runtime issues might be errors in the android app because certain
resource id's do not exist or refer to different resources.
2016-10-11 14:39:14 -04:00
Jonathan Pryor b620689ddf [Mono.Android] Generate AssemblyInformationalVersionAttribute (#259)
`Mono.Android.dll` is [supposed to contain][0] an
[`AssemblyInformationalVersionAttribute`][1] `assembly:`-level
attribute which contains the version number, git commit, and various
other bits of information related to which commit `Mono.Android.dll`
"came from."

	var attrs = (System.Reflection.AssemblyInformationalVersionAttribute[])
		typeof (Java.Lang.Object)
		.Assembly
		.GetCustomAttributes(typeof(System.Reflection.AssemblyInformationalVersionAttribute), inherit: true);
	string version = attrs [0].InformationalVersion;
	// version is like "7.0.99.113; git-rev-head:d02845e; git-branch:master"

Unfortunately, in the open-source migration this was lost, and the
above code would throw an `IndexOutOfRangeException`, as
`attrs.Length` would be 0. (Xamarin.Android 7.0 likewise doesn't
contain the `AssemblyInformationalVersionAttribute`. Oops!)

Add `<GitBlame/>`, `<GitCommitsInRange/>`, and
`<ReplaceFileContents/>` tasks, along with various bits of MSBuild-fu,
to use `src/Mono.Android/Properties/AssemblyInfo.cs.in` as a
"template" for the `AssemblyInfo.cs` to include in the
`Mono.Android.dll` build, so that an appropriate
`AssemblyInformationalVersionAttribute` value is present.

[0]: https://developer.xamarin.com/releases/android/xamarin.android_4/xamarin.android_4.14/#Xamarin.Android_4.14.0
[1]: https://msdn.microsoft.com/en-us/library/system.reflection.assemblyinformationalversionattribute(v=vs.110).aspx
2016-10-11 16:51:19 +02:00
Jonathan Pryor a61abd0e9a Bump to mono/mono-4.8.0-branch/9c029cc9 (#256)
Hopefully this will fix the Linux/Jenkins build.
2016-10-10 15:38:10 +02:00
Marek Habersack d198cfd5d5 Code formatting change
Change formatting of the previous commit so that it adheres
to the Mono coding guidelines (http://www.mono-project.com/community/contributing/coding-guidelines/#style-guidelines)
2016-10-10 13:53:46 +02:00
Samuel Debruyn 5055a209de poll CancellationToken for IsCancellationRequested in AndroidClientHandler (#258) 2016-10-10 13:51:58 +02:00
Dean Ellis 3fe80c5269 [Xamarin.Android.Build.Tasks] Remove System modal windows (#257)
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=43287

Most of the ProcessStartInfo instances did NOT include

	CreateNoWindow=true
	WindowStyle=ProcessWindowStyle.Hidden

As a result on windows at least developers would see a
DOS prompt pop up during the build process. This is very
distracting. This commit fixes up the various uses to include
the new properties
2016-10-07 11:07:52 -04:00
Atsushi Eno 186650b634 [Mono.Android] update API xml based on current class-parse + api-xml-adjuster. (#255)
api-24.xml.in was already generated with the almost latest tools,
but it has some new members probably due to android.jar updates.

Others were generated by old tools so they had extraneous generic
constraints.
2016-10-06 14:50:14 -04:00
Atsushi Eno 7f58517e57 [Mono.Android] Simplify merge.SourceFile matching (#254)
Our internal build should switch more to this OSS repo and this file
has to give more love on the other land...
2016-10-06 13:57:36 -04:00
Dean Ellis 4aad112527 [Xamarin.Android.Build.Utilities] Look within FlatPak search paths (#41) (#243)
Add `/app/lib/mandroid` to directory search paths for FlatPak support.
2016-10-05 16:05:41 -04:00
Dean Ellis 0cbfd992c3 [Xamarin.Android.Build.Tasks] Possible memory leak of whole Task chain for SDK resolving (#251)
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=45018

The MSBuild Tasks setting the AndroidLogger event handlers were
not cleaning them up afterwards. This is not a problem on the
Command Line or in VS since the build Tasks are disposed of
once the build is complete. Or at least is appears to do so
in VS.

However in XS the entire build structure thing is kept in
memory. This appears to suggest that the event handers are
not removed and are constantly being set. Which in turn would
probably produce a memory leak.

This commit reworks the two Tasks which use these event handlers to
remove them after the task has completed.
2016-10-05 16:05:24 -04:00
Atsushi Eno edff3608ae [Mono.Android] mark Manifest.permission class as non-obfuscated explicitly. (#249)
This will be required once generator changes for obfucation marking lands.
2016-10-05 15:53:54 -04:00
Dean Ellis 865ef7ce3e [Xamarin.Android.Build.Tasks] Add new Helper method for MonoAndroidHelper. (#248)
We want to be able to add just callback to the AndroidLogger, not just
hardcode it to only take an MSBuild TaskLogger. This commit adds a new
method which takes MessageHandler's for each of the event handlers
available on the AndroidLogger. This will allow us to just provide
Lambda expressions for the events.
2016-10-04 15:35:40 -04:00
Marek Habersack 2c02bcf1f4 [Mono.Android] Don't perform Java net access on main thread (#247)
It appears that sometimes calling .ResponseCode on an instance
of the Java class HttpURLConnection will trigger network activity
and if the AndroidHttpCliendHandler was invoked on the main thread,
the activity will take place there as well and that causes Android
to throw the NetworkOnMainThreadException.

Wrap the offending code in a task to avoid the exception.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=44961
2016-10-03 14:39:13 -04:00
Radek Doulik a85d49dbaa add PreserveHttpAndroidClientHandler substep (#234)
- this should make $(AndroidHttpClientHandlerType) survive linking

 - it is used by settting msbuild property
   AndroidHttpClientHandlerType to the http client handler type name
   (could be assembly qualified). the linker then doesn't strip
   related parts. if everything work as it should then you will not
   see this in the adb logcat:

    I mono-stdout: Xamarin.Android returned no custom HttpClientHandler. Defaulting to System.Net.Http.HttpClientHandler

 - also see
   https://developer.xamarin.com/releases/android/xamarin.android_6/xamarin.android_6.1/#Native_HttpClientHandler
2016-09-30 23:02:26 -04:00
Martin Baulig 53bcf69f91 [msbuild]: Add TLS Provider selection for BTLS.
* Tasks/BuildApk.cs: Add 'TlsProvider' parameter.

* Xamarin.Android.Common.targets: Add <AndroidTlsProvider> property
  and pass it to BuildApk.

Add this to your .csproj file to select the TLS Provider.  Valid
values are "legacy" and "btls".

We now add a new 'XA_TLS_PROVIDER' environment variable to the .apk,
which is read by System/Mono.Net.Security/MonoTlsProviderFactory.Droid.cs
to select the TLS Provider.

Linker support (to eliminate the unused provider, similar to how it's
already done in xamarin-macios) is coming shortly.
2016-09-30 16:19:31 +02:00
Martin Baulig bae8737991 [Mono.Android]: Add AndroidEnvironment.CertStoreLookup().
This callback method will be used by BTLS's certificate validation
to lookup trusted CA certificates from the user's trust store.
2016-09-30 16:19:31 +02:00
Martin Baulig c307d47ac2 Merge pull request #245 from xamarin/work-btls-android
Bump Mono to mono-4.8.0-branch commit 9e46b5744b93bcc0bc36ab9d957a5510aaeabf1f.

This includes the managed BTLS sources.
2016-09-30 15:41:12 +02:00
Martin Baulig faf23f0255 Bump Mono to pickup the build fix. 2016-09-30 15:18:44 +02:00
Martin Baulig 02b920a934 Bump Mono again to pickup the BTLS landing commit. 2016-09-30 14:46:45 +02:00
Martin Baulig ddd3499190 Merge pull request #244 from xamarin/work-btls-landing
Bump Mono to build with the native BTLS sources
2016-09-30 14:44:51 +02:00
Martin Baulig cebc6c8347 [build]: Make it build with the native BTLS sources.
We need to pass '--with-btls-android-ndk=$(AndroidToolchainDirectory)\ndk'
to Mono's configure to tell cmake where to find the Android NDK.
2016-09-30 14:15:41 +02:00
Martin Baulig 9d4874b113 Bump Mono to mono-4.8.0-branch commit b4b21d081b03318a07e3ae2220b365b79e1fcec8.
commit b4b21d081b03318a07e3ae2220b365b79e1fcec8
Author: Martin Baulig <martin.baulig@xamarin.com>
Date:   Fri Sep 30 11:46:46 2016 +0200

    [BTLS]: Add the native BTLS sources.

    (cherry picked from commit c950be01aca0ecce9b5f68b9f4430e99ecc51037)
2016-09-30 11:54:20 +02:00
Radek Doulik 7ddd238a54 [Xamarin.Android.Build.Tasks] Dispose TypeNameMapGenerator instances (#242)
- so that following tasks will not run into stream sharing
   (violation) issues as in #44529

 - bump Java.Interop to get:

    commit 40b75e9c4b7b986f3bb31254a4aab3d60e0ef74e
    Author: Radek Doulik <radekdoulik@users.noreply.github.com>
    Date:   Wed Sep 28 21:25:26 2016 +0200

        [Java.Interop.Tools.JavaCallableWrappers] Add TypeNameMapGenerator.Dispose() (#91)
2016-09-29 11:58:43 -04:00
Zoltan Varga 684c050408 [monodroid] Support timestamp in debug.mono.gdb property (#229)
* [libmonodroid] Add support for waiting for a native debugger to attach.

When the `debug.mono.gdb` property is set to `wait:<timestam>`,
libmonodroid will wait in a loop for the native debugger to attach.
The debugger can set the `monodroid_gdb_wait` C variable to `0`
to break the wait after attaching.

This is useful to support use cases where the debugger attaches to
the process after it starts instead of the debugger being started by
libmonodroid.

The startup sequence should be:

1. Set system properties:

        $ adb shell setprop debug.mono.gdb wait:`date +%s`
    
2. Launch the app:

        $ adb shell am startup ...

3. Start the debugger

4. Attach to the process

5. Clear the `monodroid_gdb_wait` variable:

        (gdb) p monodroid_gdb_wait=0
2016-09-28 15:35:48 -04:00
Dean Ellis b1c92cdb04 [Xamarin.Android.Build.Tasks] Fix `classes.dex` deployment. (#236)
Context https://bugzilla.xamarin.com/show_bug.cgi?id=44633

Enabling <AndroidUseSharedRuntime> in some projects causes
`classes.dex` to not deploy to device.

For some bizzare reason when running a build vs XS the
AfterTargets are NOT being called for _CompileDex. As a
result the targets that need to be called to support
debugging are not being run.

This commit adds a bunch of new property extension points
which will allow the debugging targets to inject the
additonal target requirements directly rather than relying
on Before/After targets.
2016-09-28 15:28:15 -04:00
Atsushi Eno 787785647a [Mono.Android] AtomicInteger shouldn't have And* properties (#240)
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=44391

`java.util.concurrent.atomic.AtomicInteger.getAndDecrement()` is
bound as the `AtomicInteger.AndDecrement` property, which is "weird".
Similarly, `AtomicLong.getAndDecrement()` is bound as the
`AtomicLong.AndDecrement` property.

Fix the `AtomicInteger` and `AtomicLong` types so that the
`AndDecrement` and `AndIncrement` properties are `[Obsolete]`,
with "proper" method bindings of `GetAndDecrement()` and
`GetAndIncrement()`.

Additionally, `metadata` had wrong relative path specification
which broke our internal "monodroid" build, so correct them.
2016-09-28 12:48:18 -04:00
Radek Doulik 453a80da76 [Xamarin.Android.Build.Tasks] StripEmbeddedLibraries and ReadWrite (#239)
[Xamarin.Android.Build.Tasks] StripEmbeddedLibraries and ReadWrite

Fixes part of: https://bugzilla.xamarin.com/show_bug.cgi?id=44529

When running the `<StripEmbeddedLibraries/>` task, an `IOException`
may be thrown:

	Error executing task StripEmbeddedLibraries: System.IO.IOException: Sharing violation on path .../obj/Release/linksrc/Xamarin.Android.NUnitLite.dll
	  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0025f] in <253a3790b2c44512bbca8669ecfc1822>:0
	  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <253a3790b2c44512bbca8669ecfc1822>:0
	  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
	  at Mono.Cecil.ModuleDefinition.GetFileStream (System.String fileName, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00007] in :0
	  at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00007] in :0
	  at Mono.Cecil.AssemblyDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00001] in :0
	  at Xamarin.Android.Tasks.StripEmbeddedLibraries.Execute () [0x0034a] in <3d5202a5d4874a76a99388021bf1ab1a>:0

This was caused as part of commit 1d658252, which bumped us to
Cecil 0.10.0-beta1-v2, in which `AssemblyDefinition` now holds a
`Stream` to the file that was opened, instead of being a purely
in-memory construct, which was the case in Cecil 0.9.x.

Because `AssemblyDefinition` held a `Stream` to the source assembly,
calling `AssemblyDefinition.Write(string, WeriterParameters)` would
attempt to *re-open* the file for writing, which resulteed in the
above `IOException`.

Fix this by telling `DirectoryAssemblyResolver` to open all
assemblies as read/write and using the
`AssemblyDefinition.Write(WriterParameters)` overload, so that
`AssemblyDefinition` re-uses the existing `Stream` to write the file.
2016-09-27 15:06:47 -04:00
Jonathan Pryor 6cfe2a3ee8 [build] Fix build caching, Xamarin Studio `libzip.mdproj` issues (#237)
[The Jenkins build isn't using the bundle file][0]:

	Target _BuildUnlessCached needs to be built as output file '../../bin/Debug//lib/xbuild-frameworks/MonoAndroid/v1.0/Mono.Cairo.dll' does not exist.

Another day, another "How did that ever work?!"

In particular, `Mono.Cairo.dll` was *never* built for the
Xamarin.Android profile, so *seriously*, how did the mono bundle,
"fixed" in 10b1c2a4, *actually work*?

Not only is `Mono.Cairo.dll` not built for the "monodroid" profile,
`SMDiagnostics.dll` is no longer built for MOBILE configurations
either.

Remove `Mono.Cairo.dll` and `SMDiagnostics.dll` from
`@(MonoProfileAssembly)`, which should allow the bundle to be used.

Xamarin Studio doesn't like `build-tools/libzip/libzip.mdproj`: it
refuses to load the project, stating:

> Invalid configuration mapping

This isn't a particularly helpful error. The *actual* issue is that
Xamarin Studio requires that an MSBuild project have
`<PropertyGroup/>`s with `Condition` attributes which correspond to a
"known" configuration. *It doesn't matter* that, in the case of
`libzip.mdproj`, *all* configurations use the same `$(OutputPath)`
property value, we still need separate Debug and Release configuration
sections in order to appease the Xamarin Studio masters.

[0]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/101/consoleText
2016-09-27 10:30:57 +09:00
Bernhard Urban fa61551b90 [Xamarin.Android.Build.Tasks] `Dispose()` the assembly and open as `ReadWrite` (#235) 2016-09-26 14:00:09 -04:00
Jonathan Pryor 16d65fab5e [Xamarin.Android.Build.Tasks] Dispose DirectoryAssemblyResolver instances (#233)
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=44529

Commit 1d658252 bumped to Cecil 0.10.0-beta1-v2 and
Java.Interop/a1d3ecc8, which likewise uses Cecil 0.10.0-beta1-v2.

Among the various API changes in Cecil 0.10.x vs. Cecil 0.9.x is a
change to `Mono.Cecil.IAssemblyResolver`, implemented by
`Java.Interop.Tools.Cecil.DirectoryAssemblyResolver`, to implement the
`IDisposable` interface.

Java.Interop/a1d3ecc8 added a `DirectoryAssemblyResolver.Dispose()`
method, but this method didn't *do* anything.

Cecil 0.10.0-beta1-v2 also has a *semantic* change vs. Cecil 0.9.x:
`AssemblyDefinition` is no longer a "purely in-memory" construct.
Instead, it holds a `System.IO.Stream` to the assembly it's reading
(unless `Mono.Cecil.ReaderParameters.InMemory` is `true`).

This semantic change means that an assembly can't be read from and
written to at the same time via different mechanisms, so long as there
is an `AssemblyDefinition` instance to that file.

Which brings us to (private) Bug #44529, in which an `IOException` is
thrown from the `<StripEmbeddedLibraries/>` task:

	Error executing task StripEmbeddedLibraries: System.IO.IOException: Sharing violation on path .../obj/Release/linksrc/Xamarin.Android.NUnitLite.dll
	  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0025f] in <253a3790b2c44512bbca8669ecfc1822>:0
	  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <253a3790b2c44512bbca8669ecfc1822>:0
	  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
	  at Mono.Cecil.ModuleDefinition.GetFileStream (System.String fileName, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00007] in :0
	  at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00007] in :0
	  at Mono.Cecil.AssemblyDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00001] in :0
	  at Xamarin.Android.Tasks.StripEmbeddedLibraries.Execute () [0x0034a] in <3d5202a5d4874a76a99388021bf1ab1a>:0

The underlying cause of the `IOException` is twofold:

1. `AssemblyDefinition` instances now hold a `FileStream` to the file
    they're reading from (and optionally writing to), and this
    `FileStream` will be kept open until
    `AssemblyDefinition.Dispose()` is called.

2. Nothing in `Xamarin.Android.Build.Tasks` calls
    `AssemblyDefinition.Dispose()`.

Nor should anything in `Xamarin.Android.Build.Tasks` call
`AssemblyDefinition.Dispose()`! (Almost) All `AssemblyDefinition`
instances are *cached* within `DirectoryAssemblyResolver` instances,
and nothing calls `DirectoryAssemblyResolver.Dispose()` either!
(Not that this matters *too* much, becuase
`DirectoryAssemblyResolver.Dispose()` is currently a no-op.)

There is no sane reasoning here: so long as we're using
`DirectoryAssemblyResolver`, we're going to have more files open
(compared to when Cecil 0.9.x was used), which can result in file
sharing problems and the above `IOException`.

The way foward is:

1. `Java.Interop.Tools.Cecil.DirectoryAssemblyResolver` needs to be
    updated so that
    [`DirectoryAssemblyResolver.Dispose()` is useful][0], i.e. that it
    will `Dispose()` of all held `AssemblyDefinition` instances.

2. Bump to Java.Interop/084e9f7f to pick up (1).

3. `Xamarin.Android.Build.Tasks.dll` needs to be updated so that
    `DirectoryAssemblyResolver.Dispose()` is used.

4. All code, in particular `Xamarin.Andorid.Build.Tasks.dll`, needs to
    be reviewed to ensure it doesn't do anything "stupid" with
    `AssemblyDefinition` instances and/or `DirectoryAssemblyResolver.`

    Examples of "stupid" things include:

    * `Dispose()`ing of the return value from
      `DirectoryAssemblyResolver.Load()`:

            resolver.Load (assemblyName).Dispose();

    * Treating `AssemblyDefinition` instances in a manner inconsistent
      with how `DirectoryAssemblyResolver` loads them.
      `DirectoryAssemblyResolver` will be getting a new constructor
      overload which takes an `Mono.Cecil.ReaderParameters` parameter;
      the default will be the default Cecil behavior, which is for
      read-only behavior. Thus, trying to use the `AssemblyDefinition`
      in a "write" context will fail:

            var r = new DirectoryAssemblyResolver (...);
            var a = r.Load (assemblyName);
            a.Write ();   // BOOM

[0]: https://github.com/xamarin/java.interop/pull/88
2016-09-26 15:07:52 +01:00
Dean Ellis 9187b4d015 Bump to LibZipSharp/ea6809ba to fix a file locking issue (#232)
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=44184
2016-09-23 11:57:35 -04:00
Dean Ellis 4effe072f5 [Xamarin.Android.Build.Tasks] Symbolication uses $(MonoSymbolArchive) (#227)
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=44447

"Xamarin.Android uses AndroidManagedSymbols to control whether an mSYM
is
produced. Since it's disabled by default, it needs a property in the
project file to enable it, so affects templates too.

This does not match the final spec, which uses a MonoSymbolArchive
property instead. MonoSymbolArchive should default to true for
symbolicatable, releaseable builds - i.e. when there are debug symbols
and the shared runtime is not in use.

Basically, users shouldn't have to ever see MonoSymbolArchive in their
csproj, it only exists in case users need to disable it. This also means
that existing projects will get symbols."

This commit changes the AndroidManagedSymbols over to use the
newer MonoSymbolArchive naming. It also adds logic to detect when this
should be enabled. Namely when

	MonoSymbolArchive is blank
	AndroidUseSharedRuntime is False
	EmbedAssembliesIntoApk is True
	DebugSymbols is True
	DebugType is PdbOnly

We still fallback to setting MonoSymbolArchive to False if
we still do not have a value after evaluating all of those
properties.
2016-09-23 11:55:59 -04:00
Martin Baulig 24f2aec113 Remove Mono.Security.Providers.*.dll from the build.
These have been removed from the BCL.  See
https://github.com/mono/mono/pull/3595 and
https://github.com/xamarin/xamarin-macios/pull/865.
2016-09-22 07:33:06 +02:00
Jérémie Laval 7f9a11409c [jni] Refresh current domain after attaching thread to runtime when registering types. (#228)
Change triggered by https://bugzilla.xamarin.com/show_bug.cgi?id=44448

It's possible for the register call to be called on a thread that hasn't been registered with Mono
yet. As such, the `mono_domain_get` call will return NULL until `mono_jit_thread_attach` is invoked where
domain information for the current thread becomes correct.

This is an issue because it means we invoke `monodroid_runtime_invoke` passing NULL as a bogus domain
argument. This caused a crash with `mono_domain_set` as it doesn't support being passed a NULL domain.

This commit solves the problem by re-requesting the current domain after the `mono_jit_thread_attach`
call. If the thread had been registered beforehand, this will essentially be a no-op as it should return
the same domain again. If it hadn't, attaching the thread will have set the current domain to be the
root appdomain which will be returned by `mono_domain_get` making our current domain variable now valid.
2016-09-19 14:41:00 -04:00
Dean Ellis 9e47956bcc [Xamarin.Android.Build.Tasks] Remove Quotes from <MakeDir/> call (#226)
Turns out that the MSbuild task MakeDir handles quotes on
paths already. So there is no need to add them manually when
passing in a list of directories.

This also fixes the following error

	Unable to create directory ""bin\Release\App84.App84.apk.mSYM"".
Illegal characters in path.
2016-09-19 09:56:10 -04:00
Bernhard Urban ae9cd2b352 Revert "Revert "[MakeBundleNativeCodeExternal] pass `--i18n` to `mkbundle`"" (#225)
This reverts commit 08ff8ba9.

Since we to mono 4.8, this is needed in order to make
`_BuildApkEmbed` work again.

See also: https://github.com/xamarin/xamarin-android/pull/178
2016-09-19 09:55:18 -04:00
Marek Habersack 3e41c40046 Bump LibZipSharp to fix UTF-8 encoding conversion (#224)
Fixes bug https://bugzilla.xamarin.com/show_bug.cgi?id=44268
2016-09-16 14:02:57 +01:00