[JAVA] Android OS (7.1.2) build and Hello World

What to do

  1. Get and build Android 7.1.2 source and write to Nexus 9
  2. Customized to display the "Hello, world!" Dialog at startup

Preparation

Installation of JDK 8 http://qiita.com/niusounds/items/1f32dcd6fa1f57ade98a

Download source code

$ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo
$ mkdir -p aosp/7.1.2
$ cd aosp
$ ~/bin/repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.2_r17
$ ~/bin/repo sync
...
Checking out files: 100% (6377/6377), done. out files:  26% (1719/6377)   
Checking out files: 100% (1717/1717), done.
Checking out files: 100% (44431/44431), done.
Checking out files: 100% (62/62), done.king out files:  14% (9/62)   
Checking out files: 100% (1756/1756), done.
Checking out files: 100% (8484/8484), done.
Checking out files: 100% (539/539), done.ng out files:  28% (151/539)   
Checking out files: 100% (15774/15774), done.ut files:   7% (1128/15774)   
Checking out files: 100% (25/25), done.
Syncing work tree: 100% (529/529), done. 

Build source

Java settings

$ export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
$ export PATH=$PATH:$JAVA_HOME/bin

Build settings

$ source build/envsetup.sh 
$ lunch
Lunch menu... pick a combo:
     1. aosp_arm-eng
     2. aosp_arm64-eng
     3. aosp_mips-eng
     4. aosp_mips64-eng
     5. aosp_x86-eng
     6. aosp_x86_64-eng
     7. full_fugu-userdebug
     8. aosp_fugu-userdebug
     9. mini_emulator_arm64-userdebug
     10. m_e_arm-userdebug
     11. m_e_mips-userdebug
     12. m_e_mips64-eng
     13. mini_emulator_x86-userdebug
     14. mini_emulator_x86_64-userdebug
     15. aosp_dragon-userdebug
     16. aosp_dragon-eng
     17. aosp_marlin-userdebug
     18. aosp_sailfish-userdebug
     19. aosp_flounder-userdebug
     20. aosp_angler-userdebug
     21. aosp_bullhead-userdebug
     22. hikey-userdebug
     23. aosp_shamu-userdebug

Which would you like? [aosp_arm-eng] aosp_flounder-eng ← Select according to the terminal you want to build(https://forum.xda-developers.com/wiki/Google/Device_Codenames)

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=7.1.2
TARGET_PRODUCT=aosp_flounder
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=denver64
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv7-a-neon
TARGET_2ND_CPU_VARIANT=denver
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.4.0-78-generic-x86_64-with-debian-stretch-sid
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=NJH47B
OUT_DIR=out
============================================

Build

$ make -j8 &> makelog_`date "+%Y%m%d_%H%M%S"`.txt

makelog_20170627_010549.txt


...
[ 99% 49532/49533] host C++: primitives_tests_32 <= system/media/audio_utils/tests/primitives_tests.cpp
[100% 49533/49533] host Executable: primitives_tests_32 (out/host/linux-x86/obj32/EXECUTABLES/primitives_tests_intermediates/primitives_tests32)

[0;32m#### make completed successfully (02:12:53 (hh:mm:ss)) ####[00m

Write Android Factory Image to Nexus 9

  1. Download the Factory Image of the target terminal from the following and decompress it. https://developers.google.com/android/images (I downloaded 7.1.1 because there was no 7.1.2 of Nexus 9 (flounder))
  2. Execute "adb reboot bootloader" from the command prompt Run flash-all.bat in the file unzipped in 3.1

Write the built system.img and boot.img

Write the build product below. /out/target/product/flounder/system.img /out/target/product/flounder/boot.img

$ adb reboot bootloader
$ fastboot flash boot <boot.Folder path with img>/boot.img
$ fastboot flash system <system.Folder path with img>/system.img
$ fastboot reboot
Screenshot_20170627-123118.png Screenshot_20170627-123125.png

Hello, World!

Source modification

Customize to display the "Hellor, World!" Dialog at startup.

Put the following modifications at the end of ActivityManagerService # finishBooting called when boot is completed.

https://android.googlesource.com/platform/frameworks/base/+/android-7.1.2_r17/services/core/java/com/android/server/am/ActivityManagerService.java#finishBooting

ActivityManagerService.java


...
                mUserController.sendBootCompletedLocked(
                        new IIntentReceiver.Stub() {
                            @Override
                            public void performReceive(Intent intent, int resultCode,
                                    String data, Bundle extras, boolean ordered,
                                    boolean sticky, int sendingUser) {
                                synchronized (ActivityManagerService.this) {
                                    requestPssAllProcsLocked(SystemClock.uptimeMillis(),
                                            true, false);
                                }
                            }
                        });
                scheduleStartProfilesLocked();
            }
         }

+        AlertDialog.Builder builder = new AlertDialog.Builder(mContext)
+            .setTitle("Hello, World!");
+        Dialog dialog = builder.create();
+        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
+        dialog.show();
    }

"Build Build the corrected part with pinpoint

~/AOSP/7.1.2$ mmm frameworks/base/services
...
#### make completed successfully (32 seconds) ####

The build product is output to the following

out/target/product/flounder/system/framework/services.jar

Write to terminal

Replace services.jar in the terminal with the built services.jar

$ adb remount
$ adb push <services.Folder path with jar>/services.jar /system/framework/.
$ adb reboot
Screenshot_20170627-124524.png

Recommended Posts

Android OS (7.1.2) build and Hello World
Build Java environment and output hello world [Beginner]
Hello World with Docker and C
Hello World with GWT 2.8.2 and Maven
Hello world in Java and Gradle
Hello world with Kotlin and Tornado FX
Minimal Java environment construction and Hello World
Read "Hello world"
Java, Hello, world!
Java Hello World
Beginners try using android studio Part 1 (Hello World)
Until you install Gradle and output "Hello World"
"Hello World" in Java
Java Learning (1)-Hello World
Read System.out.println ("hello, world")
Let's write Hello World
Hello world in node.js
Hello World in Java
Studying Java-Part 1-Hello World
Hello World on WebAssembly
Hello World with Micronaut
Hello World comparison between Spark Framework and Spring Boot
Until Android Studio beginners display "Hello World" on HUAWEI nova 2
Hello World with Spring Boot!
java hello world, compile, run
Java beginners read Hello World
Build Spring for Android 2.0.0 environment
Hello World with SpringBoot / Gradle
Hello, World! With Asakusa Framework!
[Swift] Create a project with Xcode (ver 12.1) and display "Hello, World!"
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
Get the acceleration and bearing of the world coordinate system on Android