JonForShort / android-tools

Android tools built for Android devices.
Apache License 2.0
155 stars 26 forks source link

Build Failed #2

Closed Amoystyle closed 5 years ago

Amoystyle commented 5 years ago
arno@arno-ubuntu:~/android$ make aapt
##============================================
PLATFORM_VERSION_CODENAME=Q
PLATFORM_VERSION=Q
TARGET_PRODUCT=aosp_arm
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.18.0-25-generic-x86_64-Ubuntu-18.04.2-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=PI
OUT_DIR=out
##============================================
[ 99% 10221/10225] //frameworks/base/tools/aapt:aapt link aapt
FAILED: out/soong/.intermediates/frameworks/base/tools/aapt/aapt/android_arm_armv7-a-neon_core/unstripped/aapt
prebuilts/clang/host/linux-x86/clang-r349610/bin/clang++ out/soong/.intermediates/bionic/libc/crtbegin_static/android_arm_armv7-a-neon_core/crtbegin_static.o @out/soong/.intermediates/frameworks/base/tools/aapt/aapt/android_arm_armv7-a-neon_core/unstripped/aapt.rsp -Wl,--whole-archive  out/soong/.intermediates/frameworks/base/tools/aapt/libaapt/android_arm_armv7-a-neon_core_static/libaapt.a out/soong/.intermediates/build/soong/cc/libbuildversion/libbuildversion/android_arm_armv7-a-neon_core_static/libbuildversion.a -Wl,--no-whole-archive  -Wl,--start-group out/soong/.intermediates/frameworks/base/libs/androidfw/libandroidfw/android_arm_armv7-a-neon_core_static/libandroidfw.a out/soong/.intermediates/external/libpng/libpng/android_arm_armv7-a-neon_core_static/libpng.a out/soong/.intermediates/system/core/libutils/libutils/android_arm_armv7-a-neon_core_static/libutils.a out/soong/.intermediates/system/core/libcutils/libcutils/android_arm_armv7-a-neon_core_static/libcutils.a out/soong/.intermediates/external/expat/libexpat/android_arm_armv7-a-neon_core_static/libexpat.a out/soong/.intermediates/system/core/libziparchive/libziparchive/android_arm_armv7-a-neon_core_static/libziparchive.a out/soong/.intermediates/system/core/base/libbase/android_arm_armv7-a-neon_core_static/libbase.a out/soong/.intermediates/system/core/liblog/liblog/android_arm_armv7-a-neon_core_static/liblog.a out/soong/.intermediates/external/zlib/libz/android_arm_armv7-a-neon_core_static/libz.a out/soong/.intermediates/external/libcxx/libc++_static/android_arm_armv7-a-neon_core_static/libc++_static.a out/soong/.intermediates/external/libunwind_llvm/libunwind_llvm/android_arm_armv7-a-neon_core_static/libunwind_llvm.a out/soong/.intermediates/bionic/libm/libm/android_arm_armv7-a-neon_core_static/libm.a out/soong/.intermediates/bionic/libc/libc/android_arm_armv7-a-neon_core_static/libc.a out/soong/.intermediates/bionic/libdl/libdl/android_arm_armv7-a-neon_core_static/libdl.a -Wl,--end-group -Wl,--start-group out/soong/.intermediates/bionic/libc/libc/android_arm_armv7-a-neon_core_static/libc.a prebuilts/clang/host/linux-x86/clang-r349610/lib64/clang/8.0.8/lib/linux/libclang_rt.builtins-arm-android.a prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/lib/libatomic.a prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/lib/gcc/arm-linux-androideabi/4.9.x/libgcc.a -Wl,--end-group out/soong/.intermediates/bionic/libc/crtend_android/android_arm_armv7-a-neon_core/obj/bionic/libc/arch-common/bionic/crtend.o -o out/soong/.intermediates/frameworks/base/tools/aapt/aapt/android_arm_armv7-a-neon_core/unstripped/aapt -target armv7a-linux-androideabi -Bprebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/bin -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined-version -fuse-ld=lld -Wl,--pack-dyn-relocs=android+relr -Wl,--use-android-relr-tags -Wl,--no-undefined -Wl,--icf=safe -Wl,--hash-style=gnu -Wl,-m,armelf  -static -nostdlib -Bstatic -Wl,--gc-sections -Wl,--exclude-libs,libunwind_llvm.a prebuilts/clang/host/linux-x86/clang-r349610/lib64/clang/8.0.8/lib/linux/libclang_rt.ubsan_minimal-arm-android.a -Wl,--exclude-libs,libclang_rt.ubsan_minimal-arm-android.a

ld.lld: error: undefined symbol: set_sched_policy

>>> referenced by Threads.cpp:0 (system/core/libutils/Threads.cpp:0)

>>> Threads.o:(thread_data_t::trampoline(thread_data_t const*)) in archive

out/soong/.intermediates/system/core/libutils/libutils/android_arm_armv7-a-neon_core_static/libutils.a clang-8: error: linker command failed with exit code 1 (use -v to see invocation) 15:22:10 ninja failed with: exit status 1 build/make/core/main.mk:21: recipe for target 'run_soong_ui' failed make: *** [run_soong_ui] Error 1

lem0nez commented 5 years ago

Make sure, that you also patched androidfw library, as aapt depends on it. After patching the files, try following commands:

  1. . ~/android/build/envsetup.sh — define environment commands for building;
  2. cd ~/android/frameworks/base/tools/aapt && mm — build aapt using Ninja build system, instead of using the Makefile.
lem0nez commented 5 years ago

If it doesn't help, try android-tools-builder script: it automatically will do all for you.

Amoystyle commented 5 years ago

Hi @lem0nez , Thanks for your time and attention for my request. I will test it and tell you about results.

Amoystyle commented 5 years ago

If it doesn't help, try android-tools-builder script: it automatically will do all for you.

Android: master

the same error, when I build aapt using Ninja build system

inimal-arm-android.a ld.lld: error: undefined symbol: set_sched_policy referenced by Threads.cpp:0 (system/core/libutils/Threads.cpp:0) Threads.o:(thread_data_t::trampoline(thread_data_t const*)) in archive out/soong/.intermediates/system/core/libutils/libutils/android_arm_armv7-a-neon_core_static/libutils.a clang-9: error: linker command failed with exit code 1 (use -v to see invocation) 17:11:20 ninja failed with: exit status 1

lem0nez commented 5 years ago

@Amoystyle, script should sync the latest branch, which have following format: android-X.X.X_rX. But it synced the master branch. What is the output of this command?

git ls-remote -h 'https://android.googlesource.com/platform/manifest' | \
    sed -r 's#^.+/##g; /^android-[1-9]/!d' | \
    sort -rV | awk 'NR==1'
rupeshkumar22 commented 5 years ago

Please tell me how can I use these tools in android studio project to create R.java and Dex files etc from source files exactly as on windows ..Sry I am kind of new to these native libraries

Amoystyle commented 5 years ago

@Amoystyle, script should sync the latest branch, which have following format: android-X.X.X_rX. But it synced the master branch. What is the output of this command?

git ls-remote -h 'https://android.googlesource.com/platform/manifest' | \
    sed -r 's#^.+/##g; /^android-[1-9]/!d' | \
    sort -rV | awk 'NR==1'
 arno@arno-virtual-machine:~/Develop/Android/frameworks/base/tools/aapt$ mm
 ============================================
 PLATFORM_VERSION_CODENAME=R
 PLATFORM_VERSION=R
 TARGET_PRODUCT=aosp_arm
 TARGET_BUILD_VARIANT=eng
 TARGET_BUILD_TYPE=release
 TARGET_ARCH=arm
 TARGET_ARCH_VARIANT=armv7-a-neon
 TARGET_CPU_VARIANT=generic
 HOST_ARCH=x86_64
 HOST_2ND_ARCH=x86
 HOST_OS=linux
 HOST_OS_EXTRA=Linux-4.18.0-25-generic-x86_64-Ubuntu-18.04.2-LTS
 HOST_CROSS_OS=windows
 HOST_CROSS_ARCH=x86
 HOST_CROSS_2ND_ARCH=x86_64
 HOST_BUILD_TYPE=release
 BUILD_ID=PI
 OUT_DIR=out
 ============================================
 [100% 58/58] Install: out/host/windows-x86/nativetest64/libaapt_tests/libaapt_te

 #### build completed successfully (14 seconds) ####

do something about it

system/core/libutils/Threads.cpp


// we use this trampoline when we need to set the priority with
// nice/setpriority, and name with prctl.
static int trampoline(const thread_data_t* t) {
thread_func_t f = t->entryFunction;
void* u = t->userData;
int prio = t->priority;
char * name = t->threadName;
delete t;
setpriority(PRIO_PROCESS, 0, prio);
//if (prio >= ANDROID_PRIORITY_BACKGROUND) {
//    set_sched_policy(0, SP_BACKGROUND);
//} else {
//    set_sched_policy(0, SP_FOREGROUND);
//}
if (name) {
    //androidSetThreadName(name);
    free(name);
}
return f(u);

}

```c++
int androidSetThreadPriority(pid_t tid, int pri)
{
    int rc = 0;
    int lasterr = 0;

    //if (pri >= ANDROID_PRIORITY_BACKGROUND) {
    //    rc = set_sched_policy(tid, SP_BACKGROUND);
    //} else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) {
    //    rc = set_sched_policy(tid, SP_FOREGROUND);
    //}

    //if (rc) {
    //    lasterr = errno;
    //}

    if (setpriority(PRIO_PROCESS, tid, pri) < 0) {
        rc = INVALID_OPERATION;
    } else {
        errno = lasterr;
    }

    return rc;
}
Amoystyle commented 5 years ago
arno@arno-virtual-machine:~$ cd ~/Develop/Android/
arno@arno-virtual-machine:~~/Develop/Android$ . build/envsetup.sh
arno@arno-virtual-machine:~~/Develop/Android$ cd ~/Develop/Android/frameworks/base/tools/aapt
arno@arno-virtual-machine:~/Develop/Android/frameworks/base/tools/aapt$ mm
============================================
PLATFORM_VERSION_CODENAME=R
PLATFORM_VERSION=R
TARGET_PRODUCT=aosp_arm
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a-neon
TARGET_CPU_VARIANT=generic
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.18.0-25-generic-x86_64-Ubuntu-18.04.2-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=PI
OUT_DIR=out
============================================
[100% 117/117] Install: out/host/windows-x86/nativetest64/libaapt_tests/libaapt_tests.exe

#### build completed successfully (02:07 (mm:ss)) ####
ld.lld: error: undefined symbol: set_sched_policy
referenced by Threads.cpp:0 (system/core/libutils/Threads.cpp:0)
Threads.o:(thread_data_t::trampoline(thread_data_t const*)) in archive out/soong/.intermediates/system/core/libutils/libutils/android_arm_armv7-a-neon_core_static/libutils.a
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)
17:11:20 ninja failed with: exit status 1

do something about it

/Android/frameworks/base/tools/aapt/Android.bp

// Defaults for the target Android devices.
cc_defaults {
    name: "aapt_defaults_target",

    static_libs: [
        "libandroidfw_target",
        "libpng",
        "libutils",
        "liblog",
        "libcutils",
        "libexpat",
        "libziparchive",
        "libbase",
        "libz",
        "libjsoncpp",           // <-- add it
        "libcgrouprc_format",   // <-- add it
        "libcgrouprc",          // <-- add it
        "libprocessgroup",      // <-- add it
    ],
    group_static_libs: true,
    static_executable: true,

    cflags: [
        "-Wall",
        "-Werror",
    ],

    target: {
        android: {
            enabled: true,
        },
    },

    // This tool is prebuilt if we're doing an app-only build.
    product_variables: {
        pdk: {
            enabled: false,
        },
        unbundled_build: {
            enabled: false,
        },
    },
}