Skip to content

Commit d910dd5

Browse files
committedAug 15, 2024·
Merge branch 'master' into experimental/unity_6000
2 parents aa8875d + f51fedc commit d910dd5

File tree

3 files changed

+131
-97
lines changed

3 files changed

+131
-97
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* [Android] Fix touch detection when using Unity's New Input System. [#938](https://github.com/juicycleff/flutter-unity-view-widget/pull/938)
1010
* [Android] Workaround for mUnityplayer error in Unity plugins using the AndroidJavaProxy. [#908](https://github.com/juicycleff/flutter-unity-view-widget/pull/908)
1111
* [Android] Add namespace for Android gradle plugin (AGP) 8 compatibility.
12+
* [Android] Fix kotlin compilation error with Flutter 3.24 and newer. [#973](https://github.com/juicycleff/flutter-unity-view-widget/issues/973)
1213

1314
## 2022.2.1
1415

‎README.md

+59-28
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,12 @@ allprojects {
364364

365365
<img src="https://github.com/juicycleff/flutter-unity-view-widget/blob/master/files/libraries.png" width="400" />
366366

367-
5. If you use Xcode 14 or newer, and Unity older than 2021.3.17f1 or 2022.2.2f1, your app might crash when running from Xcode.
367+
5. Unity plugins that make use of native code (Vuforia, openCV, etc.) might need to be added to Runner like UnityFramework.
368+
Check the contents of the `/ios/UnityLibrary/Frameworks/` directory. Any `<name>.framework` located in (subdirectories of) this directory is a framework that you can add to Runner.
369+
370+
6. Make sure pods are installed after your Unity export, either using `flutter run` or by running `pod install` in the ios folder.
371+
372+
7. If you use Xcode 14 or newer, and Unity older than 2021.3.17f1 or 2022.2.2f1, your app might crash when running from Xcode.
368373
Disable the `Thread Performance Checker` feature in Xcode to fix this.
369374
- In Xcode go to `Product > Scheme > Edit Scheme...`
370375
- Now With `Run` selected on the left, got to the `Diagnostics` tab and uncheck the checkbox for `Thread Performance Checker`.
@@ -377,30 +382,39 @@ allprojects {
377382

378383
The following setup for AR is done after making an export from Unity.
379384

385+
<b>Warning: Flutter 3.22 has introduced a crash when using AR on Android < 13 [#957](https://github.com/juicycleff/flutter-unity-view-widget/issues/957)</b>
380386

381-
<b>Warning: The `XR Plugin Management` package version `4.3.1 - 4.3.3` has bug that breaks Android exports. </b>
382-
383-
- The bug accidentally deletes your AndroidManifest.xml file after each build, resulting in a broken export.
384-
Switch to version `4.2.2` or `4.4` to avoid this.
385387

386388
<details>
387389
<summary>:information_source: <b>AR Foundation Android</b></summary>
388390

389-
7. Open the *lib/__architecture__/* folder and check if there are both *libUnityARCore.so* and *libarpresto_api.so* files.
390-
There seems to be a bug where a Unity export does not include all lib files. If they are missing, use Unity to build a standalone .apk
391-
of your AR project, unzip the resulting apk, and copy over the missing .lib files to the `unityLibrary` module.
392-
393-
8. Repeat steps 5 and 6 from the Android <b>Platform specific setup</b> (editing build.gradle and settings.gradle), replacing `unityLibrary` with `arcore_client`, `unityandroidpermissions` and `UnityARCore`.
394-
395-
9. When using `UnityWidget` in Flutter, set `fullscreen: false` to disable fullscreen.
391+
1. Check the version of the `XR Plugin Management` in the Unity package manager. Versions `4.3.1 - 4.3.3` contain a bug that breaks Android exports.
392+
Make sure to use a version <=`4.2.2` or >=`4.4`.
393+
You might have to manually change the version in `<unity project>/Packages/manifest.json` for `"com.unity.xr.management"`.
394+
395+
396+
2. You can check the `android/unityLibrary/libs` folder to see if AR was properly exported. It should contain files similar to `UnityARCore.aar`, `ARPresto.aar`, `arcore_client.aar` and `unityandroidpermissions.aar`.
397+
398+
If your setup and export was done correctly, your project should automatically load these files.
399+
If it doesn't, check if your `android/build.gradle` file contains the `flatDir` section added in the android setup step 7.
400+
401+
3. If your `XR Plugin Management` plugin is version 4.4 or higher, Unity also exports the xrmanifest.androidlib folder.
402+
Make sure to include it by adding the following line to `android/settings.gradle`
403+
```
404+
include ":unityLibrary:xrmanifest.androidlib"
405+
```
406+
4. With some Unity versions AR might crash at runtine with an error like:
407+
`java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "mUnityPlayer" in class`.
408+
See the Android setup step 3 on how to edit your MainActivity to fix this.
396409
397410
-----
398411
</details>
399412
400413
<details>
401414
<summary>:information_source: <b>AR Foundation iOS</b></summary>
402-
7. Open the *ios/Runner/Info.plist* and change the following:
403415
416+
1. Open the *ios/Runner/Info.plist* and add a camera usage description.
417+
For example:
404418
```diff
405419
<dict>
406420
+ <key>NSCameraUsageDescription</key>
@@ -413,28 +427,45 @@ Switch to version `4.2.2` or `4.4` to avoid this.
413427
<details>
414428
<summary>:information_source: <b>Vuforia Android</b></summary>
415429

416-
Thanks to [@PiotrxKolasinski](https://github.com/PiotrxKolasinski) for writing down the exact steps:
430+
1. Your export should contain a Vuforia library in the `android/unityLibrary/libs/` folder. Currently named `VuforiaEngine.aar`.
431+
432+
If your setup and export was done correctly, your project should automatically load this file.
433+
If it doesn't, check if your `android/build.gradle` file contains the `flatDir` section added in the android setup step 7.
434+
435+
In case this gets outdated or broken, check the [Vuforia documentation](https://developer.vuforia.com/library/unity-extension/using-vuforia-engine-unity-library-uaal#android-specific-steps)
436+
437+
-----
438+
</details>
439+
440+
<details>
441+
<summary>:information_source: <b>Vuforia iOS</b></summary>
417442

418-
7. Open the *android/unityLibrary/build.gradle* file and change the following:
443+
These steps are based on these [Vuforia docs](https://developer.vuforia.com/library/unity-extension/using-vuforia-engine-unity-library-uaal#ios-specific-steps) and [this comment](https://github.com/juicycleff/flutter-unity-view-widget/issues/314#issuecomment-785302253)
419444

445+
1. Open the *ios/Runner/Info.plist* and add a camera usage description.
446+
For example:
420447
```diff
421-
- implementation(name: 'VuforiaWrapper', ext: 'aar')
422-
+ implementation project(':VuforiaWrapper')
448+
<dict>
449+
+ <key>NSCameraUsageDescription</key>
450+
+ <string>$(PRODUCT_NAME) uses Cameras</string>
451+
</dict>
423452
```
453+
2. In Xcode,
454+
Select `Runner` > `General` tab.
455+
In `Frameworks, Libraries, and Embedded content` add the Vuforia frameworks. This is where you added *UnityFramework.framework* in step 4 of the iOS setup.
424456

425-
8. Using Android Studio, go to **File > Open** and select the *android/* folder. A
426-
new project will open.
427-
428-
> Don't worry if the error message "Project with path ':VuforiaWrapper' could not be
429-
> found in project ':unityLibrary'" appears. The next step will fix it.
457+
You should be able to find them in
458+
`/ios/UnityLibrary/Frameworks/com.ptc.vuforia.engine/Vuforia/Plugins/iOS/`.
459+
Currently these are
460+
- `Vuforia.framework`
461+
- `UnityDriver.framework`
462+
463+
3. To support Vuforia target databases, move the `Unity-iPhone/Vuforia` folder from Unity-iPhone to Runner. Then set `Target Membership` of this folder to Runner.
464+
465+
4. Make sure pods are installed after your Unity export, either using `flutter run` or by running `pod install` in the ios folder.
430466

431-
9. In this new project window, go to **File > New > New Module > Import .JAR/.AAR package**
432-
and select the *android/unityLibrary/libs/VuforiaWrapper.aar* file. A new folder
433-
named *VuforiaWrapper* will be created inside *android/*. You can now close this
434-
new project window.
435-
436467
-----
437-
</details>
468+
</details>
438469

439470
## Emulators
440471
We recommend using a physical iOS or Android device, as emulator support is limited.

‎android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt

+71-69
Original file line numberDiff line numberDiff line change
@@ -87,78 +87,80 @@ class FlutterUnityWidgetPlugin : FlutterPlugin, ActivityAware {
8787
}
8888

8989
/**
90+
* [August 2024 UPDATE] This unused class was disabled to fix compilation errors in Flutter 3.24.
91+
*
9092
* This class provides a {@link LifecycleOwner} for the activity driven by {@link
9193
* ActivityLifecycleCallbacks}.
9294
*
9395
* <p>This is used in the case where a direct Lifecycle/Owner is not available.
9496
*/
95-
@SuppressLint("NewApi")
96-
private class ProxyLifecycleProvider(activity: Activity) : Application.ActivityLifecycleCallbacks, LifecycleOwner, LifecycleProvider {
97-
private val lifecycle = LifecycleRegistry(this)
98-
private var registrarActivityHashCode: Int = 0
99-
100-
init {
101-
UnityPlayerUtils.activity = activity
102-
this.registrarActivityHashCode = activity.hashCode()
103-
activity.application.registerActivityLifecycleCallbacks(this)
104-
}
105-
106-
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
107-
UnityPlayerUtils.activity = activity
108-
if (activity.hashCode() != registrarActivityHashCode) {
109-
return
110-
}
111-
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
112-
}
113-
114-
override fun onActivityStarted(activity: Activity) {
115-
UnityPlayerUtils.activity = activity
116-
if (activity.hashCode() != registrarActivityHashCode) {
117-
return
118-
}
119-
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START)
120-
}
121-
122-
override fun onActivityResumed(activity: Activity) {
123-
UnityPlayerUtils.activity = activity
124-
if (activity.hashCode() != registrarActivityHashCode) {
125-
return
126-
}
127-
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
128-
}
129-
130-
override fun onActivityPaused(activity: Activity) {
131-
UnityPlayerUtils.activity = activity
132-
if (activity.hashCode() != registrarActivityHashCode) {
133-
return
134-
}
135-
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
136-
}
137-
138-
override fun onActivityStopped(activity: Activity) {
139-
UnityPlayerUtils.activity = activity
140-
if (activity.hashCode() != registrarActivityHashCode) {
141-
return
142-
}
143-
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
144-
}
145-
146-
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
147-
UnityPlayerUtils.activity = activity
148-
}
149-
150-
override fun onActivityDestroyed(activity: Activity) {
151-
UnityPlayerUtils.activity = activity
152-
if (activity.hashCode() != registrarActivityHashCode) {
153-
return
154-
}
155-
156-
activity.application.unregisterActivityLifecycleCallbacks(this)
157-
lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
158-
}
159-
160-
override fun getLifecycle(): Lifecycle {
161-
return lifecycle
162-
}
163-
}
97+
// @SuppressLint("NewApi")
98+
// private class ProxyLifecycleProvider(activity: Activity) : Application.ActivityLifecycleCallbacks, LifecycleOwner, LifecycleProvider {
99+
// private val lifecycle = LifecycleRegistry(this)
100+
// private var registrarActivityHashCode: Int = 0
101+
//
102+
// init {
103+
// UnityPlayerUtils.activity = activity
104+
// this.registrarActivityHashCode = activity.hashCode()
105+
// activity.application.registerActivityLifecycleCallbacks(this)
106+
// }
107+
//
108+
// override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
109+
// UnityPlayerUtils.activity = activity
110+
// if (activity.hashCode() != registrarActivityHashCode) {
111+
// return
112+
// }
113+
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_CREATE)
114+
// }
115+
//
116+
// override fun onActivityStarted(activity: Activity) {
117+
// UnityPlayerUtils.activity = activity
118+
// if (activity.hashCode() != registrarActivityHashCode) {
119+
// return
120+
// }
121+
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_START)
122+
// }
123+
//
124+
// override fun onActivityResumed(activity: Activity) {
125+
// UnityPlayerUtils.activity = activity
126+
// if (activity.hashCode() != registrarActivityHashCode) {
127+
// return
128+
// }
129+
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
130+
// }
131+
//
132+
// override fun onActivityPaused(activity: Activity) {
133+
// UnityPlayerUtils.activity = activity
134+
// if (activity.hashCode() != registrarActivityHashCode) {
135+
// return
136+
// }
137+
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE)
138+
// }
139+
//
140+
// override fun onActivityStopped(activity: Activity) {
141+
// UnityPlayerUtils.activity = activity
142+
// if (activity.hashCode() != registrarActivityHashCode) {
143+
// return
144+
// }
145+
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_STOP)
146+
// }
147+
//
148+
// override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
149+
// UnityPlayerUtils.activity = activity
150+
// }
151+
//
152+
// override fun onActivityDestroyed(activity: Activity) {
153+
// UnityPlayerUtils.activity = activity
154+
// if (activity.hashCode() != registrarActivityHashCode) {
155+
// return
156+
// }
157+
//
158+
// activity.application.unregisterActivityLifecycleCallbacks(this)
159+
// lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY)
160+
// }
161+
//
162+
// override fun getLifecycle(): Lifecycle {
163+
// return lifecycle
164+
// }
165+
// }
164166
}

0 commit comments

Comments
 (0)
Please sign in to comment.