Enable JAVA 8 advanced feature support in system app for Android 9.

226 views
Skip to first unread message

Donal Morrissey

unread,
Apr 26, 2020, 1:33:54 PM4/26/20
to android-porting
Hi There,
I'm trying to backport the updater_sample system app to a platform build running Android 9 / API 28. This updater_sample app uses advanced Java features such as lambda functions which are not supported in the JDK of the platform build. So the platform build is failing when it attempts to compile the backported app.

If I was compiling the app via Android Studio I would add something like the following to the gradle config file:

android {
  compileOptions {
    // change compatibility to Java 8 to get Java 8 IDE support  
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

But I'm not sure where to add this in the platform build.

Is there a way to configure the build of this system app in the platform build (perhaps via its Android.bp file) to use the JDK 1.8?

Thank you,
Donal


The content of this e-mail, including any attachments it may contain, is intended only for the recipient(s) named above. It may contain information that is confidential, subject to copyright, or otherwise legally protected against disclosure. If you have received this e-mail in error please notify the author and delete it from your system.

Donal Morrissey

unread,
Apr 27, 2020, 8:02:55 PM4/27/20
to android-porting
Looking at the AOSP build log I can see that it is trying to compile the app using the following javac command:

out/soong/host/linux-x86/bin/soong_javac_wrapper prebuilts/jdk/jdk9/linux-x86/bin/javac -J-Xmx2048M -Xmaxerrs 9999999 -encoding UTF-8 -sourcepath "" -g -XDskipDuplicateBridges=true -XDstringConcat=inline  -bootclasspath "" -classpath prebuilts/sdk/system_current/android.jar:out/soong/.intermediates/external/guava/guava/android_common/turbine-combined/guava.jar -source 1.8 -target 1.8 ...

If I manually change the source and target parameters to 1.9 and execute the javac build command, the app is compiled successfull.

Does anyone know how to change this SDK to 1.9 so that the full AOSP build uses it?

Thank you,
Donal

Donal Morrissey

unread,
Apr 28, 2020, 8:46:49 PM4/28/20
to android-porting
Hi All,
I've managed to solve this. Sharing here if anyone else come across this issue in future. I needed to add the following property to the Android.bp file: java_version: "1.9".
So my Android.bp file now looks like this:

android_app {
    name
: "SystemUpdaterSample",
    sdk_version
: "system_current",


    srcs
: ["src/**/*.java"],


    static_libs
: [
       
"guava",
   
],


    optimize
: {
        proguard_flags_files
: [
           
"proguard.flags",
       
],
   
},
   
    java_version
: "1.9",


    resource_dirs
: ["res"],
}


Donal
Reply all
Reply to author
Forward
0 new messages