Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/*
WARNING: Do NOT Modify! Changes will be overwritten by the OneSignal plugin.
*/

apply plugin: 'com.android.library'

android {
namespace 'com.onesignal.onesignalsdk'

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
Expand All @@ -9,16 +15,16 @@ android {

def unityLib = project(':unityLibrary').extensions.getByName('android')

defaultConfig {
defaultConfig {
consumerProguardFiles "consumer-proguard.pro"
minSdkVersion unityLib.defaultConfig.minSdkVersion.mApiLevel
targetSdkVersion unityLib.defaultConfig.targetSdkVersion.mApiLevel
}
}

compileSdkVersion unityLib.compileSdkVersion
buildToolsVersion unityLib.buildToolsVersion

lintOptions {
abortOnError false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.IO;
using UnityEditor;

namespace OneSignalSDK {

[InitializeOnLoad]
sealed class MigrateAndroidResources {
static MigrateAndroidResources() {
UpdateBuildDotGradleContains();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with our Unity SDK process, is my understanding below correct?

  1. I don’t see where this new class is being called, so this class is automatically initialized due to InitializeOnLoad ?

  2. The main logic effectively takes the contents that is in com.onesignal.unity.android/Editor/OneSignalConfig.androidlib/build.gradle and replaces the contents in the file OneSignalExample/Assets/Plugins/Android/OneSignalConfig.androidlib/build.gradle , for example, if they are different. This is because the file OneSignalExample/Assets/Plugins/Android/OneSignalConfig.androidlib/build.gradle is automatically generated and consumers wouldn’t manipulate this file themselves, but this file may not automatically update when com.onesignal.unity.android/Editor/OneSignalConfig.androidlib/build.gradle changes. Hence, why we need to do this migration step to save the client a hassle and questions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, the [InitializeOnLoad] means Unity will call the static constructor in a few scenarios; A. the SDK is added; B. The SDK is updated;
  2. Correct

}

/// <summary>
/// Updates Assets/Plugins/Android/OneSignalConfig.androidlib/build.gradle
/// with contains provided by OneSignal-Unity-SDK 5.1.13.
/// Includes compatibility with Unity 6, as it's Gradle version has new
/// requirements.
/// </summary>
private static void UpdateBuildDotGradleContains() {
if (!Directory.Exists(ExportAndroidResourcesStep._pluginExportPath))
return;

string exportedFilename = Path.Combine(
ExportAndroidResourcesStep._pluginExportPath,
"build.gradle"
);
string exportedContains = File.ReadAllText(exportedFilename);

string packageFilename = Path.Combine(
ExportAndroidResourcesStep._pluginPackagePath,
"build.gradle"
);
string packageContains = File.ReadAllText(packageFilename);

// We want to copy only when needed, otherwise it can reset file
// properties, such as permissions and timestamps
if (exportedContains != packageContains) {
File.Copy(packageFilename, exportedFilename, true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
WARNING: Do NOT Modify! Changes will be overwritten by the OneSignal plugin.
*/

apply plugin: 'com.android.library'

android {
Expand All @@ -11,11 +15,11 @@ android {

def unityLib = project(':unityLibrary').extensions.getByName('android')

defaultConfig {
defaultConfig {
consumerProguardFiles "consumer-proguard.pro"
minSdkVersion unityLib.defaultConfig.minSdkVersion.mApiLevel
targetSdkVersion unityLib.defaultConfig.targetSdkVersion.mApiLevel
}
}

compileSdkVersion unityLib.compileSdkVersion
buildToolsVersion unityLib.buildToolsVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ private void MigratePluginToAndroidlib() {
private static readonly string _packagePath = Path.Combine("Packages", "com.onesignal.unity.android", "Editor");
private static readonly string _androidPluginsPath = Path.Combine("Assets", "Plugins", "Android");

private static readonly string _pluginPackagePath = Path.Combine(_packagePath, _pluginName);
private static readonly string _pluginExportPath = Path.Combine(_androidPluginsPath, _pluginName);
internal static readonly string _pluginPackagePath = Path.Combine(_packagePath, _pluginName);
internal static readonly string _pluginExportPath = Path.Combine(_androidPluginsPath, _pluginName);

private static readonly string _manifestPackagePath = Path.Combine(_pluginPackagePath, "AndroidManifest.xml");
private static readonly string _manifestExportPath = Path.Combine(_pluginExportPath, "AndroidManifest.xml");
Expand Down
Loading