Modifying Kodi to use as launcher
#1
Since the Android Leanback launcher is both slow and ugly I decided to use Kodi 18.5 as the launcher on my 2015 Sony Bravia AndroidTV running Android 7, I thought I'd share my experiences:

SET UP BUILD ENVIRONMENT
Set up build environment as per https://github.com/xbmc/xbmc/blob/Leia/d...Android.md - i did it in a Ubuntu 16.04 VMWare environment. There were some issues with java and the key store (I can't remember exactly what) but use a completely fresh Ubuntu install and you should be good. The README specifies NDK 18 which can't be found, use 18b and then rename $HOME/android-tools/android-ndk-r18b to  $HOME/android-tools/android-ndk-r18.

MODIFY ANDROIDMANIFEST.XML.IN TO MAKE KODI DETECTED AS A LAUNCHER
Modify tools/android/packaging/xbmc/AndroidManifest.xml.in to make Kodi a launcher (I know there are bridge apps such as https://play.google.com/store/apps/detai...mclauncher but we are going to modify and build Kodi anyway) so that:
  • Launcher intent filter is added to Main activity:
Quote:            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                    
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
  • Splash and Main activities have android:launchMode="singleTop"
  • Splash and Main activities have android:documentLaunchMode="never"
  • Splash and Main activities have android:excludeFromRecents="true"
The developer guidelines suggest setting android:launchMode="singleTask" and androidConfusedtateNotNeeded="true" for launchers but this causes significant load times (as it starts from scratch every time you go to the home screen) and I have found no issues running with singleTop and no stateNotNeeded.

MODIFY XBMCAPP.CPP TO CATCH HOME BUTTON INTENT
To react to "Home button press" add handling for android.intent.action.MAIN/android.intent.category.HOME in void CXBMCApp::onNewIntent(CJNIIntent intent) (found on line 1076 in xbmc/platform/android/activity/XBMCApp.cpp):
Quote:  if(action == "android.intent.action.MAIN" && intent.hasCategory("android.intent.category.HOME"))
  {
    CApplicationMessenger::GetInstance().PostMsg(TMSG_GUI_ACTIVATE_WINDOW, WINDOW_HOME, 0, nullptr); // Sets Home window as active
  } else // below is original code
  if (!targetFile.empty() &&  (action == "android.intent.action.VIEW" || action == "android.intent.action.GET_CONTENT"))
  {
    CLog::Log(LOGDEBUG, "-- targetFile: %s", targetFile.c_str());
    ...
The above will send Kodi to Home.xml when the Home button is pressed (the key press doesn't generate a key press event, it only generates a MAIN/HOME intent). One could look at clearing the "Kodi window stack" as well (so that back button press after pressing home goes nowhere).

BUILD KODI
As per https://github.com/xbmc/xbmc/blob/Leia/d...Android.md

MODIFY SKIN TO REACH ANDROID SETTINGS
Add a button to access Android settings, there is no package for the settings (at least not on Android 7) but StartAndroidActivity accepts an empty string as package name so the following will launch the Android settings from a skin: StartAndroidActivity("", "android.settings.SETTINGS") - from settings you can reach everything in Android. I run a modified version of Pellucid by Chris Bevan with background images added to the various Nav screens.

DEPENDING ON SYSTEM SET UP DISABLE TV AND KODI VOLUME CONTROL
If, as I do, you have a sound system which you can program to take the IR signals from your TV remote you may want to unmap the Android and Kodi volume control and only control the volume on the sound system:
  • Modify the Kodi keymap (either manually in android/data/org.xbmc.kodi/files/.kodi/userdata/keyboard.xml or through Add-on:Keymap Editor) removing mappings of VolumeUp, VolumeDown and Mute
  • Use https://play.google.com/store/apps/detai...tton&hl=en or similar to unmap vol up, down and mute from Android
UNINSTALL LEANBACK
Uninstall the Leanback launcher through adb shell pm uninstall -k --user 0 com.google.android.leanbacklauncher once this is done the select launcher dialog will be displayed when the launcher should be visible, select always

The above setup is much snappier (and a lot better looking) than Leanback for me, so overall great success..

And that's it so far..
S
Reply
#2
Is it possible to make this as an APK, or do I have to go through all the steps?

Ask, because I'm not all an programmer. But after what I read, I understand it as you redoing an APK, would it be possible to save it as an APK and just run it like that.

And from an post on Reddit, someone wrote that if you empty the cach for Leanback Launcher, you could choose the new one.

Petter
Petter :-)
Many thanks for all the effort YOU all do! THANKS! :-)
nVidia Shield TV (2015), Samsung QE75Q70R and Yamaha RX-V767
Reply
#3
Man, this is exactly what I have been looking for.  Any chance you can post this anywhere where I can  download, because that seems way too complicated for me.
Reply
#4
What happen if Kodi crash on start ?
Is there a way to get back to the Android level ?
Reply
#5
(2020-06-14, 10:13)AcidZero Wrote: What happen if Kodi crash on start ?
Is there a way to get back to the Android level ?

Android has a fallback system where if the selected third party launcher crashes, the system default launcher is restored as default Home app.
Reply
#6
Ok, so I thought I'd update this as I just compiled Matrix 19.1 with the above modifications (I accidentally first compiled 20 alpha so it works for that branch as well). The process above remains valid but for anyone interested this time I did it in a Windows WSL subsystem running Ubuntu 20.04 through the following process:

1. Ensure there is enough memory for the WSL and gradle inside the WSL
  • Stop all WSL instances and the service:
Code:
C:\Users\XXX>wsl --shutdown
  • Create %USERPROFILE%/.wslconfig with the following content:
Code:
[wsl2]
memory=8GB   # Set the memory available to WSL
processors=2 # Set the number of virtualized processors for WSL
  • Open a WSL instance and in your root project directory
Code:
kodi $> echo "org.gradle.jvmargs=-Xmx4096M" > gradle.properties

2. Follow instructions at https://github.com/xbmc/xbmc/blob/master...Android.md to clone the repo and set up the build environment (specify branch as otherwise it will default to the current master branch which at the time of writing is kodi 20.0 alpha, it may not be what you want).
  • The build guide specifies NDK revision 20 which is no longer available, go to https://developer.android.com/ndk/downlo...r_releases and get 20b. Extract as per the build guide but rename the directory from "android-ndk-r20b" to "android-ndk-r20".
  • I had rather poor luck with running more than one thread during makes (failed at different stages when running configure as well as the building of tools and dependencies, binary addons and kodi itself) so you may want to run configure and make single-threaded (i.e. leave out the -j$(getconf _NPROCESSORS_ONLN) option)

3. Change the relevant source files, the changes are still the same:
  • Add launcher intent filter to Main activity (tools/android/packaging/xbmc/AndroidManifest.xml.in)
Code:
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
        
    <category android:name="android.intent.category.HOME" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
  • Add caputre of home button press (line 1158 in xbmc/platform/android/activity/XBMCApp.cpp):
Code:
if(action == "android.intent.action.MAIN" && intent.hasCategory("android.intent.category.HOME"))
{
  CApplicationMessenger::GetInstance().PostMsg(TMSG_GUI_ACTIVATE_WINDOW, WINDOW_HOME, 0, nullptr); // Sets Home window as active
} else // below is original code
if (!targetFile.empty() &&  (action == "android.intent.action.VIEW" || action == "android.intent.action.GET_CONTENT"))
{
  CLog::Log(LOGDEBUG, "-- targetFile: %s", targetFile.c_str());
  ...

4. I also ran into some minor issues during the build:
  • When running make for tools and dependencies I had to run it with admin privileges (to create directories in /usr/local etc.)
Code:
dependencies $> sudo make
  • When at the final step, make apk, the file CMakeFiles/apk.dir/build.make is malformed at line 76, ... && "PATH=... should have the quote after the equal sign, i.e. ... && PATH="... 

As I see people have asked for the APK earlier I can upload it if anyone wants, just let me know where (it's 153 MB). It is however compiled for ARM Android so unless that matches your device it won't help you very much.

As a side note, make sure you have Kodi up and running (i.e. have gone through the first run setup and granted permissions) before removing other launchers, or at least have some way of raising the Android Settings so that you can manually launch Kodi (first run seems to fail if is launched by the system as the launcher).

With regards to the question of what to do if kodi crashes, either reset Android on the TV or if you have an ADB-over-IP connection up you can reinstall leanback (it's not really uninstalled from the device) with
Code:
kodi $> adb shell cmd package install-existing com.google.android.leanbacklauncher
(from https://forum.xda-developers.com/t/how-t...b.3894235/)
Reply
#7
(2021-06-08, 12:59)SlartiBartFastFjord Wrote: Ok, so I thought I'd update this as I just compiled Matrix 19.1 with the above modifications (I accidentally first compiled 20 alpha so it works for that branch as well). The process above remains valid but for anyone interested this time I did it in a Windows WSL subsystem running Ubuntu 20.04 through the following process:

1. Ensure there is enough memory for the WSL and gradle inside the WSL
  • Stop all WSL instances and the service:
Code:
C:\Users\XXX>wsl --shutdown
  • Create %USERPROFILE%/.wslconfig with the following content:
Code:
[wsl2]
memory=8GB   # Set the memory available to WSL
processors=2 # Set the number of virtualized processors for WSL
  • Open a WSL instance and in your root project directory
Code:
kodi $> echo "org.gradle.jvmargs=-Xmx4096M" > gradle.properties

2. Follow instructions at https://github.com/xbmc/xbmc/blob/master...Android.md to clone the repo and set up the build environment (specify branch as otherwise it will default to the current master branch which at the time of writing is kodi 20.0 alpha, it may not be what you want).
  • The build guide specifies NDK revision 20 which is no longer available, go to https://developer.android.com/ndk/downlo...r_releases and get 20b. Extract as per the build guide but rename the directory from "android-ndk-r20b" to "android-ndk-r20".
  • I had rather poor luck with running more than one thread during makes (failed at different stages when running configure as well as the building of tools and dependencies, binary addons and kodi itself) so you may want to run configure and make single-threaded (i.e. leave out the -j$(getconf _NPROCESSORS_ONLN) option)

3. Change the relevant source files, the changes are still the same:
  • Add launcher intent filter to Main activity (tools/android/packaging/xbmc/AndroidManifest.xml.in)
Code:
<intent-filter>
    <action android:name="android.intent.action.MAIN" />
        
    <category android:name="android.intent.category.HOME" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
  • Add caputre of home button press (line 1158 in xbmc/platform/android/activity/XBMCApp.cpp):
Code:
if(action == "android.intent.action.MAIN" && intent.hasCategory("android.intent.category.HOME"))
{
  CApplicationMessenger::GetInstance().PostMsg(TMSG_GUI_ACTIVATE_WINDOW, WINDOW_HOME, 0, nullptr); // Sets Home window as active
} else // below is original code
if (!targetFile.empty() &&  (action == "android.intent.action.VIEW" || action == "android.intent.action.GET_CONTENT"))
{
  CLog::Log(LOGDEBUG, "-- targetFile: %s", targetFile.c_str());
  ...

4. I also ran into some minor issues during the build:
  • When running make for tools and dependencies I had to run it with admin privileges (to create directories in /usr/local etc.)
Code:
dependencies $> sudo make
  • When at the final step, make apk, the file CMakeFiles/apk.dir/build.make is malformed at line 76, ... && "PATH=... should have the quote after the equal sign, i.e. ... && PATH="... 

As I see people have asked for the APK earlier I can upload it if anyone wants, just let me know where (it's 153 MB). It is however compiled for ARM Android so unless that matches your device it won't help you very much.

As a side note, make sure you have Kodi up and running (i.e. have gone through the first run setup and granted permissions) before removing other launchers, or at least have some way of raising the Android Settings so that you can manually launch Kodi (first run seems to fail if is launched by the system as the launcher).

With regards to the question of what to do if kodi crashes, either reset Android on the TV or if you have an ADB-over-IP connection up you can reinstall leanback (it's not really uninstalled from the device) with
Code:
kodi $> adb shell cmd package install-existing com.google.android.leanbacklauncher
(from https://forum.xda-developers.com/t/how-t...b.3894235/)
Thanks for getting it to work always wanted a way to have Kodi as my main launcher, I'd be very interested in the APK if you could provide it some way, maybe a link to it on Google drive?
Reply
#8
(2021-06-08, 13:29)Supersilver Wrote:
(2021-06-08, 12:59)SlartiBartFastFjord Wrote:  
Thanks for getting it to work always wanted a way to have Kodi as my main launcher, I'd be very interested in the APK if you could provide it some way, maybe a link to it on Google drive?
I don't use google nor do I have any file sharing locations I would like to share publicly, if you arrange somewhere to upload it I can upload it there. The best would probably be somewhere that is publicly available if there are more that want to download a copy. Otherwise the compiling is pretty straight forward using the instructions above, however depending on your hardware it will take some 24h for all of the build (but you obviously don't have to watch the screen for the duration, launch a step and check in every 8h or so).
Reply
#9
(2021-06-08, 15:14)SlartiBartFastFjord Wrote:
(2021-06-08, 13:29)Supersilver Wrote:
(2021-06-08, 12:59)SlartiBartFastFjord Wrote:  
Thanks for getting it to work always wanted a way to have Kodi as my main launcher, I'd be very interested in the APK if you could provide it some way, maybe a link to it on Google drive?
I don't use google nor do I have any file sharing locations I would like to share publicly, if you arrange somewhere to upload it I can upload it there. The best would probably be somewhere that is publicly available if there are more that want to download a copy. Otherwise the compiling is pretty straight forward using the instructions above, however depending on your hardware it will take some 24h for all of the build (but you obviously don't have to watch the screen for the duration, launch a step and check in every 8h or so).
https://gofile.io/uploadFiles

That sounds like the best place to host the APK so it requires no registration and can be shared easily, what do you think?
Reply
#10
Is Shield TV ARM?
Think I've read that..

And, will this Kodi version update. Or do you have to compile if there is an update?

Don't have the hardware to do this my self, that's why I ask.
Petter :-)
Many thanks for all the effort YOU all do! THANKS! :-)
nVidia Shield TV (2015), Samsung QE75Q70R and Yamaha RX-V767
Reply
#11
(2021-06-08, 15:24)Supersilver Wrote:
(2021-06-08, 15:14)SlartiBartFastFjord Wrote:
(2021-06-08, 13:29)Supersilver Wrote:  
https://gofile.io/uploadFiles

That sounds like the best place to host the APK so it requires no registration and can be shared easily, what do you think?
https://gofile.io/d/JISaWB

I take no responsibility for whatever happens to your devices/systems, all I can say is that those work on my 2015 Sony Bravia TV.
Reply
#12
(2021-06-08, 18:27)pettergulbra Wrote: Is Shield TV ARM?
Think I've read that..

And, will this Kodi version update. Or do you have to compile if there is an update?

Don't have the hardware to do this my self, that's why I ask.
Sorry, I have no idea what the architecture of Shield TV is.

Regarding updates, if you update you will overwrite the modified Kodi-version with a newer "stock" version. To use a newer version that source must be modified and then compiled.
Reply
#13
Hey can anyone that downloaded the APK re-upload it? As I seem to have lost the file in my stupidity
Reply
#14
Shield is arm64.
On an related note, why don't you put the code on github? That way a pull request can eventually be made for official inclusion in kodi
Reply
#15
Hello,
I'm trying to build Kodi for my FireTV, however I'm getting stuck at the fifth step in the build guide. I'm building inside an Ubuntu Docker container on an Arch Linux host and this is my error message:
ixemusuneh (paste)
What is wrong here? Does samba-gplv3 cause this issue?
Reply

Logout Mark Read Team Forum Stats Members Help
Modifying Kodi to use as launcher0