Video Tutorial for Building Android: Advanced Topics

twrp
Praise God! Another video series featuring more advanced material!
Previously, I had created a video tutorial and guide for how to compile Android, from Lollipop through Marshmallow, Nougat, and Oreo. If you need help learning the basics or intermediate material, please see my other video tutorial thread on XDA, Or here on my website through the navigation bar at the top.

Who is this video series for?
Well, this video tutorial is a guide built primarily for the intermediate Android developer. This is written for those who already know how to compile custom roms for a phone that they own using device trees and vendor files that are already available. Things like using git, GitHub, GitLab, ADB, fastboot, and repo sync should already be something familiar to them.

That said, I believe that an intermediate developer will find this set of videos to be most helpful. The goal of this video series is to push the intermediate developer up to a rudimentary advanced level.

Advanced developer?
An advanced rom/kernel developer will probably far exceed my feeble abilities, and will not likely find much useful information here. Perhaps if you are an advanced developer, you would consider making another tutorial or adding to this advanced video series! (See further posts for recommendations on contributing videos.) Please! I’d really like to add links to your YouTube channel, or your git repository full of advanced topics for developers! Help up the quality of devices and builds of Android by showing others what you know how to do best!

Why did you put this together?
Well, after releasing the previous tutorial, explaining to beginners how to use things like git, repo sync, compile roms, and do small kernel modification, it was brought to my attention that a more advanced course was needed for intermediate users who already know how to build roms, but may (like myself) struggle with more complicated tasks. I don’t know how to do everything, and we all have to take the next step sometime, so why not take that next step together?

What’s in the videos?
During the series, we will be attempting several more advanced tasks. At present, there is not a lot in the series, but below are some of the highlights from what is available.

  • A: Building a device tree from scratch
  • B: Upgrading a device from Marshmallow to Nougat
  • C: Creating your very own custom rom!

Section A: Building a device tree from scratch:

+ Research
+ Finding similar devices
+ Pulling vendor files
+ Setting up a device tree
+ Getting block device information
+ Pulling kernel information
+ Breaking down boot images
+ Build errors
+ Target Assets
+ Tombstones AND MORE!

Download links: The video quality is now HD!
MP4 Video GitLab:
https://gitlab.com/alaskalinuxuser/advanced_course_android_developer_guide_mp4

MP4 Video Downloads:
https://gitlab.com/alaskalinuxuser/advanced_course_android_developer_guide_mp4/-/archive/master/advanced_course_android_developer_guide_mp4-master.zip

YouTube links: The YouTube quality is now HD!
https://www.youtube.com/watch?v=5c66tBsiVVM&list=PLRJ9-cX1yE1nnhWBrZtuVz5YC2OPfQVVp

Section B: Upgrading a device from Marshmallow to Nougat (Work in progress) :

+ Research
+ Finding similar devices
+ Comparing changes
+ Editing a device tree
+ Build errors
+ AND MORE!

Download links: The video quality is now HD!
MP4 Video GitLab:
https://gitlab.com/alaskalinuxuser/HD_Android_Compile_Upgrade_MN_Videos

MP4 Video Downloads:
https://gitlab.com/alaskalinuxuser/HD_Android_Compile_Upgrade_MN_Videos/-/archive/master/HD_Android_Compile_Upgrade_MN_Videos-master.zip

YouTube links: The YouTube quality is now HD!
https://www.youtube.com/playlist?list=PLRJ9-cX1yE1lm9qFpVkOBO1oFJVFFK-fk

Section C: Creating your very own custom rom! (Work in progress) :

+ Research
+ Forking a base rom
+ Adding to the manifest
+ Editing which apps are built
+ Editing settings/files/display
+ AND MORE!

Download links: The video quality is now HD!
MP4 Video GitLab:
https://gitlab.com/alaskalinuxuser/hd_makinganewcustomrom

MP4 Video Downloads:
https://gitlab.com/alaskalinuxuser/hd_makinganewcustomrom/-/archive/master/hd_makinganewcustomrom-master.zip

YouTube links: The YouTube quality is now HD!
https://www.youtube.com/playlist?list=PLRJ9-cX1yE1nTAc0uM17HL9KuN__GDexh

My device and kernel trees:

  1. (GitHub) : https://github.com/alaskalinuxuser/
  2. (GitLab) : https://gitlab.com/alaskalinuxuser/

Linux – keep it simple.

Advertisements

enum class is not a class unless it’s -std=c++11

treestuff

As I progress through the C++ course at Udemy, I’ve just completed section 4. However, I ran into a few snags along the way. Some of them are due to differences between the instructor using Windows, and me using Linux. Most notably, I ran into a complete showstopper that took me a while to figure out, so I’ll share it here.

g++ -Wall -c “Timber.cpp”
Timber.cpp:17:1: warning: scoped enums only available with -std=c++11 or -std=gnu++11
enum class side { LEFT, RIGHT, NONE };
^
Timber.cpp: In function ‘int main()’:
Timber.cpp:169:20: error: ‘side’ is not a class or namespace
side playerSide = side::LEFT;
^
Timber.cpp:264:26: error: ‘side’ is not a class or namespace
branchPositions[i] = side::NONE;
^
Timber.cpp:287:18: error: ‘side’ is not a class or namespace
playerSide = side::RIGHT;
^
Timber.cpp:321:18: error: ‘side’ is not a class or namespace
playerSide = side::LEFT;
^
Timber.cpp:534:31: error: ‘side’ is not a class or namespace
if (branchPositions[i] == side::LEFT)
^
Timber.cpp:542:36: error: ‘side’ is not a class or namespace
else if (branchPositions[i] == side::RIGHT)
^
Timber.cpp: In function ‘void updateBranches(int)’:
Timber.cpp:688:24: error: ‘side’ is not a class or namespace
branchPositions[0] = side::LEFT;
^
Timber.cpp:692:24: error: ‘side’ is not a class or namespace
branchPositions[0] = side::RIGHT;
^
Timber.cpp:696:24: error: ‘side’ is not a class or namespace
branchPositions[0] = side::NONE;
^
Compilation failed.

Per the instructor, I typed out the branches (literally, tree branches) and I get this odd error about the enum class side not being a class or namespace. The key was this portion:

warning: scoped enums only available with -std=c++11 or -std=gnu++11

A Google search and a bit of perusing lead me to change my build script to this:

#!/bin/bash

# You need libsfml installed on your system!

g++ -c -std=c++11 Timber.cpp
g++ Timber.o -o timber-app -lsfml-graphics -lsfml-window -lsfml-system

./timber-app

echo “type ./timber-app to launch”
exit

In order to get it to compile, I had to declare the -std=c++11 during the build. I added it to my Geany program as well, under the settings.

geany11

Now it compiles without issue! So far, I’ve only added some bushy branches to my game, but it is coming along nicely! You can check it out at my GitLab if you’d like.

Linux – keep it simple.

Update to Rom/Kernel/TWRP building guide!

Hey everyone!

Just wanted to let you know that I was able to finish and upload another hour worth of videos! That’s right, currently there is more than 9 hours of video tutorial available. As promised, this was added to the series:

* Installing/using VirtualBox
* Fixing a VB Ubuntu problem with screen resolution
* Syncing minimal LineageOS or Omni for building TWRP
* Converting an Omni TWRP device to LineageOS/CM and building it.
* Custom TWRP mods with fonts/icons/splash screens/etc….

twrp

Hope that you are enjoying the series, but mostly, I hope that it is informative and gets you building!
I did try to up the video quality, but I had to tone it back down a bit, as the files became a bit large for uploading and handling. The quality is a little better than the first videos, but not exactly 1080p! 

Thanks again for all of the thanks button slaps and YouTube subscriptions. That lets me know that you guys really appreciate the videos. Be sure to check out my Video Tutorial section in the menu for links to the videos!

Linux – keep it simple.

Video Tutorial on How to Compile Android and Modify Kernels

video

For those interested, I have just posted a video tutorial series on XDA for building Android Oreo, Nougat, Marshmallow, and Lollipop on 5 different phones, the emulator, and 5 different ROMs. Also included are custom kernel editing, adding apps, changing source code, backgrounds, and more. Here’s what I posted:

From XDA: https://forum.xda-developers.com/android/general/guide-how-to-build-custom-roms-kernel-t3814251

===========================================================================

Praise God! Finally a video tutorial of how to build Android and modify kernels!

I have created a video tutorial and guide for how to compile Android, from Lollipop through Marshmallow, Nougat, and Oreo. The video series covers several different phones, the emulator, kernel and rom editing, app source code editing, and much more!

Who is this video series for?
Well, this video tutorial is a step by step guide built primarily for the beginner. This is written for those who already know how to flash TWRP, CWM, or the like, and who have installed a custom rom before. This is designed to help those who are ready to move up from flashing and installing other peoples custom rom to actually start making their own custom roms. I recommend that a beginner watch the entire series in numerical/alphabetical order (the videos are marked).

That said, I believe that an intermediate developer may find a useful trick here and there, and they should just skip ahead to videos of interest. Perhaps kernel development, or something along those lines.

An advanced rom/kernel developer will probably far exceed my feeble abilities, and will not likely find much useful information here. Perhaps if you are an advanced developer, you would consider continuing the tutorial or making an advanced video series! (See further posts for recommendations on contributing videos.)

Why did you put this together?
Well, after building roms for several different devices, I started receiving requests from users who wanted to start building their own roms, but didn’t know how. I didn’t have enough time to answer everyones questions, so I wrote a few guides, pointed others to guides that were available, but there are some things that you just need to see to understand. Hence, the video tutorial. I just hope that someone finds it useful.

This course was written in order! While Lollipop and Marshmallow are old by today’s standards, there is still good learning value in building them, and there are topics covered there that really make them worth watching.

What’s in the videos?
During the series, we will be building for the emulator, as well as 5 different phones of various brands, and 5 different roms. I hope that this will give the viewer a good idea of how to build for their own specific phone as they see the differences and similarities across the phones and custom roms.

[CODE]
+ Ubuntu installation
+ Java installations
+ Using Git, GitHub, GitKraken, and the command line
+ Fastboot and ADB
+ Heimdall/Odin
+ QFIL, QPST, SALT, and other tools
+ AOSP, SlimRoms, PACrom, AOKP, AOSCP
+ Lollipop, Marshmallow, Nougat, Oreo
+ Errors
+ Overclocking CPU/GPU
+ Adding Governors and I/O Schedulers
+ Sound modifications
+ Changing app colors, text, and icons
+ Adding prebuilt apps
+ Adding source code
+ Converting device from one rom to another
+ AND MORE!
[/CODE]

**** This is an UNOFFICIAL TUTORIAL. Use at your own risk! ****
Download links:
Ogg Vorbis Video GitLab:
[url]https://gitlab.com/alaskalinuxuser/course_android_developer_guide[/url]
Clicking on a video in GitLab will allow you to watch it online.

Ogg Vorbis Video Downloads:
[url]https://gitlab.com/alaskalinuxuser/course_android_developer_guide/-/archive/master/course_android_developer_guide-master.zip[/url]
This download is rather large due to the multiple videos.

MP4 Video GitLab:
[url]https://gitlab.com/alaskalinuxuser/course_android_developer_guide_mp4[/url]
Clicking on a video in GitLab will allow you to watch it online.

MP4 Video Downloads:
[url]https://gitlab.com/alaskalinuxuser/course_android_developer_guide_mp4/-/archive/master/course_android_developer_guide_mp4-master.zip[/url]
This download is rather large due to the multiple videos.

I also have several written guides available on XDA, here are a few:

Building ROMs for the Galaxy Note Edge: [url]https://forum.xda-developers.com/note-edge/general/guide-build-aosp-roms-kernels-note-edge-t3488840[/url]
Building ROMs for the Galaxy S4: [url]https://forum.xda-developers.com/galaxy-s4-tmobile/general/guide-step-step-instructions-building-t3402637[/url]

===========================================================================

Be sure to check out the videos or the XDA thread! I hope that these will help some of the aspiring Android developers out there!

Linux – keep it simple.

Geany: the little IDE that could!

geany_ide.png

Recently, while working with some older equipment, I needed a lightweight java IDE to compile some java projects. I really wasn’t looking for something quite as big as eclipse or netbeans, I just wanted a simple, one stop solution that would allow me to build java programs on an older laptop.

So, I rubbed a magic lamp, and out popped Geany!

Well, more specifically, the laptop is running Debian Wheezy, and had openJDK already installed. With that alone, I could have built java programs from the command line, but it can get a little tedious. So, I looked on the repositories for an IDE that wasn’t too large.

Thus enter Geany. I first used Geany a long time ago as a text editor on #! (CrunchBang) Linux, but revisiting the program revealed that I was not using it to it’s full potential. Specifically, you can compile, build, and run various program types from within Geany. Of course, it only outsources the commands for you, so you need a java jdk in order to compile java, or a c++ compiler to compile c++. Geany just does all the command line work for you.

What Geany does accomplish for you, however, is a great user interface with templates and the ability to organize projects or view code with different filters. As you can see in the picture, I was testing out Logic Crazy’s Alpha Beta Chess program.

As well as showing you the code, it can do parenthesis highlighting, colors for different code type, and a class and method tree on the side. It really is a great program if you need a lightweight IDE. I know that I’ll be putting it to good use.

Linux – keep it simple.

error: use of undeclared identifier ‘LED_ADJUSTMENT_G’

After synching my source with AOKP for Nougat 7.1.2, I ran into this error when trying to build for the JFLTETMO:

[CODE]
target thumb C: lights.MSM8960 <= hardware/samsung/liblights/lights.c
hardware/samsung/liblights/lights.c:215:40: error: use of undeclared identifier ‘LED_ADJUSTMENT_R’
int red = ((color >> 16) & 0xFF) * LED_ADJUSTMENT_R;
^
hardware/samsung/liblights/lights.c:216:41: error: use of undeclared identifier ‘LED_ADJUSTMENT_G’
int green = ((color >> 8) & 0xFF) * LED_ADJUSTMENT_G;
^
hardware/samsung/liblights/lights.c:217:33: error: use of undeclared identifier ‘LED_ADJUSTMENT_B’
int blue = (color & 0xFF) * LED_ADJUSTMENT_B;
^
hardware/samsung/liblights/lights.c:258:31: error: use of undeclared identifier ‘LED_BRIGHTNESS_BATTERY’
adjusted_brightness = LED_BRIGHTNESS_BATTERY;
^
hardware/samsung/liblights/lights.c:261:31: error: use of undeclared identifier ‘LED_BRIGHTNESS_NOTIFICATION’
adjusted_brightness = LED_BRIGHTNESS_NOTIFICATION;
^
hardware/samsung/liblights/lights.c:264:31: error: use of undeclared identifier ‘LED_BRIGHTNESS_ATTENTION’
adjusted_brightness = LED_BRIGHTNESS_ATTENTION;
^
6 errors generated.
[/CODE]

Pretty simple, as we have talked about this before. In the past, I actually removed these lines from the light.c file, but this time I decided I would leave them in, and declare them instead. Essentially, the outcome is the same though for this build.

What these lines do is allow for custom liblight configurations. Perhaps a particular phone or tablet has a built in LED notification light where the green is brighter than the red or blue. In that case, every mixed color made from those LEDs will look strange. This gives the rom maker the option to “dim” down one or all three of the lights. The same applies for the brightness of the battery, notification, or attention lights.

As you can see below, I just declared them with the default values:

[CODE]
return err;
}

// WJH declaring these undeclared lights.
int LED_ADJUSTMENT_R = 1;
int LED_ADJUSTMENT_G = 1;
int LED_ADJUSTMENT_B = 1;
// WJH declaring these undeclared lights.

static int calibrate_color(int color, int brightness)
{
int red = ((color >> 16) & 0xFF) * LED_ADJUSTMENT_R;
int green = ((color >> 8) & 0xFF) * LED_ADJUSTMENT_G;
int blue = (color & 0xFF) * LED_ADJUSTMENT_B;

return (((red * brightness) / 255) << 16) + (((green * brightness) / 255) << 8) + ((blue * brightness) / 255);
}

…………EDITED FOR SPACE………………

led->delay_off = state->flashOffMS;
break;
default:
return -EINVAL;
}

// WJH declaring these brightness adjustments.
int LED_BRIGHTNESS_BATTERY = 255;
int LED_BRIGHTNESS_NOTIFICATION = 255;
int LED_BRIGHTNESS_ATTENTION = 255;
// WJH declaring these brightness adjustments.

switch (type) {
case TYPE_BATTERY:
adjusted_brightness = LED_BRIGHTNESS_BATTERY;
break;
case TYPE_NOTIFICATION:
adjusted_brightness = LED_BRIGHTNESS_NOTIFICATION;
break;
case TYPE_ATTENTION:
adjusted_brightness = LED_BRIGHTNESS_ATTENTION;
break;
default:
adjusted_brightness = 255;
}
[/CODE]

 

For the LED_ADJUSTMENT_R/G/B, I gave a value of 1. If you look at the math, it is used in the next formulae as (a & b) * LED_ADJUSTMENT_R/G/B. So if I set a value of 0, then the mathmatical outcome will be 0. If I set it at 1, then it will always be (a & b).

For the LED_BRIGHTNESS_BATTERY and so forth, I used the adjusted_brightness of 255, which is the default.

For both of these sets, I could have just removed them all together. But I build for several phones using the same source. By leaving them in, I should have an error if the device tree declared what is already declared in the lights.c file. Or at least that is my hope. In that case, then I could remove my handy work to make room for the actual values.

Linux – keep it simple.

undeclared identifier ‘POWER_HINT_LAUNCH_BOOST’

So, a new one for me. I’m building a rom for the H811, the T-Mobile variant of the LG G4. Currently building the tried and true AOKP 7.1.2 that I have used for my other phones, and I ran into an error:

[CODE]
target thumb C: power.msm8992_32 <= device/qcom/common/power/power-8992.c
device/qcom/common/power/power-8992.c:211:17: error: use of undeclared identifier 'POWER_HINT_LAUNCH_BOOST'; did you mean 'POWER_HINT_CPU_BOOST'?
if (hint == POWER_HINT_LAUNCH_BOOST) {
^~~~~~~~~~~~~~~~~~~~~~~
POWER_HINT_CPU_BOOST
hardware/libhardware/include/hardware/power.h:71:5: note: 'POWER_HINT_CPU_BOOST' declared here
POWER_HINT_CPU_BOOST = 0x00000110,
^
1 error generated.
[/CODE]

The suggested option was to change POWER_HINT_LAUNCH_BOOST to POWER_HINT_CPU_BOOST, but I didn't like that, since just a dozen lines later in the code, there was already an if/then statement for POWER_HINT_CPU_BOOST. Esentially, we need to either declare POWER_HINT_LAUNCH_BOOST, or get rid of it in our code. In this case, I decided to scrap it because if it was needed, then it would have existed already. Strange logic perhaps, but what we see is that if it is not called, it will not return anything anyways. If it is called, it just supplies some information that I think we can live without.

[/CODE]
// WJH was POWER_HINT_LAUNCH_BOOST
// WJH if (hint == POWER_HINT_LAUNCH_BOOST) {
// WJH launch_boost_info_t *info = (launch_boost_info_t *)data;
// WJH if (info == NULL) {
// WJH ALOGE("Invalid argument for launch boost");
// WJH return HINT_HANDLED;
// WJH }

// WJH ALOGV("LAUNCH_BOOST: %s (pid=%d)", info->packageName, info->pid);

// WJH int duration = 2000;
// WJH int resources[] = { SCHED_BOOST_ON, 0x20C };

// WJH start_prefetch(info->pid, info->packageName);
// WJH interaction(duration, ARRAY_SIZE(resources), resources);

// WJH return HINT_HANDLED;
// WJH }

if (hint == POWER_HINT_CPU_BOOST) {
int duration = *(int32_t *)data / 1000;
int resources[] = { SCHED_BOOST_ON };
………….EDITED FOR SPACE…………….
[/CODE]

That will cut it out of the loop, which means the loss of a feature, but I think it is one we can live without.

Linux – keep it simple.

POWER_HINT_LAUNCH_BOOST is not declared in this scope!

While building AOKP 7.1.2 for the kltevwz (the Verizon Samsung Galaxy S5), I ran into this error:

[CODE]

device/qcom/common/power/power-8974.c:143:17: error: ‘POWER_HINT_LAUNCH_BOOST’ was not declared in this scope …….Edited for space…….. make: *** Waiting for unfinished jobs….

[/CODE]

So, I headed over to device/qcom/common/power/power-8974.c, and this is what I saw:

[CODE]

if (hint == POWER_HINT_LAUNCH_BOOST) {
int duration = 2000;
int resources[] = { CPUS_ONLINE_MIN_3,
CPU0_MIN_FREQ_TURBO_MAX, CPU1_MIN_FREQ_TURBO_MAX,
CPU2_MIN_FREQ_TURBO_MAX, CPU3_MIN_FREQ_TURBO_MAX };

interaction(duration, ARRAY_SIZE(resources), resources);

return HINT_HANDLED;
}

[/CODE]

Looked pretty normal to me. However, when comparing to LineageOS’s 14.1 files, I saw that they dropped the “boost” from the name of the hint. So I edited mine to match, like so:

[CODE]

if (hint == POWER_HINT_LAUNCH) {
int duration = 2000;
int resources[] = { CPUS_ONLINE_MIN_3,
CPU0_MIN_FREQ_TURBO_MAX, CPU1_MIN_FREQ_TURBO_MAX,
CPU2_MIN_FREQ_TURBO_MAX, CPU3_MIN_FREQ_TURBO_MAX };

interaction(duration, ARRAY_SIZE(resources), resources);

return HINT_HANDLED;
}

[/CODE]

And, it built that part successfully! I like the easy problems!

Linux – keep it simple.

fatal error: ‘liblights/samsung_lights_helper.h’ file not found

Moving on from the S4, I began work on the Note Edge, only to be greeted with this error:

[CODE]
target thumb C: lights.APQ8084 <= hardware/samsung/liblights/lights.c
hardware/samsung/liblights/lights.c:34:10: fatal error: ‘liblights/samsung_lights_helper.h’ file not found
#include <liblights/samsung_lights_helper.h>
^
1 error generated.
[/CODE]

The fix was easy enough, I checked the folder, and sure enough, it was not there. So, I downloaded it from here:

https://github.com/LineageOS/android_hardware_samsung/tree/310d1999e5478a28b73eacbc5b4db62174431ee9/liblights

I like simple problems!

Linux – keep it simple.

Wframe-larger-than error!

It’s been a while since I’ve seen this happen, and although I’ve mentioned it before, it just goes to show that it is an ongoing issue. Let’s take a look at the output of the compiler:

[CODE]
/home/alaskalinuxuser/compile/build_cm14/kernel/samsung/tblte/drivers/input/touchscreen/wacom/wacom_i2c_flash.c: In function ‘wacom_i2c_flash’:
/home/alaskalinuxuser/compile/build_cm14/kernel/samsung/tblte/drivers/input/touchscreen/wacom/wacom_i2c_flash.c:622:1: warning: the frame size of 1152 bytes is larger than 1024 bytes [-Wframe-larger-than=]
error, forbidden warning: wacom_i2c_flash.c:622
make[5]: *** [drivers/input/touchscreen/wacom/wacom_i2c_flash.o] Error 1
make[4]: *** [drivers/input/touchscreen/wacom] Error 2
make[3]: *** [drivers/input/touchscreen] Error 2
make[2]: *** [drivers/input] Error 2
make[1]: *** [drivers] Error 2
make[1]: *** Waiting for unfinished jobs….
[/CODE]

The key part being here:

warning: the frame size of 1152 bytes is larger than 1024 bytes [-Wframe-larger-than=]
error, forbidden warning: wacom_i2c_flash.c:622

Typically, a warning is not going to stop your build process, but in some cases, the warning is so severe that it is flagged by predetermined settings that this type of warning would be an error. Errors, of course, stop the build.

In the case of frames being too large, I have usually found that (if it built sucessfully for someone else) the toolchain you are using is not sufficient for the task. So I headed over to UBERTC to download a newer toolchain.

https://bitbucket.org/UBERTC/

And, after downloading it, extracting it, and placing it in the build_cm14/prebuilts/gcc/linux-x86/arm folder, I then edited my device/samsung/tblte-common/BoardConfigCommon.mk file, like so:

[CODE]
KERNEL_TOOLCHAIN := /home/alaskalinuxuser/compile/build_cm14/prebuilts/gcc/linux-x86/arm/UBERTC-5.3/bin
KERNEL_TOOLCHAIN_PREFIX := arm-eabi-
[/CODE]

And away we go, there turned out to be some other errors as well, but this did solve the “too large” problem, as the new toolset built it in a way that was within tolerance.

Linux – keep it simple.