Skip to content

Commit

Permalink
Merge pull request #841 from jonpryor/jonp-d15-4-fixes
Browse files Browse the repository at this point in the history
Cherry-pick fixes from master
  • Loading branch information
Aguilex authored Sep 11, 2017
2 parents 993f540 + b88b026 commit 0df2d9e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Mono.Android/java/mono/android/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ private Runtime ()
{
}

public static native void init (String lang, String[] runtimeApks, String runtimeDataDir, String[] appDirs, ClassLoader loader, String externalStorageDir, String[] assemblies, String packageName);
public static native void init (String lang, String[] runtimeApks, String runtimeDataDir, String[] appDirs, ClassLoader loader, String[] externalStorageDirs, String[] assemblies, String packageName);
public static native void register (String managedType, java.lang.Class nativeClass, String methods);
public static native void notifyTimeZoneChanged ();
public static native int createNewContext (String[] runtimeApks, String[] assemblies, ClassLoader loader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public static void LoadApplication (Context context, ApplicationInfo runtimePack
String cacheDir = context.getCacheDir ().getAbsolutePath ();
String dataDir = context.getApplicationInfo ().dataDir + "/lib";
ClassLoader loader = context.getClassLoader ();
java.io.File external0 = android.os.Environment.getExternalStorageDirectory ();
String externalDir = new java.io.File (
external0,
"Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath ();
String externalLegacyDir = new java.io.File (
external0,
"../legacy/Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath ();

Runtime.init (
language,
Expand All @@ -49,9 +56,10 @@ public static void LoadApplication (Context context, ApplicationInfo runtimePack
dataDir,
},
loader,
new java.io.File (
android.os.Environment.getExternalStorageDirectory (),
"Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath (),
new String[] {
externalDir,
externalLegacyDir
},
MonoPackageManager_Resources.Assemblies,
context.getPackageName ());

Expand Down
14 changes: 11 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Resources/MonoPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public static void LoadApplication (Context context, ApplicationInfo runtimePack
String cacheDir = context.getCacheDir ().getAbsolutePath ();
String dataDir = getNativeLibraryPath (context);
ClassLoader loader = context.getClassLoader ();
java.io.File external0 = android.os.Environment.getExternalStorageDirectory ();
String externalDir = new java.io.File (
external0,
"Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath ();
String externalLegacyDir = new java.io.File (
external0,
"../legacy/Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath ();

Runtime.init (
language,
Expand All @@ -49,9 +56,10 @@ public static void LoadApplication (Context context, ApplicationInfo runtimePack
dataDir,
},
loader,
new java.io.File (
android.os.Environment.getExternalStorageDirectory (),
"Android/data/" + context.getPackageName () + "/files/.__override__").getAbsolutePath (),
new String[] {
externalDir,
externalLegacyDir
},
MonoPackageManager_Resources.Assemblies,
context.getPackageName ());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ public void MergeLibraryManifest ()
android:authorities='${applicationId}.FacebookInitProvider'
android:name='.internal.FacebookInitProvider'
android:exported='false' />
<meta-data android:name='android.support.VERSION' android:value='25.4.0' />
<meta-data android:name='android.support.VERSION' android:value='25.4.0' />
</application>
</manifest>
", encoding: System.Text.Encoding.UTF8);
Expand Down Expand Up @@ -522,6 +524,8 @@ public void MergeLibraryManifest ()
"${applicationId}.FacebookInitProvider was not replaced with com.xamarin.manifest.FacebookInitProvider");
Assert.IsTrue (manifest.Contains ("com.xamarin.test.internal.FacebookInitProvider"),
".internal.FacebookInitProvider was not replaced with com.xamarin.test.internal.FacebookInitProvider");
Assert.AreEqual (manifest.IndexOf ("meta-data", StringComparison.OrdinalIgnoreCase),
manifest.LastIndexOf ("meta-data", StringComparison.OrdinalIgnoreCase), "There should be only one meta-data element");
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ void MergeLibraryManifest (string mergedManifest)
}
}

void RemoveDuplicateElements ()
{
var duplicates = doc.Descendants ()
.GroupBy (x => x.ToFullString ())
.SelectMany (x => x.Skip (1));
foreach (var duplicate in duplicates)
duplicate.Remove ();

}

IEnumerable<XNode> FixupNameElements(string packageName, IEnumerable<XNode> nodes)
{
foreach (var element in nodes.Select ( x => x as XElement).Where (x => x != null && ManifestAttributeFixups.ContainsKey (x.Name.LocalName))) {
Expand Down Expand Up @@ -838,6 +848,7 @@ public void Save (string filename)

public void Save (System.IO.TextWriter stream)
{
RemoveDuplicateElements ();
var ms = new MemoryStream ();
doc.Save (ms);
ms.Flush ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public static string[] GetPaths (this XDocument doc, params string[] paths)
e = e.Elements (p);
return e.Select (p => p.Value).ToArray ();
}

public static string ToFullString (this XElement element)
{
return element.ToString (SaveOptions.DisableFormatting);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<AndroidIncludeDebugSymbols>True</AndroidIncludeDebugSymbols>
</PropertyGroup>
</When>
<When Condition=" '$(EmbedAssembliesIntoApk)' == 'False' ">
<PropertyGroup>
<AndroidIncludeDebugSymbols>True</AndroidIncludeDebugSymbols>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<AndroidIncludeDebugSymbols>False</AndroidIncludeDebugSymbols>
Expand Down Expand Up @@ -1025,7 +1030,7 @@ because xbuild doesn't support framework reference assemblies.
</ReadLinesFromFile>
</Target>

<Target Name="_CreatePropertiesCache" DependsOnTargets="_ReadPropertiesCache">
<Target Name="_CreatePropertiesCache" DependsOnTargets="_SetupDesignTimeBuildForBuild;_ReadPropertiesCache">
<MakeDir Directories="$(IntermediateOutputPath)" Condition="!Exists('$(IntermediateOutputPath)')" />
<WriteLinesToFile
Condition="'@(_PropertiesCache)' != '@(_PropertyCacheItems)'"
Expand Down
4 changes: 2 additions & 2 deletions src/monodroid/jni/mono_android_Runtime.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/monodroid/jni/monodroid-glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ monodroid_get_system_property (const char *name, char **value)
#ifdef RELEASE
#define MAX_OVERRIDES 1
#else
#define MAX_OVERRIDES 2
#define MAX_OVERRIDES 3
#endif
static char* override_dirs [MAX_OVERRIDES];

Expand Down Expand Up @@ -410,6 +410,7 @@ get_primary_override_dir (JNIEnv *env, jstring home)

static char *primary_override_dir;
static char *external_override_dir;
static char *external_legacy_override_dir;

static void
create_update_dir (char *override_dir)
Expand Down Expand Up @@ -651,6 +652,7 @@ get_libmonosgen_path ()
// external storage locations so we need to file copy the shared object to an internal
// storage location before loading it.
copy_monosgen_to_internal_location (primary_override_dir, external_override_dir);
copy_monosgen_to_internal_location (primary_override_dir, external_legacy_override_dir);

int i;
for (i = 0; i < MAX_OVERRIDES; ++i)
Expand Down Expand Up @@ -2512,6 +2514,7 @@ get_ds2_path ()
for (i = 0; i < sizeof (gdbservers)/sizeof (gdbservers [0]); ++i) {
file = monodroid_strdup_printf ("%s", gdbservers [i]);
copy_file_to_internal_location (primary_override_dir, external_override_dir, file);
copy_file_to_internal_location (primary_override_dir, external_legacy_override_dir, file);
free (file);
}

Expand Down Expand Up @@ -3893,7 +3896,7 @@ create_and_initialize_domain (JNIEnv* env, jobjectArray runtimeApks, jobjectArra
}

JNIEXPORT void JNICALL
Java_mono_android_Runtime_init (JNIEnv *env, jclass klass, jstring lang, jobjectArray runtimeApks, jstring runtimeNativeLibDir, jobjectArray appDirs, jobject loader, jstring externalStorageDir, jobjectArray assemblies, jstring packageName)
Java_mono_android_Runtime_init (JNIEnv *env, jclass klass, jstring lang, jobjectArray runtimeApks, jstring runtimeNativeLibDir, jobjectArray appDirs, jobject loader, jobjectArray externalStorageDirs, jobjectArray assemblies, jstring packageName)
{
char *runtime_args = NULL;
char *connect_args;
Expand Down Expand Up @@ -3923,9 +3926,13 @@ Java_mono_android_Runtime_init (JNIEnv *env, jclass klass, jstring lang, jobject
setup_environment (env, runtimeApks);

primary_override_dir = get_primary_override_dir (env, (*env)->GetObjectArrayElement (env, appDirs, 0));
esd = (*env)->GetStringUTFChars (env, externalStorageDir, NULL);
esd = (*env)->GetStringUTFChars (env, (*env)->GetObjectArrayElement (env, externalStorageDirs, 0), NULL);
external_override_dir = monodroid_strdup_printf ("%s", esd);
(*env)->ReleaseStringUTFChars (env, externalStorageDir, esd);
(*env)->ReleaseStringUTFChars (env, (*env)->GetObjectArrayElement (env, externalStorageDirs, 0), esd);

esd = (*env)->GetStringUTFChars (env, (*env)->GetObjectArrayElement (env, externalStorageDirs, 1), NULL);
external_legacy_override_dir = monodroid_strdup_printf ("%s", esd);
(*env)->ReleaseStringUTFChars (env, (*env)->GetObjectArrayElement (env, externalStorageDirs, 1), esd);

init_categories (primary_override_dir);
create_update_dir (primary_override_dir);
Expand All @@ -3937,6 +3944,7 @@ Java_mono_android_Runtime_init (JNIEnv *env, jclass klass, jstring lang, jobject

#ifndef RELEASE
override_dirs [1] = external_override_dir;
override_dirs [2] = external_legacy_override_dir;
for (i = 0; i < MAX_OVERRIDES; ++i) {
const char *p = override_dirs [i];
if (!directory_exists (p))
Expand Down

0 comments on commit 0df2d9e

Please sign in to comment.