Porting An Android App To Androidtv App: Piyush Kumar

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Porting An Android App To AndroidTV App

Author: Piyush Kumar

There are millions of apps for Android and as Android TV is a modified version of Android, in theory it is possible for one
to run Android apps on any Android TV. But reality is not that simple and that is why there is huge difference in number
of apps in the Android TV app store. This is where Android comes handy by providing side loading option.
I started on the sideloading path assuming that it is going to be a straight forward affair and was surprised that it is much
more involved. With the help of DuckduckGo, Reddit and XDA I was able to side load few apps on my Sony TV. I decided
to document the steps so that someone in my situation can save some time (and probably improve on this).
But before you start, make sure that your app is not designed to work only in Portrait mode (as was case with few apps I
was trying) because it is a neck bending experience to use apps on TV when they are rendered at 90* angle.

1. Enabling side loading on your TV:


a. In case of Sony (and Android 7) you can go to Settings-->Security and restrictions-->"Unknown sources" -->
Enable the toggle button to allow side loading of apps.
b. Ensure that "Verify apps" option right under the "Unknown sources" setting (on Sony TV) is disabled.
2. Setting up necessary tools:
a. Download APK2TV from this Website (https://nvidiashieldzone.com/shield-android-tv/apk2tv/). Props to
this dude for making this tool as it makes things so easy and straight forward that non-programmers can use
this too.
b. Unzip apk2tv on your computer (For ex: C:\Temp\apk2tv_v12)
c. Download latest version of apktool jar from the github/bitbucket
(https://bitbucket.org/iBotPeaches/apktool/downloads/ )

d. Rename the old "apktool.jar" present in the apk2tv_v12 folder to "apktool.jar.old"


e. Rename the latest jar for apktool (apktool_2.4.1.jar) downloaded from apktool github/bitbucket to
"apktool.jar" and place it in the apk2tv_v12 folder
f. Download the latest version of apktool wrapper script for your OS from github
(https://ibotpeaches.github.io/Apktool/install/). In my case I was using Windows, so I downloaded the
associated ".bat" file and would continue to use it in rest of the write up.
g. Rename the old "apktool.bat" present in the apk2tv_v12 folder to "apktool.bat.old"
h. Place the latest wrapper (apktool.bat) downloaded from apktool github/bitbucket in the apk2tv_v12 folder
i. On your TV, open the app store and download a file manager/explorer app. In my case I used File
Commander
j. Confirm Java (1.8) and .Net Framework (4.X) are installed on your machine. If they are not, please download
and install them.
3. Getting the APK:

Page 1
3. Getting the APK:
a. Download the app, that you want to set up on your TV, on your android Mobile phone.
b. Download an app to export the apk. In my case I used APK Extractor
c. Using the extractor app (APK Extractor), export the app. APK extractor would put the file in a folder called
"ExtractedApks" on your default phone memory
Note: you can get the apk directly from any apk repo websites but I chose this route for my own peace of
mind.
d. Export the extracted APK to the machine where we have set up apk2tv in previous steps.
4. Preparing the logo for the app:
a. Search for logo of the app on Duckduckgo image search
b. Save the logo that you like on your machine
c. Open the logo saved in above step in Microsoft Paintbrush
d. Click on the resize button --> click on pixel --> change the values to 320X180
e. Save the file as PNG
5. Modifying Apk:
a. Run APK2TV.exe ( I used run as administrator option in order to avoid any permission related issues)

b. Click on Load APK --> browse to the location where you have copied the extracted apk --> select the apk and
click Open
c. Once you click open in previous step, a command prompt would open and you would see tool decoding the
apk you selected. Once the decoding is completed system would give a prompt as shown below and you can
press any button to proceed.

d. Click on the Existing Banner radio button --> browse to the location where you have saved the logo of the
app and click Open
e. Click on "Convert" icon at the bottom and wait. It would take some time but in the end you would have the
apk present in the "Output Folder" location
6. Deploying the updated APK:

Page 2
6. Deploying the updated APK:
a. Copy the updated apk (from output folder) to a USB drive
b. Connect the USB drive to your TV
c. Open the file explorer/manager app on your TV
d. Browse the USB drive and install the updated apk
e. If everything goes well, you would have app icon appear on TV home screen

Hopefully this works for you and you are done. But in case you want to understand what is happening under the
hood, read on.

Apktool.jar: This is the 3rd party utility that is used to reverse engineer packaged android apps (apk files). It is able
to decode as well as rebuild the apk for usecases like localization, support for custom platforms etc. Under the
hood this utilizes Android Asset Packaging Tool (AAPT/AAPT2) to do the decompile and rebuild tasks.

Apk2TV: The person who wrote this tool is awesome as he made this exercise extremely easy. The tool uses the
apktool.jar for decode and rebuild but then adds few lines in AndroidManifest.xml. Android TV uses Leanback
launcher thus an app needs to have few tags in its AndroidManifest.xml for Leanback launcher to display it on
home screen. The modified APK contains those flags and thus after side loading Android TV starts to display the
app on home screen. Below given are the main tags I saw being added (for the app I was playing with) to the
AndroidManifest.xml by the tool:
In the application tag
android:banner="@drawable/ic_banner"

<category android:name="android.intent.category.LEANBACK_LAUNCHER" />


<uses-feature android:name="android.hardware.gamepad" android:required="false"/>
<uses-feature android:name="android.software.leanback" android:required="false"/>

This path to convert normal Android apps to work on Android TV apps might not work in some cases and there is
not lot that we can do about it. The errors could be related to apktool or just the way AAPT works or may be
something else. Hope this helps.

Page 3

You might also like