Dear Android Building Group,

I am currently trying to extend the network security configuration to apply
certificate transparency by default. Therefore I am extending the
AOSP/frameworks/base/core/java/android/net/config directory.
I would also like to use some external libraries within this directory,
which turned out to be a big problem for me. For a concrete example, let's
say I want to use the gson library.

First I will provide my way of implementing the gson library for
AOSP/frameworks/base/core/java/android/net/config (1). The provided way
should be the closest to a working implementation, still, it breaks on
boot. After that, I will provide a very similar implementation for using
gson in AOSP/frameworks/base/services/core/java/com/android/server (2),
which works fine.

*Questions:*
1. Why does (1) break and how can I fix it?

*Specifications:*
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=11
TARGET_PRODUCT=aosp_x86_64
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_2ND_ARCH=x86
TARGET_2ND_ARCH_VARIANT=x86_64
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-4.19.0-10-amd64-x86_64-Debian-GNU/Linux-10-(buster)
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=RQ2A.210405.005
OUT_DIR=out
PRODUCT_SOONG_NAMESPACES=device/generic/goldfish
device/generic/goldfish-opengl hardware/google/camera
 hardware/google/camera/devices/EmulatedCamera device/generic/goldfish
device/generic/goldfish-opengl

*Implementation (1):*
+ AOSP/prebuilts/misc/common/gson
  + Android.pb
  + gson-2.8.7.jar


*AOSP/prebuilts/misc/common/gson/Android.pb*
*__________*

+ java_import {
+     name: "gson",
+     installable: false,
+     host_supported: true,
+     jars: ["gson-2.8.7.jar"],
+ }

*__________*


*AOSP/frameworks/base/Android.bp*
*__________*
*...*

java_library {
    name: "framework-minus-apex",
    defaults: ["framework-defaults"],
    srcs: [":framework-non-updatable-sources"],
    installable: true,
    javac_shard_size: 150,
    required: [
        "framework-platform-compat-config",
        "libcore-platform-compat-config",
        "services-platform-compat-config",
        "documents-ui-compat-config",
    ],
+    libs: ["framework-updatable-stubs-module_libs_api","gson",],

...
__________


*AOSP/frameworks/base/core/java/android/net/config/NetworkSecurityTrustManager.java*
__________
...
import com.google.gson.Gson;
...
public void checkserverTrusted(...)...{
  ...
+  android.util.Log.d(TAG,"About to instantiate Gson object.");
+  Gson gson = new Gson();
+  android.util.Log.d(TAG,"Gson object has been successfully
instantiated.");
  ...
}
...
__________


Building the source is no problem. However, running the artifacts crashes
the system:
...
05-31 12:25:23.842 792 1374 D TAG: About to instantiate Gson object.
--------- beginning of crash
05-31 12:25:23.847 792 1374 E AndroidRuntime: FATAL EXCEPTION: Thread-4
05-31 12:25:23.847 792 1374 E AndroidRuntime: Process:
com.android.networkstack.process, PID: 792
05-31 12:25:23.847 792 1374 E AndroidRuntime:
java.lang.NoClassDefFoundError: Class not found using the boot class
loader; no stack trace available
...




*Implementation (2):*
+ AOSP/prebuilts/misc/common/gson
  + Android.pb
  + gson-2.8.7.jar


*AOSP/prebuilts/misc/common/gson/Android.pb*
__________

+ java_import {
+     name: "gson",
+     installable: false,
+     host_supported: true,
+     jars: ["gson-2.8.7.jar"],
+ }

__________


*AOSP/frameworks/base/services/core/Android.bp*
__________


java_library_static {
    name: "services.core.unboosted",
    ...
    static_libs: [
+        "gson",
        "time_zone_distro",
        "time_zone_distro_installer",
        "android.hardware.authsecret-V1.0-java",
...

__________


*AOSP/frameworks/base/services/core/java/com/android/server/am/ActiveServices.java*
__________
...
import com.google.gson.Gson;
...

public ActiveServices(ActivityManagerService service) {
    mAm = service;
    int maxBg = 0;
    try {
        maxBg =
Integer.parseInt(SystemProperties.get("ro.config.max_starting_bg",
"0"));
    } catch(RuntimeException e) {
    }
    mMaxStartingBackground = maxBg > 0
            ? maxBg : ActivityManager.isLowRamDeviceStatic() ? 1 : 8;
+
+   android.util.Log.d(TAG,"About to instantiate Gson object.");
+   Gson gson = new Gson();
+   android.util.Log.d(TAG,"Gson object has been successfully instantiated.");
}
...


For (2) everything works as expected. And both logs can be observed in
logcat.

Can you please help me to fix (1) or at least to understand the problem?

Thanks a lot!


Regards,
John

-- 
-- 
You received this message because you are subscribed to the "Android Building" 
mailing list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-building?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"Android Building" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-building/CADnfz%2BdQd6%2BFHnCNmmsC1YA7Uov34Gd1A3VfVxrDC3yuTCAPDQ%40mail.gmail.com.

Reply via email to