Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ahmadm712/970cb8da5b8ef4369cd9e2b2b6ba67a5 to your computer and use it in GitHub Desktop.

Select an option

Save ahmadm712/970cb8da5b8ef4369cd9e2b2b6ba67a5 to your computer and use it in GitHub Desktop.
Embed Unity Game as library on android native flutter
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