Build Unity Library
Unity 2022.3.17f1 may throw the following error when integrating with React Native or Flutter:
AndroidJavaException: java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "mUnityPlayer" in class
This issue has been fixed in Unity 2022.3.19f1.
1. Prepare Android Library (Unity Project)
1. Export Android Project
Export the Android project from Unity (select Export Project in Build Settings).
2. Update AndroidManifest.xml
Navigate to:
<build-folder>/unityLibrary/src/main/AndroidManifest.xml
Remove the <intent-filter> section associated with the Unity launcher:
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>3. Build Android App Library with Gradle
cd <build-folder>
export JAVA_HOME=<unity-folder>/PlaybackEngines/AndroidPlayer/OpenJDK
# build AAR file
gradle wrapper && ./gradlew assembleRelease4. Create directory <build-folder>/unityLibrary/build/unityLibrary. Copy or move the following components into this directory:
-
<build-folder>/unityLibrary/build/outputs/aar/unityLibrary-release.aar -
<build-folder>/unityLibrary/libs
5. Create file <build-folder>/unityLibrary/build/unityLibrary/build.gradle with the following content:
configurations.maybeCreate("default")
artifacts.add("default", file("unityLibrary-release.aar"))Distribute files include the <build-folder>/unityLibrary/build/unityLibrary directory and its content
2. Prepare iOS Library (Unity Project)
1. Export iOS Project
2. Required Configurations
- Change the Target Membership of the
Datafolder fromUnity-iPhonetoUnityFramework. - Change the access level of
NativeCallProxy.hfromProjecttoPublic. - In
Frameworks/Silver Tau/NSR/Runtime/Plugins/iOS, remove all Target Membership entries exceptUnityFramework(typically removeUnity-iPhone). - Remove bitcode from
StcCorder.framework: bitcode_strip -r StcCorder.framework/StcCorder -o StcCorder.framework/StcCorder (ref: https://warchimede.com/posts/2024-10-08-how-to-remove-bitcode-from-framework/ )
3. Build framework and export XCFramework
xcodebuild archive -project "Unity-iPhone.xcodeproj" -scheme "UnityFramework" -configuration Release -destination generic/platform=iOS -archivePath "build/app.xcarchive" CODE_SIGNING_ALLOWED=NO SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild -create-xcframework -archive build/app.xcarchive -framework UnityFramework.framework -output build/UnityFramework.xcframeworkDistribute files include the UnityFramework.framework and its contents
Last updated on