Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add condition in Android.bp

I want to differentiate code between Android Q and Android R how do I achieve this in Android.bp? In Android.mk I did something like this

ifeq ($(PLATFORM_VERSION), R)
LOCAL_CFLAGS += -DANDROID_R_AOSP
else
LOCAL_CFLAGS += -DANDROID_Q_AOSP

How to do above code in Android.bp?

like image 623
Sriraj Hebbar Avatar asked Jan 19 '26 04:01

Sriraj Hebbar


1 Answers

Follow the instructions given here.

Replace this part in the my_defaults.go:

    if ctx.AConfig().Getenv("SOME_ENV_VAR") == "some_value" {
        cflags = append(cflags, "-DCONDITIONAL")
    }

With:

    if ctx.AConfig().PlatformVersionName() == "R" {
        cflags = append(cflags, "-DANDROID_R_AOSP")
    } else {
        cflags = append(cflags, "-DANDROID_Q_AOSP")
    }

Reference: link. In older versions this function was called PlatformVersion() (link), but for Android 9 or higher you should be fine.

like image 174
f9c69e9781fa194211448473495534 Avatar answered Jan 21 '26 22:01

f9c69e9781fa194211448473495534



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!