- I want to export my project via Gradle and use Android Studio to build it.
Reasons you might want to do this include:
- You want to make modifications to the application in Android Studio before building it.
- You want full control over the build process.
It is best practice to have your Android developer environment set up before building your Unity application in Android Studio.
This involves downloading and installing Android Studio, which also installs the Android SDK. You can download Android Studio from the Android Studio website.
Once you have downloaded Android Studio, you need to add the Android SDK path to Unity. See Unity documentation on Android SDK/NDK setup for steps on how to do this.
Once you have your Android developer environment set up, you can open your Unity Project.
Important: You need to set a valid bundle identifier to be able to export an Android Project. To set this, go to Player Settings (menu: Edit > Project Settings > Player), navigate to Other Settings, and under Identification, use the Package Name field.
Go to Build Settings and make sure Android is selected as the target platform and tick the Export Project checkbox, as shown below:
You can now export your project using the Export button and choose a folder to export your project to.
Assuming there are no build errors, you now have a Gradle project located in the specified folder. You can open this with Android Studio.
To open your Grandle project with Android Studio, open Android Studio and select Import Project, then navigate to the folder that contains your Gradle folder. If you're asked to choose whether to use a Gradle wrapper, select OK. Later, you need to override the Gradle distribution that it downloads (this is to work around a bug in Android Studio, where it believes Unity's Gradle version is invalid).
Once the project has finished importing, go to Android Studio's preferences and search for Gradle. From here, you can select a specific Gradle version for your project. Select Use local Gradle distribution, then navigate to Unity's Gradle installation, located at:
OSX: <Unity installation folder>/PlaybackEngines/AndroidPlayer/Tools/gradle
Windows: <Unity installation folder>/Editor/Data/PlaybackEngines/AndroidPlayer/Tools/gradle
Click Apply and wait for your project to perform another Gradle sync. After this is finished, you can make your changes to the Android Studio project.
To build with Android Studio, go to Run > Edit Configurations. Create a new Gradle configuration with the plus (+) icon. To select a Gradle project, click the folder icon. In Tasks, enter build, as shown below. Then apply your changes and click Run > Run <Name of your config>.
On windows 10 with Unity 2017.4.0f1 there is no need to specify the unity gradle directory when importing the Unity project into android studio. When android studio prompts for a gradle directory just say cancel and it builds fine. Android studio might prompt for the gradle directory again after it completes the build and you should just select cancel again.
Tengo un problema con Unity 2018.3.10f1 (64-bit) Me aparece el siguiente mensaje: "Failed getting available Android API levels. Make sure your android sdk tools version is 25 or higher and you have internet connection".
Son un cliente de Unity Plus desde el año pasado, y hasta ahora no he podido compilar mi proyecto de Unity para Android. Necesito Ayuda.
No build system (gradle) available "Unity 2019.1.4f1". Why is that?
Thanks! It's really helpful.
every time I try to build my game to apk it appears this
Thanks for your comment!
I am sorry to see that you are having an issue with building to APK. Sadly, we are not able to help with technical questions in the comments section here, so I am sorry about that.
What I would recommend is visiting the Unity Support Forums to find help with your issue. You can visit our forums by following this link: https://forum.unity.com/
If the forums do not give you a solution, please feel free to reach out to firstname.lastname@example.org and we would be happy to help you.
This article is out-of-date.
Please sign in to leave a comment.