Android Data Binding in Make file (Android.mk)
Asked Answered
U

2

13

As per a lot of examples, android data bindings are enabled by putting the following snippet in build.gradle file:

android {
    ....
    dataBinding {
        enabled = true
    }
}

However, I'm working on an android project in AOSP which builds using the make file (Android.mk).

So my question is: How can we add support for data-binding dependencies in android make file?

Ushijima answered 28/8, 2017 at 14:53 Comment(13)
Have you found a solution for this?Pedant
No, not yet. I dropped this idea long ago since couldn't find the solution :)Ushijima
Oh, that's bad. How do you think about this? android.googlesource.com/platform/build/+/master/core/…Pedant
Is there still no solution for this? I have tried adding the data binding aars and that doesn't work.Panathenaea
@Bananadroid what in that makefile did you think would work? I don't see anything data binding related.Panathenaea
@MattD , I don't remember the exact reason why I post that link. Anyway. I can't make it work either. I found some samples (like this: androidxref.com/6.0.0_r1/xref/frameworks/data-binding/…) but it did not workPedant
I'm also interested in using databinding with a Make file (or even in a Soong config file).Burgomaster
are you using the latest ndk version ?Fontainebleau
I think you are working on the project which has native code like c or c++ code. first, you have to use proper ndk lib then convert this function to an appropriate liveData type to use databinding. and follow the proper guidelines for the data binding from android developer developer.android.com/ndk/guides/android_mk developer.android.com/topic/libraries/data-binding#kotlinSalicaceous
Check this dev.to/manishkherde/comment/an8Carranza
It's not a native C/C++ project, just an AOSP project. I've seen the comment talking about of that blog but I haven't been lucky trying to do it.Burgomaster
any progress on that? @waqaslam. I tried LOCAL_DATA_BINDING := true but it didn't work for me.Vories
I also faced this problem when porting the default template native code to AOSP. I have proceeded by removing databinding code and using the regular Android way. Would be glad if there is some other way.Rett
G
2

I found a solution that works for me!

The first hurdle to climb will look something like this: error: package net.mulliken.pinenotenotebook.databinding does not exist

I found that Android Studio automatically generates these files. It was in app/build/generated/data_binding_base_class_source_out/debug/out/net/mulliken/pinenotenotebook/databinding. In order to incorporate this in my build I made a symbolic link from my Android studio workspace to databinding_src in my packages folder.

After that it still didn't work because it could not find the view binding package. You will probably get an error like this: error: package androidx.viewbinding does not exist

I found that google has a repo that includes this package and so I cloned it into my AOSP workspace under frameworks.

[me aosp/frameworks] $ git clone -b studio-main https://android.googlesource.com/platform/frameworks/data-binding data-binding

I then created a new symbolic link from that path into my package directory so that the compiler could find that class:

[me packages/apps/MyAPP] $ ln -s ../../../../frameworks/data-binding/extensions/viewbinding/src/main/java/ androidx_viewbinding_src

At the end of the day my Android.bp file looks like this:

android_app {
    name: "PineNoteNotebook",

    static_libs: [
        "androidx.appcompat_appcompat",
        "com.google.android.material_material",
        "androidx-constraintlayout_constraintlayout",
        "androidx.navigation_navigation-fragment",
        "androidx.navigation_navigation-ui",
    ],

    certificate: "platform",

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

    resource_dirs: ["res"],

    product_specific: true,

    sdk_version: "current",

    optimize: {
        enabled: false
    },

    required: ["libpinenote"],
}

And my package tree looks like this:

.
├── Android.bp
├── AndroidManifest.xml -> /home/mulliken/AndroidStudioProjects/PineNoteNotebook/app/src/main/AndroidManifest.xml
├── androidx_viewbinding_src -> ../../../../frameworks/data-binding/extensions/viewbinding/src/main/java/
├── databinding_src -> /home/mulliken/AndroidStudioProjects/PineNoteNotebook/app/build/generated/data_binding_base_class_source_out/debug/out
├── res -> /home/mulliken/AndroidStudioProjects/PineNoteNotebook/app/src/main/res/
└── src -> /home/mulliken/AndroidStudioProjects/PineNoteNotebook/app/src/main/java/
Gibbeon answered 19/5, 2022 at 19:24 Comment(2)
Thanks! This helped me to unblock with the databinding dependency. And I liked the idea of using a symlink into AOSP. I'm looking forward to a permanent solution for this.Nutgall
This solution was savior. While there are hardly any documentation on the same. Thanks for sharing.Mckeehan
F
-5

i think you must use the latest android studio 3.6 version , with the latest ndk + add this to your android gradle

android {
    ...
    viewBinding {
        enabled = true
    }
}

check this : https://developer.android.com/topic/libraries/view-binding

Fontainebleau answered 12/3, 2020 at 8:28 Comment(1)
That's viewbinding, not the same. Also builds in AOSP do not use Gradle, that's why we are asking for make (or even Soong) config files.Burgomaster

© 2022 - 2024 — McMap. All rights reserved.