juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.09k stars 505 forks source link

[Android] Fix UnityThemeSelector error due to missing files in unityLibrary/src/android/res #894

Open timbotimbo opened 8 months ago

timbotimbo commented 8 months ago

Description

If you export the example project for Android with Unity 2023.3.x, you will get errors related to a missing style/UnityThemeSelector. This is because the file that declares this style is accidentally deleted during the export, this pull request makes sure the file is kept.

Cause

During the unity export, the folder unityLibrary/src/main/res is accidentally deleted during a copy.

It first copies unity/<project>/Builds/<name>.apk/unityLibrary to android/unityLibrary. unityLibrary/src/main/res now contains multiple files (may differ per Unity version)

Then it copies unity/<project>/Builds/<name>.apk/launcher/src/main/reson top of that. This copy function deletes the destination folder. So now unityLibrary/src/main/res only contains:

The missing styles.xml file is now causing this issue.

Error message

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
   > Android resource linking failed
     C:\Users\User\Documents\unity_widget\example\build\app\intermediates\packaged_manifests\release\AndroidManifest.xml:81: error: resource style/UnityThemeSelector (aka com.xraph.plugin.flutter_unity_widget_example:style/UnityThemeSelector) not found.
     error: failed processing manifest.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:bundleReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2ProcessResourcesRunnable
   > Android resource linking failed
     C:\Users\User\Documents\unity_widget\example\build\app\intermediates\bundle_manifest\release\AndroidManifest.xml:81: error: resource style/UnityThemeSelector (aka com.xraph.plugin.flutter_unity_widget_example:style/UnityThemeSelector) not found.
     error: failed processing manifest.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
==============================================================================

Type of Change