Last active
July 23, 2025 09:37
-
-
Save ahmadm712/970cb8da5b8ef4369cd9e2b2b6ba67a5 to your computer and use it in GitHub Desktop.
Embed Unity Game as library on android native flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1.Take 'unityLibrary' on 'android/' folder | |
| 2.Setup 'setting.gradle' add 'unityLibrary' | |
| ``` | |
| // add to the bottom line | |
| include ':unityLibrary' | |
| project(':unityLibrary').projectDir = file('./unityLibrary') | |
| ``` | |
| 3.Setup 'android/app/build.gradle' implement 'unityLibrary' | |
| ``` | |
| // add to the bottom line | |
| dependencies { | |
| implementation project(':unityLibrary') | |
| } | |
| ``` | |
| 4.Coment 'keepUnitySymbols' on 'unityLibrary/build.gradle' | |
| ``` | |
| // apply from: '../shared/keepUnitySymbols.gradle' | |
| ``` | |
| 5. Coment 'noCompress' on 'androidResources' at 'unityLibrary/build.gradle' | |
| ``` | |
| // noCompress = ['.unity3d', '.ress', '.resource', '.obb', '.bundle', '.unityexp'] + unityStreamingAssets.tokenize(', ') | |
| ``` | |
| 6. Coment launcher at androidManifest on unitylibrary to avoid duplicate launcher | |
| ``` | |
| <!-- <intent-filter> | |
| <category android:name="android.intent.category.LAUNCHER" /> | |
| <action android:name="android.intent.action.MAIN" /> | |
| </intent-filter> --> | |
| ``` | |
| 7. Synch project with gradle files to make library visible at android folder | |
| 8. Voila your unityLibrary available and ready to embed on native android | |
| 9. Import UnityPlayerGameActivity and call it on intent | |
| ``` | |
| import com.unity3d.player.UnityPlayerGameActivity | |
| val intent = Intent(this, UnityPlayerGameActivity::class.java) | |
| startActivity(intent) | |
| finish() // Optional: return immediately | |
| ``` | |
| 10. Done | |
| 11. Coment ndk path | |
| // ndkPath "C:/Program Files/Unity/Hub/Editor/6000.0.28f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment