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?

waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • Have you found a solution for this? – Banana droid Nov 05 '18 at 07:10
  • No, not yet. I dropped this idea long ago since couldn't find the solution :) – waqaslam Nov 05 '18 at 12:48
  • Oh, that's bad. How do you think about this? https://android.googlesource.com/platform/build/+/master/core/package_internal.mk – Banana droid Nov 05 '18 at 14:55
  • Is there still no solution for this? I have tried adding the data binding aars and that doesn't work. – Matt Oct 02 '19 at 14:52
  • @Bananadroid what in that makefile did you think would work? I don't see anything data binding related. – Matt Oct 02 '19 at 14:53
  • @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: http://androidxref.com/6.0.0_r1/xref/frameworks/data-binding/Android.mk) but it did not work – Banana droid Oct 02 '19 at 15:32
  • I'm also interested in using databinding with a Make file (or even in a Soong config file). – Abdelilah El Aissaoui Mar 09 '20 at 08:23
  • are you using the latest ndk version ? – B.mansouri Mar 12 '20 at 08:10
  • 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 https://developer.android.com/ndk/guides/android_mk https://developer.android.com/topic/libraries/data-binding#kotlin – Chhattlal Sahu Mar 13 '20 at 17:01
  • Check this https://dev.to/manishkherde/comment/an8 – Shweta Chauhan Mar 14 '20 at 14:34
  • 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. – Abdelilah El Aissaoui Mar 16 '20 at 10:31
  • any progress on that? @waqaslam. I tried `LOCAL_DATA_BINDING := true` but it didn't work for me. – ziLk Mar 23 '21 at 10:39
  • 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. – zeitgeist Nov 15 '21 at 09:31

2 Answers2

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/
  • 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. – code Jan 03 '23 at 09:38
  • This solution was savior. While there are hardly any documentation on the same. Thanks for sharing. – Devidas May 16 '23 at 06:56
-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

B.mansouri
  • 376
  • 7
  • 16