DEV Community

Kiran Jodhani
Kiran Jodhani

Posted on

How to export android APK in Unity?

Making a game in Unity is one thing and building it successfully is another difficult task due to the errors one had to face while building. Do not worry, I list the steps, how I built my APK. So this would be a self answered question so as to help others in building their APK.

STEP 1 : Creating keystore and key

First thing first make your game.
Go to File > Build Settings in Unity editor.
Select Platform as Android ( in build settings) if not done already.
Click on Player Settings... button. Fill out Company Name, Product Name , Version and choose a Default Icon for your game.
Now, click the little Andorid icon tab in the inspector pane. A tab will appear named Settings for Android.
Under Settings for Android, you will find various options such as Icon, Resolution and Presentation, Splash Image, etc.
Click on Publishing Settings. Tick mark Create a new keystore... . Then press Browse Keystore. A window will appear select location for your Keystore. and give filename as "yourkeystorename.keystore". Then set Keystore password and confirm it.
Now, Create Key. In Alias by default, it is Unsigned (debug). Change that to Create a new key.
A window will appear fill the Alias and password and confirm the password field. (NOTE : password has to be same as the keystore password we created in step no above).
Then, press create key button. Now the key has been created and change the Alias from Unsigned (debug) to your key that you just created.
Enter the password and you're ready to build your apk.

STEP 2 : Installing SDK and JDK

But I didn't have Android SDK installed. So Building apk showed ERROR: Unable to detect SDK in the selected directory.

So I downloaded "Android Version 3.6.1 for Windows 64-bit" (749 MB) from this link: https://developer.android.com/studio. For Installation, it's easy, just click next throughout the installation. (For me this also automatically installed JDK)
Now set the SDK and JDK location in Unity. Go to Edit>Preferences>External Tools.
Browse and choose the location where SDK is installed and Tick the Use embedded JDK check-box.
To know where Andoird SDK is located, steps are :
Open Up Android Studio, and then Go to 1. Configure 2.Project Defaults 3.Project Structure there you have SDK location.

STEP 3: Fixing the ERROR: Unable to detect SDK in the selected directory. (Even when SDK is installed)

Even After SDK was installed it was showing the same ERROR: Unable to detect SDK in the selected directory.

I noticed that the in the SDK location "tools" named folder was missing.
If it is not missing then I would recommed deleting it.
Fix it by downgrading the android sdk tool version.

The steps : .

Delete android sdk "tools" folder : [Your Android SDK root]/tools -> tools
Download SDK Tools: http://dl-ssl.google.com/android/repository/tools_r25.2.5-windows.zip
Extract that to Android SDK root
Build your project

STEP 4 : Additional Build problems

Hopefully, your APK should be built without any errors.

But during the build, the APK it was stuck at "building gradle project". To fix that ensure that you've set the keystore and key in the publishing settings.

After all this I was finally able to build my APK. :'-)

Hope this all helped, if you have any suggestions and fixes for problem related to building an APK please post it here so that others can also take help from it.

The Motivation behind this post was to save all the work at one place that one had to do while building an APK.

Top comments (0)