Android Builds of OpenJDK Mobile project now available

Bob Vandette bob.vandette at oracle.com
Wed Feb 17 21:15:46 UTC 2016


It appears that I was correct that the NDK has improved in the latest version wrt.
source level compatibility with the standard Linux distros and toolchains.

Here’s a webrev and patch that corrects compilation errors and allows both ARM and x86 Android
builds using the latest NDK r10e.  

http://cr.openjdk.java.net/~bobv/8150074/ <http://cr.openjdk.java.net/~bobv/8150074/>

We should inspect all #ifdef/#ifndef __ANDROID__ uses throughout the sources
to see if we can remove more unnecessary logic.

Bob.


> On Feb 17, 2016, at 12:44 PM, Bob Vandette <bob.vandette at oracle.com> wrote:
> 
> Ali,
> 
> You are correct that there are problems building JDK 9 for Android using the latest
> Android NDK (r10e).
> 
> I’ve filed an enhancement issue to track this problem.
> 
> https://bugs.openjdk.java.net/browse/JDK-8150074 <https://bugs.openjdk.java.net/browse/JDK-8150074>
> 
> If you have a chance to dig into these issues further, please do so and update the alias.
> If you get to the point of having a clean webrev, I can review it and help you integrate it.
> 
> Some of the static versus non-static issues may be related to the fact that we had to add
> implement a few missing bionic functions in our sources.  It’s possible that these conflicts
> are due to the fact that the NDK r10e now supports these functions.   The best solution
> is to remove our temporary implementations.
> 
> Many of the other issues may fall into the same category where the newer NDK may be
> getting closer to standard linux/glibc allowing us to remove android specific ifdefs.
> 
> As for the requirement to define the tools (CC, CXX, etc) this should not be necessary.
> Did you follow the instructions I posted on generating an NDK based toolchain?
> 
> Bob.
> 
> 
>> On Feb 17, 2016, at 6:38 AM, Ali Ebrahimi <ali.ebrahimi1781 at gmail.com <mailto:ali.ebrahimi1781 at gmail.com>> wrote:
>> 
>> Hi Bob,
>> I finally built mobile jdk for x86 and arm with some modifications:
>> I used:
>> OS: Ubuntu 15.10
>> NDK: android-ndk-r10e-linux-x86_64 with --platform=android-21 for building toolchain
>> 
>> But my modifications:
>> JDK:
>> Errors:
>> 1) error: static declaration of <some method> follows non-static declaration
>> 
>> diff -r 91482de10f40 src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c
>> --- a/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c	Wed Feb 10 14:17:12 2016 -0500
>> +++ b/src/java.base/linux/native/libjava/ProcessHandleImpl_linux.c	Tue Feb 16 21:06:55 2016 +0330
>> @@ -242,7 +242,7 @@
>>  }
>>  
>>  #ifdef __ANDROID__
>> -static int getline(char **line, size_t *len, FILE *fp) {
>> +int getline(char **line, size_t *len, FILE *fp) {
>>    char *buf;
>>    size_t bufLen;
>>    if (*line != NULL) {
>>  
>> diff -r 91482de10f40 src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c
>> --- a/src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c	Wed Feb 10 14:17:12 2016 -0500
>> +++ b/src/java.base/linux/native/libnio/fs/LinuxNativeDispatcher.c	Tue Feb 16 21:06:55 2016 +0330
>> @@ -174,7 +174,7 @@
>>  }
>>  
>>  #ifdef __ANDROID__
>> -static struct mntent* getmntent_r(FILE* fp, struct mntent* m, char* buf, int buflen) {
>> +struct mntent* getmntent_r(FILE* fp, struct mntent* m, char* buf, int buflen) {
>>      if (m) {
>>          char *str;
>>          char *last;
>> diff -r 91482de10f40 src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c
>> --- a/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c	Wed Feb 10 14:17:12 2016 -0500
>> +++ b/src/java.base/unix/native/libjava/ProcessHandleImpl_unix.c	Tue Feb 16 21:06:55 2016 +0330
>> @@ -115,7 +115,7 @@
>>   * support.  Determine if the following are the most suitable alternatives.
>>   *
>>   */
>> -static int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>> +int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>>  {
>>    *result = NULL;
>>    errno = 0;
>> diff -r 91482de10f40 src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c
>> --- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Wed Feb 10 14:17:12 2016 -0500
>> +++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c	Tue Feb 16 21:06:55 2016 +0330
>> @@ -160,7 +160,7 @@
>>   * support.  Determine if the following are the most suitable alternatives.
>>   *
>>   */
>> -static int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>> +int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>>  {
>>    *result = NULL;
>>    errno = 0;
>> @@ -173,7 +173,7 @@
>>    return 0;
>>  }
>>  
>> -static int getpwnam_r(const char *name, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>> +int getpwnam_r(const char *name, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>>  {
>>    *result = NULL;
>>    errno = 0;
>> @@ -186,7 +186,7 @@
>>    return 0;
>>  }
>>  
>> -static int getgrgid_r(gid_t gid, struct group* grp, char* buf, size_t buflen, struct group** result)
>> +int getgrgid_r(gid_t gid, struct group* grp, char* buf, size_t buflen, struct group** result)
>>  {
>>    *result = NULL;
>>    errno = 0;
>> @@ -199,7 +199,7 @@
>>    return 0;
>>  }
>>  
>> -static int getgrnam_r(const char *name, struct group* grp, char* buf, size_t buflen, struct group** result)
>> +int getgrnam_r(const char *name, struct group* grp, char* buf, size_t buflen, struct group** result)
>>  {
>>    *result = NULL;
>>    errno = 0;
>> diff -r 91482de10f40 src/jdk.security.auth/unix/native/libjaas/Unix.c
>> --- a/src/jdk.security.auth/unix/native/libjaas/Unix.c	Wed Feb 10 14:17:12 2016 -0500
>> +++ b/src/jdk.security.auth/unix/native/libjaas/Unix.c	Tue Feb 16 21:06:55 2016 +0330
>> @@ -39,7 +39,7 @@
>>  #include <errno.h>
>>  
>>  #ifdef __ANDROID__
>> -static int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>> +int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>>  {
>>    *result = NULL;
>>    errno = 0;
>> 
>> 2) 
>> Error “initializer element is not constant” when trying to initialize variable <http://stackoverflow.com/questions/3025050/error-initializer-element-is-not-constant-when-trying-to-initialize-variable-w>
>> I only commented line: this is only workaound
>> 
>> diff -r 91482de10f40 src/java.base/linux/native/libnet/linux_close.c
>> --- a/src/java.base/linux/native/libnet/linux_close.c	Wed Feb 10 14:17:12 2016 -0500
>> +++ b/src/java.base/linux/native/libnet/linux_close.c	Tue Feb 16 21:06:55 2016 +0330
>> @@ -57,7 +57,7 @@
>>   * Signal to unblock thread
>>   */
>>  #ifdef __ANDROID__
>> -#define __SIGRTMAX SIGRTMAX
>> +//#define __SIGRTMAX SIGRTMAX
>>  #endif
>>  static int sigWakeup = (__SIGRTMAX - 2);
>> 
>> Hotspot:
>> 
>> 1) error: static declaration of <some method> follows non-static declaration
>> 
>> diff -r de1d92b01bae src/os/linux/vm/perfMemory_linux.cpp
>> --- a/src/os/linux/vm/perfMemory_linux.cpp	Wed Feb 10 14:15:17 2016 -0500
>> +++ b/src/os/linux/vm/perfMemory_linux.cpp	Tue Feb 16 20:32:38 2016 +0330
>> @@ -44,7 +44,7 @@
>>  # include <pwd.h>
>>  
>>  #ifdef __ANDROID__
>> -static int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>> +int getpwuid_r(uid_t uid, struct passwd* pwd, char* buf, size_t buflen, struct passwd** result)
>>  {
>>    *result = NULL;
>>    errno = 0;
>>   
>> 2) error: conflicting declaration 'typedef elf_greg_t greg_t'
>> android-x86-toolchain/sysroot/usr/include/sys/ucontext.h:123:13: note: previous declaration as 'typedef int greg_t'
>> 
>> I forced redefinition with #define macro. I don't know if redefinition is required here
>> 
>> diff -r de1d92b01bae src/os_cpu/linux_x86/vm/os_linux_x86.cpp
>> --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Wed Feb 10 14:15:17 2016 -0500
>> +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp	Tue Feb 16 20:32:38 2016 +0330
>> @@ -89,6 +89,7 @@
>>  #endif
>>  
>>  #ifdef __ANDROID__
>> +#define greg_t elf_greg_t
>>  typedef elf_greg_t greg_t;
>>  #define SPELL_REG_SP "esp"
>>  #define SPELL_REG_FP "ebp"
>>  #define CTX_REG_AX eax
>> 
>> 3) error: conflicting declaration 'typedef struct asm_ucontext ucontext_t'
>>  typedef struct ucontext ucontext_t;
>> ..
>> android-x86-toolchain/sysroot/usr/include/sys/ucontext.h:161:3: note: previous declaration as 'typedef struct ucontext ucontext_t'
>>  } ucontext_t;
>> 
>> This is my hack��
>> 
>> diff -r de1d92b01bae src/share/vm/utilities/globalDefinitions_gcc.hpp
>> --- a/src/share/vm/utilities/globalDefinitions_gcc.hpp	Wed Feb 10 14:15:17 2016 -0500
>> +++ b/src/share/vm/utilities/globalDefinitions_gcc.hpp	Tue Feb 16 20:32:38 2016 +0330
>> @@ -78,15 +78,18 @@
>>  #include <asm/sigcontext.h>
>>  /* avoid conflicting ucontext definitions */
>>  #define ucontext asm_ucontext
>> -struct ucontext {
>> +struct custom_ucontext {
>>    unsigned long uc_flags;
>> -  struct ucontext *uc_link;
>> +  struct custom_ucontext *uc_link;
>>    stack_t uc_stack;
>>    struct sigcontext uc_mcontext;
>>    sigset_t uc_sigmask;
>>  };
>> -
>> -typedef struct ucontext ucontext_t;
>> +#define ucontext_t custom_ucontext
>> +typedef struct custom_ucontext ucontext_t;
>>  #endif //__ANDROID__
>> 
>> 
>> Also in my toolchain for platform android-21 following files is missing I copied them from android-19
>> asm/elf.h
>> asm/user.h
>> 
>> 
>> With all of this and adding:
>> export CC=$ANDROID_DEVKIT/bin/arm-linux-androideabi-gcc
>> export CXX=$ANDROID_DEVKIT/bin/arm-linux-androideabi-g++
>> export LD=$ANDROID_DEVKIT/bin/arm-linux-androideabi-ld
>> export AR=$ANDROID_DEVKIT/bin/arm-linux-androideabi-ar
>> export MT=$ANDROID_DEVKIT/bin/arm-linux-androideabi-mt
>> export NM=$ANDROID_DEVKIT/bin/arm-linux-androideabi-nm
>> export OBJDUMP=$ANDROID_DEVKIT/bin/arm-linux-androideabi-objdump
>> export RANLIB=$ANDROID_DEVKIT/bin/arm-linux-androideabi-ranlib
>> export STRIP=$ANDROID_DEVKIT/bin/arm-linux-androideabi-strip
>> 
>> I ran my Hello World program in android jvm.
>> 
>> On Thu, Feb 11, 2016 at 10:33 PM, Bob Vandette <bob.vandette at oracle.com <mailto:bob.vandette at oracle.com>> wrote:
>> The OpenJDK Mobile project was recently merged with JDK 9 build 102 and
>> as of today nows has the ability to build both iOS and Android Java 9 binaries
>> for execution on both x86 and arm devices.
>> 
>> I’ve updated the iOS and Android Platform specific project pages with up to date
>> build instructions.
>> 
>> http://openjdk.java.net/projects/mobile/ios.html <http://openjdk.java.net/projects/mobile/ios.html>
>> http://openjdk.java.net/projects/mobile/android.html <http://openjdk.java.net/projects/mobile/android.html>
>> 
>> Enjoy,
>> Bob Vandette
>> Mobile Project Lead
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> -- 
>> 
>> Best Regards,
>> Ali Ebrahimi
> 



More information about the mobile-dev mailing list