Skip to content

Unity6; Automatic Android migration #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025
Merged

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Apr 16, 2025

Description

One Line Summary

Automatically apply required changes for Unity 6 build compatibility, this only effects Android.

Details

Follow up to PR #776

Motivation

If changes were not applied automatic it will lead extra work the app developer has to search for or may reach out to OneSignal support for help.

Scope

Only effects Android builds.

Testing

Unit testing

None

Manual testing

Tested with Unity 6000.0.42f1.7976.8784 on macOS.
Made changes to the file located at Assets/Plugins/Android/OneSignalConfig.androidlib/build.gradle and ensured it reverts it.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

Automatically update Assets/Plugins/Android/OneSignalConfig.androidlib/build.gradle
with the contains provided by the OneSignal SDK. This way the app
developer doesn't have to take any manual steps when upgrading to
Unity 6.

The changes to build.gradle were done in commit
d253d42
Also update example project with missing build.gradle namespace.
@jkasten2 jkasten2 requested review from nan-li and fadi-george April 16, 2025 22:25
@jkasten2 jkasten2 changed the title Unity6 android migration Unity6; Automatically Android migration Apr 16, 2025
[InitializeOnLoad]
sealed class MigrateAndroidResources {
static MigrateAndroidResources() {
UpdateBuildDotGradleContains();
Copy link

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
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

@jkasten2 jkasten2 merged commit eb134ae into main Apr 17, 2025
1 check passed
@jkasten2 jkasten2 deleted the unity6-android-migration branch April 17, 2025 18:21
@jkasten2 jkasten2 changed the title Unity6; Automatically Android migration Unity6; Automatic Android migration Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants