Exporting a project to Gradle and building/deploying on Android Studio

Symptoms

  • I want to export my project via Gradle and use Android Studio to build it.

Cause

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.

Resolution

You need to have your Android developer environment set up before you can build your Unity application in Android Studio. This involves downloading and installing Android Studio, which also installs the Android SDK. Download Android Studio from the Android Studio website.

Next, 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. Note that 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 in the picture below.

Screen_Shot_2021-07-09_at_2.27.49_PM.png

You can now export your project using the Export button. Select 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 do this, open Android Studio and select Import Project, then navigate to the folder that contains your Gradle folder. If you’re asked to select whether to use a Gradle wrapper, select OK. Later, you need to override the Gradle distribution that it downloads (this is to workaround 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

 mceclip1.png

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 ConfigurationsCreate 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>.

Screen_Shot_2021-07-09_at_3.02.04_PM.png

More Information

https://docs.unity3d.com/Manual/android-gradle-overview.html

https://developer.android.com/studio/build/build-variants.html

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值