Yes
I have a native android aar library which uses the Android's DataBinding feature. Databinding generates some classes compile time in 'build/intermediates/classes/your/package/name/databinding'. However when I create the plugin for that aar file & use that plugin in native script app, the app crashes saying No class Def found for DataBinding classes. If I remove the DataBinding from the native aar library then the plugin works in {N} application so this confirms that there is no issue on the plugin side.
This happens because the databinding classes are not being generated/copied into platform/android/build/intermediates/classes/F0F1/debug/com/your/package/databinding/.
To confirm this, I created a new project in Android Studio, added the .aar file as dependency. It was working fine here as I could see the databinding classes. Then I copied the databinding classes in my {N} app's platform/android/build/** and it was also working fine without crashing. So it's clear that those classes are not being compiled/copied for me.
Am I missing something here?
Here's my include.gradle from plugin which has dataBinding enabled:
android {
productFlavors {
"nativescript-myplugin" {
dimension "nativescript-myplugin"
}
}
dataBinding {
enabled = true
}
}
repositories {
maven {
url 'https://maven.google.com'
}
}
tns --version to fetch it)node_modules/tns-core-modules/package.json file in your project)"tns-android" property in thepackage.json file of your project)This could be reproduced by using aar file which is having DataBinding If I get time today, I'll try to create a demo which shows the issue
This is urgent for me. Would really appreciate someone's help here.
@sam0829 please provide a minimal sample project with reproducible behavior so that we could investigate locally.
Thank you!
DatabindingCodes.zip
@Pip3r4o Thanks for replying :) I have attached all the required files from demo. Basically I created an "aar" file which has an Activity which changes the TextView's text in onCreate and uses DataBinding for it.
Here's what included in the attachment:
databinding-debug.aar : The aar file which uses the databinding and contains MainActivity
DatabindingAARCode.zip : The aar file's android code which you can use to modify / rebuild aar
AndroidDatabindingUsage.zip: The Android studio demo which uses the "aar" file & demonstrates that the MainActivity from aar is being called without any problem.
nativescript-databinding-plugin.zip: NativeScript plugin code which uses the aar file & exposes one method to startActivity from aar
NativeScriptDataBindingUsage.zip: This is the project which uses the NativeScriptPlugin for calling the Activity from aar and crashes saying MainBindings class not found which is supposed to be created by DataBinding
@sam0829 I tried to run the project with the nativescript-databinding-plugin npm installed locally for the project, however I got a NPE at build time, configuration step. I'd appreciate it if you created a Github repository clearly outlining the installation and reproduction steps,
@Pip3r4o Sure, will try to set it up in a day or two.
@Pip3r4o Here's the repo link : https://github.com/sam0829/nativescript-android-databinding-error
@sam0829 thanks Sam. I'll let you know when I've debugged it next week!
@sam0829 I've tried building with the repository provided - something's missing. I am still getting the NullPointerException during build.
$ tns run android
Searching for devices...
Executing before-liveSync hook from D:\work\personal\nativescript-android-databinding-error\hooks\before-liveSync\nativescript-angular-sync.js
Skipping prepare.
Building project...
Gradle build...
+ applying user-defined configuration from D:\work\personal\nativescript-android-databinding-error\app\App_Resources\Android\app.gradle
+ add include.gradle from D:\work\personal\nativescript-android-databinding-error\node_modules\nativescript-databinding-plugin\platforms\android\include.gradle
+ creating include.gradle for plugin D:\work\personal\nativescript-android-databinding-error\node_modules\tns-core-modules-widgets
+ applying plugin configuration from D:\work\personal\nativescript-android-databinding-error\platforms\android\build\configurations\nativescript-databinding-plugin\include.gradle
+ applying plugin configuration from D:\work\personal\nativescript-android-databinding-error\platforms\android\build\configurations\tns-core-modules-widgets\include.gradle
+ adding nativescript runtime package dependency: nativescript-optimized
+ adding aar plugin dependency: D:\work\personal\nativescript-android-databinding-error\node_modules\nativescript-databinding-plugin\platforms\android\databinding-debug.aar
+ adding aar plugin dependency: D:\work\personal\nativescript-android-databinding-error\node_modules\tns-core-modules-widgets\platforms\android\widgets-release.aar
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'DatabindingSampleUsageN'.
> java.lang.NullPointerException (no error message)
Snippet of the stack trace:
Caused by: java.lang.NullPointerException
10:01:15.402 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.build.gradle.internal.ndk.DefaultNdkInfo.findTargetPlatformVersionOrLower(DefaultNdkInfo.java:167)
10:01:15.402 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.build.gradle.internal.ndk.DefaultNdkInfo.findLatestPlatformVersion(DefaultNdkInfo.java:89)
10:01:15.402 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.build.gradle.internal.ndk.NdkHandler.getPlatformVersion(NdkHandler.java:131)
10:01:15.402 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.build.gradle.internal.ndk.NdkHandler.supports64Bits(NdkHandler.java:234)
10:01:15.402 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at com.android.build.gradle.internal.ndk.NdkHandler.getSupportedAbis(NdkHandler.java:297)
Does it ring any bells? What's your version of the Android Build-Tools? What's the compile SDK used?
@Pip3r4o I haven't seen any such errors.
The .aar file is built in Android Studio 3.0.1 with following stuff & uses Kotlin:
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.21"
compileSdkVersion 26
buildToolsVersion : As the Android Studio 3.0.1 picks the needed Build Tool itself, I suspect it is **26.0.2**
For the NativeScript Plugin & Demo part, I am having
"tns-android": {
"version": "3.3.1"
}
I have not specified the compileSdk or build tool version explicitly to use so it should be the Default one required for 3.3.1 or something.
@sam0829 the 'default' ones are your latest versions respectively for compileSdk and build-tools, and are passed implicitly to the android build.
@Pip3r4o Ok so whatever latest I have in my SDK is picked as 'Default' right? So I checked my SDK & here's what I have,
Latest SDK : 26
Build Tools: 26.0.2 & 27.0.3 (But I guess as my compile SDK is 26, the 26.0.2 will be picked). Is there any way I can check which versions are used by my NativeScript project?
Hey @sam0829 I managed to run the application with the tns-android: 3.4.2 runtime. I tap on the gray button, and voila, Activity pops up with Hello World! Modified as is expected judging by the plugin code in the .aar
I have build tools 26.0.2, and 27.0.3 installed, though the version defaults to 27.
Hi @Pip3r4o Wow, So what can be the possible problem for me? tns-android version I am using (3.3.1) or the wrong build-tools / compile sdk versions being selected as default? If second is the case, is there any way I can find out which buildtool or compile SDK is selected in my {N} app?
In any case I guess I can explicitly pass the compile SDK & build-tools in my app.gradle if I remember correct, But I would still like to know the build-tools & compile SDK version of my {N} project.
@sam0829 if you run tns build android --log trace a line containing spawn: gradlew.bat, or spawn: gradlew (on Linux/Mac) will eventually come up, it contains the arguments the gradlew build has been started with. In my case it's spawn: gradlew.bat "assembleDebug" "--debug" "--stacktrace" "-PcompileSdk=android-27" "-PtargetSdk=27" "-PbuildToolsVersion=27.0.3" "-PsupportVersion=26.0.0-alpha1" "-PgenerateTypings=false"
I'd also recommend that you use the latest runtime, as it often has bugfixes.
@Pip3r4o Thanks a lot man for looking into this :). I am closing the issue as the issue is from my end only. I'll try to upgrade the runtime and check my versions today and hopefully that will fix the issue for me.