NativeScript / android

Android runtime for NativeScript (based on V8)

Home Page:https://docs.nativescript.org/guide/android-marshalling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Including kotlin file into App_Resources/Android/src/main/java seems to not work

darkyelox opened this issue · comments

Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 8.1.1
  • Cross-platform modules: 8.1.1
  • Android Runtime: 8.1.1

Describe the bug
I'm trying to use a Kotlin file with some function for include into my Angular project but everything about it is undefined, for example if I define my packages as org.acrapp then acrapp is undefined and so on.

But if I create a Test.java file with a class inside and package org.acrapp the package isn't undefined anymore but everything from the Kotlin file is undefined (no classes no functions, etc)

To Reproduce
This is what I'm trying to do:

// Tools.kt on App_Resources/Android/src/main/java folder
@file:JvmName("Tools")

package org.acrapp

class TestKotlin

fun sayHello() {
    print("Hello World!")
}
// In some TypeScript Angular component
constructor(
  private readonly http: HttpClient,
  private readonly feedback: FeedbackService,
) {
  console.log(org.acrapp) // this prints undefined if package is defined in a Kotlin file, but if defined in Java file it isn't undefined
}

I noticed that if the Kotlin file has an syntax error the CLI stars an Android build but no error is thrown, is like it is ignoring my Kotlin file (Java files are compiled as expected)

Expected behavior
I was expecting that Kotlin was enabled by default for use in App_resources, if that isn't the case have I do enable it? how?

Additional context
Running on Genymotion with Android 10

Can u try adding the following to the app.gradle

project.ext {
    useKotlin = "true"
}

Can u try adding the following to the app.gradle

project.ext {
    useKotlin = "true"
}

Tried that and also in before-plugins.gradle but nothing works, the file is ignored even if it has syntax errors when built. Do you have an example of a working project using kotlin that way? (without using a plugin but using kotlin file directly in App_Resources/Android...)

@darkyelox

project.ext {
    useKotlin = "true"
}

should be the way. Did you clean after adding it?

@darkyelox

project.ext {
    useKotlin = "true"
}

should be the way. Did you clean after adding it?

Did it and nothing changed, here is my graddle, it compiles but ignores Kotlin files (even with syntax error).

// Add your native dependencies here:

// Uncomment to add recyclerview-v7 dependency
dependencies {
  implementation 'com.android.support:multidex:1.0.3'
  implementation 'com.squareup.okhttp3:okhttp:4.9.0'
}

// If you want to add something to be applied before applying plugins' include.gradle files
// e.g. project.ext.googlePlayServicesVersion = "15.0.1"
// create a file named before-plugins.gradle in the current directory and place it there

android {
  defaultConfig {
    minSdkVersion 19
    generatedDensities = []
    multiDexEnabled true
  }

  packagingOptions {
      pickFirst '**/*.so'
  }

  aaptOptions {
    additionalParameters "--no-version-vectors"
  }
}

project.ext {
  useKotlin = "true"
}

@darkyelox you will need to create a gradle.properties file in App_Resources/Android then add the following

useKotlin=true

@triniwiz I actually don't think the gradle.properties gets picked up in App_Resources. I had to make a hook to merge the platform one with the one I would put in App_Resources

@darkyelox you will need to create a gradle.properties file in App_Resources/Android then add the following

useKotlin=true

Confirmed that this worked (for someone else) on Discord!