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.

Advertisements

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.

Yet again, error: package com.android.okhttp does not exist

By now, I think I would remember this one by heart, yet every time, this error throws me for a loop….

[CODE]
external/apache-http/../../frameworks/base/core/java/android/net/http/SslCertificate.java:19: error: cannot find symbol
import com.android.internal.util.HexDump;
^
symbol: class HexDump
location: package com.android.internal.util
external/apache-http/../../frameworks/base/core/java/android/net/http/SslCertificate.java:42: error: package com.android.org.bouncycastle.asn1.x509 does not exist
import com.android.org.bouncycastle.asn1.x509.X509Name;
^
external/apache-http/../../frameworks/base/core/java/android/net/http/HttpResponseCache.java:19: error: package com.android.okhttp does not exist
import com.android.okhttp.Cache;
^
external/apache-http/../../frameworks/base/core/java/android/net/http/HttpResponseCache.java:20: error: package com.android.okhttp does not exist
import com.android.okhttp.AndroidShimResponseCache;
^
external/apache-http/../../frameworks/base/core/java/android/net/http/HttpResponseCache.java:21: error: package com.android.okhttp does not exist
import com.android.okhttp.OkCacheContainer;
^
external/apache-http/../../frameworks/base/core/java/android/net/http/HttpResponseCache.java:152: error: cannot find symbol
public final class HttpResponseCache extends ResponseCache implements Closeable, OkCacheContainer {/home/alaskalinuxuser/compile/20170314_AOKP7/prebuilts/tools/common/m2/repository/com/squareup/okhttp/okhttp/2.5.0
^
symbol: class OkCacheContainer
external/apache-http/../../frameworks/base/core/java/android/net/http/HttpResponseCache.java:154: error: cannot find symbol
private final AndroidShimResponseCache delegate;
^
symbol: class AndroidShimResponseCache
location: class HttpResponseCache
external/apache-http/../../frameworks/base/core/java/android/net/http/HttpResponseCache.java:156: error: cannot find symbol
private HttpResponseCache(AndroidShimResponseCache delegate) {
^
symbol: class AndroidShimResponseCache
location: class HttpResponseCache
external/apache-http/../../frameworks/base/core/java/android/net/http/HttpResponseCache.java:296: error: cannot find symbol
public Cache getCache() {
^
symbol: class Cache
location: class HttpResponseCache
[/CODE]

And, from the same website that I fail to bookmark every time:

https://issuetracker.google.com/issues/37130763

These are caused by missing some package dependency. Following patch is used to fix it (for external/apache-http/Android.mk):

— a/Android.mk
+++ b/Android.mk
@@ -95,7 +95,7 @@ LOCAL_SRC_FILES += \
../../frameworks/base/core/java/android/net/http/SslError.java \

-LOCAL_JAVA_LIBRARIES := $(apache_http_java_libs)
+LOCAL_JAVA_LIBRARIES := $(apache_http_java_libs) okhttp bouncycastle framework
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_DROIDDOC_SOURCE_PATH := $(LOCAL_PATH)/src \
$(LOCAL_PATH)/android \

That’s it. Those few ines make the whole thing work. Hopefully, I’m saving someone else from scouring the internet for this problem. Again.

Linux – keep it simple.

SyntaxError: invalid syntax

As I was wrapping up my work on the upgrade to 7.1.2 on the S4, I ran into this error, which prevented the compiler from building the userdata.img file. Here’s the output:

[CODE]
get/product/jfltetmo/userdata.img
File “./build/tools/releasetools/build_image.py”, line 157
print cmd
^
SyntaxError: invalid syntax
[/CODE]

The fix was actually quite easy. I needed to encapsulate the cmd in parenthesis, like this:

./build/tools/releasetools/build_image.py

[CODE]
cmd = “fec -e -p %d %s %s %s” % (padding_size, sparse_image_path,
verity_path, verity_fec_path)
print (cmd) # WJH
status, output = commands.getstatusoutput(cmd)
[/CODE]

The proof is in the pudding, but what help was how the cmd is defined, then notice that the “status, output” line also puts cmd in parenthesis. So, I did the same for the print cmd line, and it worked!

Linux – keep it simple.

Healthd problems with pointers to fonts….

In the continuing saga of updating to 7.1.2, I’ve run into an interesting error about gr_text and gr_measure that are used to set the fonts properly when you are charging your phone while it is off. In 7.1.1, this worked just fine:

AOKP711/system/core/healthd/healthd_mode_charger.cpp

[CODE]
static int draw_text(const char *str, int x, int y)
{
int str_len_px = gr_measure(str);

if (x < 0)
x = (gr_fb_width() – str_len_px) / 2;
if (y < 0)
y = (gr_fb_height() – char_height) / 2;
gr_text(x, y, str, 0);

return y + char_height;
———- Abreviated for space ——————–
gr_init();
gr_font_size(&char_width, &char_height);

#ifndef CHARGER_DISABLE_INIT_BLANK
[/CODE]

But that didn’t work in 7.1.2. I found this github commit for a sony phone: https://github.com/sonyxperiadev/device-sony-common/pull/247 and was able to modify it enough to fix the S4, like so:

AOKP712/system/core/healthd/healthd_mode_charger.cpp

[CODE]
static int draw_text(const char *str, int x, int y)
{
int str_len_px = gr_measure(gr_sys_font(), str); // WJH

if (x < 0)
x = (gr_fb_width() – str_len_px) / 2;
if (y < 0)
y = (gr_fb_height() – char_height) / 2;
gr_text(gr_sys_font(), x, y, str, 0); // WJH

return y + char_height;
———- Abreviated for space ——————–
gr_init();
gr_font_size(gr_sys_font(), &char_width, &char_height); //WJH

#ifndef CHARGER_DISABLE_INIT_BLANK
[/CODE]

It even worked! Hopefully that can help someone else out as well.

Linux – keep it simple.